compef {lazy.sasef} | R Documentation |
Comparison of Two Different Parametrization of a Linear Model
compef(obj1 = NULL, obj2 = NULL, print = 0)
obj1 |
A design object for model1 |
obj2 |
A design object for model2 |
print |
= 1 to print the result |
This program compares the following two equivalent linear models:
model1: yhat = X beta
and model2: yhat = Z alpha
where X and Z are the design matrices of the same column rank,
and expressed the estimable function of model1 (beta) in terms of
the parameters of model2 (alpha).
Note that the estimable function of model1 is Q %*% beta
where :
Q = matSwp(t(X)%*%X)%*%t(X)%*%X
which, if X is of full column rank, is equal to I.
The columns of Q
are labeled as L1,L2,...,
.
Note also that, because both X and Z share the same column space,
Z can be expressed as
Z = X%*%matSwp(t(X)%*%X)%*%t(X) %*% Z
Therefore, by multiplying matSwp(t(X)%*%X)%*%t(X)
to the both sides of
X %*% beta = Z alpha
we have,
matSwp(t(X)%*%X)%*%t(X) %*%%*% X beta = matSwp(t(X)%*%X)%*%t(X) %*% Z alpha Q %*% beta = matSwp(t(X)%*%X)%*%t(X)%*% X%*%matSwp(t(X)%*%X)%*%t(X)%*%Z alpha = matSwp(t(X)%*%X)%*%t(X)%*%X %*% matSwp(t(X)%*%X)%*%t(X)%*%Z alpha = Q %*% matSwp(t(X)%*%X)%*%t(X)%*%Z alpha
The correspondence from alpha to beta is obtained by
Q %*% beta = R %*% alpha
where
R = Q %*% matSwp(t(X)%*%X)%*%t(X)%*%Z
A design object which 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..
List of Q, R, Rf, Rc
where Q is the numeric form of estimable functions
R = Q matSwp(t(X)%*%X)%*%t(X)%*%Z
Rf Fractional expression of R
Rc Character version of R
# data data <- du23[,1:2] # sas EFs from NonFullrank design matrix # type I, II, III dNF <- design_mat( data, type=-1, sort=0 ) ef1 <- sasef( dNF, type="I", print=1 ) ef2 <- sasef( dNF, type="II", print=1 ) ef3 <- sasef( dNF, type="III", print=1 ) # zero-sum (effect coding) design matrix dZS <- design_mat( data, type=0, sort=0, pattern="a" ) # drop-last (treatment coding) design matrix dDL <- design_mat( data, type=1, sort=0 ) # cell means design matrix dCM <- design_mat( data, type=-2, sort=0 ) # Comparison # SAS type III EF in terms of the cell means temp=compef( ef3, dCM, print=3 ) # Cell Means in terms of SAS type III EF temp=compef( dCM, ef3, print=3 ) # Zero-Sum in terms of the cell means temp=compef( dZS, dCM, print=3 ) # Cell Means in terms of zero-sum temp=compef( dCM, dZS, print=3 ) # type III in terms of zero-sum temp=compef( ef3, dZS, print=3 ) # zero-sum in terms of sas non-full-rank X: temp=compef( dZS, dNF, print=3 )