calc_ss_r {lazy.sasef} R Documentation

## Calculation of SS associated with SAS Estimable Functions using Reduction notation

### Description

Calculation of SS associated with SAS Estimable Functions using Reduction notation

### Usage

```calc_ss_r(obj = NULL, y = NULL, type = "III", print = 0)
```

### Arguments

 `obj` A design object `y` The response variable vector `type` The type of SS to be calculated. "I", "II" or "III". `print` = 1 to print the result

### Details

A design object is a list of the design matrix (X), infomation list (info) and parameter list (param) where

X is the design matrix

info is a list whose length is the number of effects:

info[[i]] contains the following:
ename name of effect[i]
order order of effect[i]: 0, 1, ..., maxorder
elevels # of levels of effect[i]
df degrees of freedom of effect[i]
erange range of effect[i] in the estimable function
range=cbind(from,to) where
from is the starting independent colmn of effect[i] in X
to is the ending independent column of effect[i] in X
rangef=cbind(from,to) where
from is the starting colmn of effect[i] in X
to is the ending column of effect[i] in X
menum vector of main effect number involved in effect[i] contained vector of effect numbers which contains effect[i]
where effect number is defined according to the order of column of X.
contains vector of effects which effect[i] contais.
param is a list consisting of

type, drop, maxorder, sort, pattern

ef Information of estimable function.

Type I SS is calculated by recording the successive differences of the rss (residual sums of squares) of the models.
For example, for two factor design with factor A and B
SS(A) = R( A | mu ), SS(B) = R( B | A, mu ), SS(AB) = R( AB | mu, A, B )

Type II SS is calculated as the difference between the rss of the model with those effects which contain current effect
and the model with the current effect and those which do not contain it.
For example, for two factor design with factor A and B
SS(A) = R( A | mu, B ), SS(B) = R( B | mu, A ) , SS(AB) = R( AB | mu, A, B )

Type III SS is calculated as the difference between the rss of the full model
and the model w/o current effect.
For example, for two factor design with factor A and B
SS(A) = R( A | mu, B, AB ), SS(B) = R( B | mu, A, AB ) , SS(AB) = R( AB | mu, A, B )

### Value

A matrix with SS and df

### Examples

```# 2 x 3 unbalanced factorial data
# design matrix and the estimable functions
d1 <- design_mat( du23[,1:2], type=0 )

# response variable
y <- du23[,3]

# calculate Ss
SS1 <- calc_ss_r( d1, y, type="I", print=1 )
SS2 <- calc_ss_r( d1, y, type="II", print=1 )
SS3 <- calc_ss_r( d1, y, type="III", print=1 )

# Comparison with
# SS by native and existing functions.

# Use zeo-sum design matrix in lm.
options(contrasts=c(factor="contr.sum",ordered="contr.poly"))
LM1 <- lm(y  ~ A*B , data=du23)

# type I SS
anova(LM1)

# library(car)    # This is needed to use Anova function.
# type II SS
# Anova(LM1)
# type III Ss
# Anova(LM1,type="III")

# 2 x 3 unbalanced factorial data
# design matrix and the estimable functions
d2 <- design_mat( du232[,1:3], type=0, sort=1 )

# response variable
y <- du232[,4]

# calculate Ss
SS21 <- calc_ss_r( d2, y, type="I", print=1 )
SS22 <- calc_ss_r( d2, y, type="II", print=1 )
SS23 <- calc_ss_r( d2, y, type="III", print=1 )

# Comparison with
# SS by native and existing functions.

# Use zeo-sum design matrix in lm.
options(contrasts=c(factor="contr.sum",ordered="contr.poly"))
LM2 <- lm(y  ~ A*B*C , data=du232)

# type I SS
anova(LM2)

# library(car)    # This is needed to use Anova function.
# type II SS
# Anova(LM2)
# type III Ss
# Anova(LM2,type="III")
```

[Package lazy.sasef version 0.1.2 Index]