calc_ss {lazy.sasef}R Documentation

Calculation of SS associated with SAS Estimable Functions

Description

Calculation of SS associated with SAS Estimable Functions

Usage

calc_ss(obj = NULL, y = NULL, print = 0)

Arguments

obj

A design object

y

The response variable vector

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.

The SS associated with each of estimable function of effect i,
Qf[erange[i,1]:erange[i,2],,drop=0],
where Qf is the non-zero rows of Q matrix: Q[locnz,,drop=0],
can be calculated as:
ssq(y-X%*%betahat0) - ssq(y-X%*%betahat)
where betahat is the LS estimate of beta w/o constraints and
betahat0 is the LS estimate of beta with constraints
Qf[erange[i,1]:erange[i,2],,drop=0] %*% beta = 0
which is given as
betahat0=betahat-invtXX%*%t(Qfi)%* %solve(Qfi%*%invtXX%*%t(Qfi))%*%(Qfi%*%betahat)

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=-1, pattern="a" )
ef1 <- sasef( d1, type="I", print=1 )
ef2 <- sasef( d1, type="II", print=1 )
ef3 <- sasef( d1, type="III", print=1 )

# response variable
y <- du23[,3]

# calculate Ss
SS1 <- calc_ss( ef1, y, print=1 )
SS2 <- calc_ss( ef2, y, print=1 )
SS3 <- calc_ss( ef3, y, 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  + A *B , data=du23)

# type I SS
anova(LM2)

# library(car)
# type II SS
# Anova(LM2)
# type III Ss
# Anova(LM2,type="III")




# 2 x 3 x 2 unbalanced factorial data
# design matrix and the estimable functions
d2 <- design_mat( du232[,1:3], type=-1, pattern="a", sort=1 )
ef21 <- sasef( d2, type="I", print=1 )
ef22 <- sasef( d2, type="II", print=1 )
ef23 <- sasef( d2, type="III", print=1 )

# response variable
y <- du232[,4]

# calculate Ss
SS21 <- calc_ss( ef21, y, print=1 )
SS22 <- calc_ss( ef22, y, print=1 )
SS23 <- calc_ss( ef23, y, 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)
# type II SS
# Anova(LM2)
# type III Ss
# Anova(LM2,type="III")


[Package lazy.sasef version 0.1.4 Index]