R: Reform a Design Matrix to that Contrasts Become Coefficients
contrastAsCoef
R Documentation
Reform a Design Matrix to that Contrasts Become Coefficients
Description
Reform a design matrix so that one or more coefficients from the new matrix correspond to specified contrasts of coefficients from the old matrix.
Usage
contrastAsCoef(design, contrast=NULL, first=TRUE)
Arguments
design
numeric design matrix.
contrast
numeric matrix with rows corresponding to columns of the design matrix (coefficients) and columns containing contrasts. May be a vector if there is only one contrast.
first
logical, should coefficients corresponding to contrasts be the first columns (TRUE) or last columns (FALSE) of the output design matrix.
Details
If contrast doesn't have full column rank, then superfluous columns are dropped.
Value
A list with components
design
reformed design matrix
coef
columns of design matrix which hold the meaningful coefficients
qr
QR-decomposition of contrast matrix
Author(s)
Gordon Smyth
See Also
model.matrix in the stats package.
An overview of linear model functions in limma is given by 06.LinearModels.
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(limma)
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/limma/contrastAsCoef.Rd_%03d_medium.png", width=480, height=480)
> ### Name: contrastAsCoef
> ### Title: Reform a Design Matrix to that Contrasts Become Coefficients
> ### Aliases: contrastAsCoef
> ### Keywords: regression
>
> ### ** Examples
>
> design <- cbind(1,c(0,0,1,1,0,0),c(0,0,0,0,1,1))
> cont <- c(0,-1,1)
> design2 <- contrastAsCoef(design, cont)$design
>
> # Original coef[3]-coef[2] becomes coef[1]
> y <- rnorm(6)
> fit1 <- lm(y~0+design)
> fit2 <- lm(y~0+design2)
> coef(fit1)
design1 design2 design3
0.3754279 -1.4508091 -0.1671291
> coef(fit2)
design2C1 design2Q2 design2Q3
1.2836800 -0.5435015 -1.0744367
>
>
>
>
>
> dev.off()
null device
1
>