design_mat {lazy.sasef}  R Documentation 
Generation of Various Design Matrices
design_mat(data = NULL, fnames = NULL, levels = NULL, type = 0, drop = "last", maxorder = 3, sort = 0, delim = "", pattern = "A", print = 0, debug = 0)
data 
Matrix of data frame containing the combination of factor levels

fnames 
A vector of factor names 
levels 
A vector of levels of each factor 
type 
The type of design matrix 
drop 
= "first" if the first level is dropped when type >= 0 
maxorder 
The maximum order of effects 
sort 
= 1 to sort the columns according to the order of effect 
delim 
NOT yet available 
pattern 
The pattern of factor names: 
print 
= 1 to print the design info 
debug 
= 1 to print the intermediate result 
When data is NULL, levels and fnames will be used.
When data is given, the colums specified by fnames will be used.
If fnames is NULL, all the columns will be used and the column names
will be used as factor names.
Data has priority over levels.
Note that an effect is defined as a combination of each levels
of factors with order 1 (main), 2 (two way interaction), ..., maxorder.
To retrieve the information of the design matrix, use get_design_info.
To extract the subset of the columns of the design matrix,
use get_design_subset.
To rename the columns of the design matrix,
use change_enames.
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
and
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 (full rank) estimable functions
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
Information of estimable function may be added to this object later.
# generate various types of design matrices res0 < design_mat( levels=c(2:3), type=0 )$X res10 < design_mat( levels=c(2:3), type=1 )$X res11 < design_mat( levels=c(2:3), type=1, drop="first" )$X resnf < design_mat( levels=c(2:3), type=1 )$X rescm < design_mat( levels=c(2:3), type=2 )$X Print(res0, res10, res11) Print(resnf,rescm) # projecting all to type=0 matrix and checking if they are equivalent. P0 < res0%*%solve(t(res0)%*%res0)%*%t(res0) maxad10 < max(abs(res10P0%*%res10)) maxad11 < max(abs(res11P0%*%res11)) maxadnf < max(abs(resnfP0%*%resnf)) maxadcm < max(abs(rescmP0%*%rescm)) Print( maxad10, maxad11, maxadnf, maxadcm ) # sorting the columns levels < c(2,3,2) ll < lapply( levels,function(x) seq(1:x) ) data < cprod(ll); data < rbind(data,c(1,1,1)) rownames(data) < 1:nrow(data); colnames(data)=c("A","B","C") res1 < design_mat( data ) res2 < design_mat( data, sort=1 ) Print(res1$X) Print(res2$X)