Title: | Information Decomposition of Two-Phase Experiments |
---|---|
Description: | The main purpose of this package is to generate the structure of the analysis of variance (ANOVA) table of the two-phase experiments. The user only need to input the design and the relationships of the random and fixed factors using the Wilkinson-Rogers' syntax, this package can then quickly generate the structure of the ANOVA table with the coefficients of the variance components for the expected mean squares. Thus, the balanced incomplete block design and provides the efficiency factors of the fixed effects can also be studied and compared much easily. |
Authors: | Kevin Chang [aut, cre], Katya Ruggiero [aut] |
Maintainer: | Kevin Chang <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.6.2 |
Built: | 2025-02-12 04:40:39 UTC |
Source: | https://github.com/kcha193/infodecompute |
he main purpose of this package is to generate the structure of the analysis of variance (ANOVA) table of the two-phase experiments. The user only need to input the design and the relationships of the random and fixed factors using the Wilkinson-Rogers' syntax, this package can then quickly generate the structure of the ANOVA table with the coefficients of the variance components for the expected mean squares. Thus, the balanced incomplete block design and provides the efficiency factors of the fixed effects can also be studied and compared much easily.
Package: | infoDecompuTE |
Type: | Package |
Version: | 0.6.1 |
Date: | 2018-05-28 |
License: | GPL (>= 3) |
LazyLoad: | yes |
Kevin Chang and Katya Ruggiero
Maintainer: Kevin Chang <[email protected]>
Adjust for appropriate syntax describing the effects matching the structural formula.
adjustEffectNames(effectsMatrix, effectNames)
adjustEffectNames(effectsMatrix, effectNames)
effectsMatrix |
a matrix of variables by terms showing which variables
appear in which terms generated by the |
effectNames |
a vector of character containing the labels of the
treatment or block terms in the model generated by the |
A vector of character containing the labels of the terms in the model with appropriate syntax describing the effects.
Kevin Chang
str.for = "A*(B/E/C)*D" effectsMatrix= attr(terms(as.formula(paste("~", str.for)), keep.order = TRUE) , "factors") effectNames = attr(terms(as.formula(paste("~", str.for)), keep.order = TRUE) , "term.labels") adjustEffectNames(effectsMatrix, effectNames)
str.for = "A*(B/E/C)*D" effectsMatrix= attr(terms(as.formula(paste("~", str.for)), keep.order = TRUE) , "factors") effectNames = attr(terms(as.formula(paste("~", str.for)), keep.order = TRUE) , "term.labels") adjustEffectNames(effectsMatrix, effectNames)
Adjust for appropriate syntax describing the effects matching the structural formula.
adjustMissingLevels(design.df, str.for)
adjustMissingLevels(design.df, str.for)
design.df |
a data frame containing the experimental design. Requires
every column be a |
str.for |
a single string of characters containing the structural formula using the Wilkinson-Rogers' syntax. |
A list containing a data frame with the experimental design and a single string of characters containing the structural formula.
Kevin Chang
design.df = data.frame( Blk = factor(1:16), Ani = factor(c( 1,1,2,2, 1,1,2,2, 1,1,2,2, 1,1,2,2)), Trt = factor(c( 1,2,3,4, 1,2,3,4, 1,2,3,4, 1,2,3,4)), stringsAsFactors = TRUE ) adjustMissingLevels(design.df, str.for = "Ani/Trt")
design.df = data.frame( Blk = factor(1:16), Ani = factor(c( 1,1,2,2, 1,1,2,2, 1,1,2,2, 1,1,2,2)), Trt = factor(c( 1,2,3,4, 1,2,3,4, 1,2,3,4, 1,2,3,4)), stringsAsFactors = TRUE ) adjustMissingLevels(design.df, str.for = "Ani/Trt")
Randomised Block design consisted of 6 blocks and 3 plots.
chrisEx1
chrisEx1
A data frame with 18 rows and 5 variables:
Block factor containing 6 levels
Plot factor containing 3 levels
Treatment factor A containing 3 levels
Treatment factor B containing 3 levels
Treatment factor C containing 9 levels
data(chrisEx1) summaryAovOnePhase(chrisEx1, "Blocks/Plots", "A*B*C")
data(chrisEx1) summaryAovOnePhase(chrisEx1, "Blocks/Plots", "A*B*C")
Randomised Block design consisted of 8 blocks and 2 plots.
chrisEx2
chrisEx2
A data frame with 18 rows and 5 variables:
Block factor containing 6 levels
Plot factor containing 3 levels
Treatment factor A containing 2 levels
Treatment factor B containing 2 levels
Treatment factor C containing 3 levels
data(chrisEx2) summaryAovOnePhase(chrisEx2, "Blocks/Plots", "A*B*C")
data(chrisEx2) summaryAovOnePhase(chrisEx2, "Blocks/Plots", "A*B*C")
Randomised Block design consisted of 4 blocks and 2 plots.
chrisEx3
chrisEx3
A data frame with 8 rows and 5 variables:
Block factor containing 4 levels
Plot factor containing 2 levels
Treatment factor A containing 2 levels
Treatment factor B containing 2 levels
Treatment factor C containing 4 levels
data(chrisEx2) summaryAovOnePhase(chrisEx2, "Blocks/Plots", "A*B*C")
data(chrisEx2) summaryAovOnePhase(chrisEx2, "Blocks/Plots", "A*B*C")
Compute the variance components' coefficients and corresponding to random
effects in the expected mean squares of ANOVA table in single-phase or
two-phase experiments. These coefficients are then inserted to a matrix
where the rows correspond to each source of variation and column correspond
to DF and every variance component. The mean squares is calculated if the
response
argument is used.
getCoefVC.onePhase( Pb, design.df, v.mat, response, table.legend, decimal, digits )
getCoefVC.onePhase( Pb, design.df, v.mat, response, table.legend, decimal, digits )
Pb |
a list of matrices generated by |
design.df |
a data frame containing the experimental design. Requires
every column be a |
v.mat |
a list of matrix generated by |
response |
a numeric vector contains the responses from the experiment. |
table.legend |
a logical allows users to generate a legend for the
variance components of the ANOVA table for large designs. Default is
|
decimal |
a logical allows users to display the coefficients as the
decimals. Default is |
digits |
a integer indicating the number of decimal places. Default is 2, resulting in 2 decimal places. |
The main purpose of this function is to combine the matrices presenting every source of variation of the ANOVA table and the variance matrix to compute the coefficients of the variance components.
The complication arise in giving the row names of the matrix for the source of variation in the ANOVA table.
A matrix containing the characters.
Kevin Chang
design1 <- local({ Ani <- as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt <- as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str <- "Ani" rT <- terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm <- attr(rT,"term.labels") Z <- makeBlkDesMat(design1, blkTerm) trt.str <- "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factor") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) N = makeOverDesMat(design1, trtTerm) Replist = getTrtRep(design1, trtTerm) Rep <- Replist$Rep trt.Sca <- Replist$Sca effFactors = lapply(makeOrthProjectors(Z), function(z) getEffFactor(z, T, N, Rep, trt.Sca)) #Now construct variance matrices Pb <- effFactors[sort(1:length(effFactors), decreasing=TRUE)] v.mat <- getVMat.onePhase(Z.Phase1 = Z, design.df = design.df, var.comp = NA) getCoefVC.onePhase(Pb = Pb, design.df = design1, v.mat = v.mat, response = NA, table.legend = FALSE, decimal = FALSE, digit = 2)
design1 <- local({ Ani <- as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt <- as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str <- "Ani" rT <- terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm <- attr(rT,"term.labels") Z <- makeBlkDesMat(design1, blkTerm) trt.str <- "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factor") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) N = makeOverDesMat(design1, trtTerm) Replist = getTrtRep(design1, trtTerm) Rep <- Replist$Rep trt.Sca <- Replist$Sca effFactors = lapply(makeOrthProjectors(Z), function(z) getEffFactor(z, T, N, Rep, trt.Sca)) #Now construct variance matrices Pb <- effFactors[sort(1:length(effFactors), decreasing=TRUE)] v.mat <- getVMat.onePhase(Z.Phase1 = Z, design.df = design.df, var.comp = NA) getCoefVC.onePhase(Pb = Pb, design.df = design1, v.mat = v.mat, response = NA, table.legend = FALSE, decimal = FALSE, digit = 2)
Compute the variance components' coefficients and corresponding to random
effects in the expected mean squares of ANOVA table in single-phase or
two-phase experiments. These coefficients are then inserted to a matrix
where the rows correspond to each source of variation and column correspond
to DF and every variance component. The mean squares is calculated if the
response
argument is used.
getCoefVC.twoPhase( Pb, design.df, v.mat, response, table.legend, decimal, digits )
getCoefVC.twoPhase( Pb, design.df, v.mat, response, table.legend, decimal, digits )
Pb |
a list of matrices generated by |
design.df |
a data frame containing the experimental design. Requires
every column be a |
v.mat |
a list of matrix generated by |
response |
a numeric vector contains the responses from the experiment. |
table.legend |
a logical allows users to generate a legend for the
variance components of the ANOVA table for large designs. Default is
|
decimal |
a logical allows users to display the coefficients as the
decimals. Default is |
digits |
a integer indicating the number of decimal places. Default is 2, resulting in 2 decimal places. |
The main purpose of this function is to combine the matrices presenting every source of variation of the ANOVA table and the variance matrix to compute the coefficients of the variance components.
The complication arise in giving the row names of the matrix for the source of variation in the ANOVA table.
A matrix containing the characters.
Kevin Chang
Perform the information decomposition for either the block or treatment effects within a single stratum and Compute the Efficiency Factors for every treatment effect within a single stratum.
getEffFactor(z, T, N, Rep, trt.Sca)
getEffFactor(z, T, N, Rep, trt.Sca)
z |
a matrix containing the orthogonal projector of a stratum
generated by |
T |
a list of contrast matrices generated by
|
N |
a matrix containing the design matrix generated by
|
Rep |
a matrix containing the treatment replication number and is
generated by |
trt.Sca |
a numeric vector for computing a coefficients of the fixed
effect parameter in EMS and is generated by |
The main purpose of this function is to construct a list of resultant matrices associated with each source of variation after the information decomposition and to compute the canonical or average efficiency factors for each treatment effects in each stratum of ANOVA table.
The canonical efficiency factors are generated when the user input the treatment contrasts, otherwise the average efficiency factors, which is the harmonic mean of the canonical efficiency factors, are generated.
A list of matrices and numeric vectors containing the efficiency factors of every treatment effect.
Kevin Chang
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str = "Ani" rT = terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z = makeBlkDesMat(design1, blkTerm) trt.str = "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factor") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) N = makeOverDesMat(design1, trtTerm) Replist = getTrtRep(design1, trtTerm) Rep <- Replist$Rep trt.Sca <- Replist$Sca effFactors = lapply(makeOrthProjectors(Z), function(z) getEffFactor(z, T, N, Rep, trt.Sca))
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str = "Ani" rT = terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z = makeBlkDesMat(design1, blkTerm) trt.str = "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factor") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) N = makeOverDesMat(design1, trtTerm) Replist = getTrtRep(design1, trtTerm) Rep <- Replist$Rep trt.Sca <- Replist$Sca effFactors = lapply(makeOrthProjectors(Z), function(z) getEffFactor(z, T, N, Rep, trt.Sca))
Calculate coefficients of fixed effects components of EMS and Treatment Efficiency Factors within each stratum in Single-Phase or two-phase experiment.
getFixedEF.onePhase( effFactors, trt.Sca, T, Rep, table.legend, decimal, digits, list.sep )
getFixedEF.onePhase( effFactors, trt.Sca, T, Rep, table.legend, decimal, digits, list.sep )
effFactors |
a list of numeric vector generated by
|
trt.Sca |
a numeric vector generated by |
T |
a list of matrices generated by |
Rep |
a numeric matrix generated by |
table.legend |
a logical allows users to generate a legend for the
variance components of the ANOVA table for large designs. Default is
|
decimal |
a logical allows users to display the coefficients as the
decimals. Default is |
digits |
a integer indicating the number of decimal places. Default is 2, resulting in 2 decimal places. |
list.sep |
a logical allows users to present the efficiency factors and coefficients of the fixed effects a list of separate matrices. |
Constructs a matrix containing the coefficients of the coefficients of fixed effects components of EMS within each stratum. Also calculates and the average efficiency factors of each treatment effect across all strata
Construct a matrix contain the coefficients of the fixed Components and the average efficiency factors of single-phase experiments.
The function uses the efficiency factors generated by getEffFactor
to calculated the coefficients of fixed Effects components of EMS and
insert the treatment efficiency factor within each stratum.
The complication arise in giving the row names of the matrix for the source of variation in the ANOVA table.
A matrix.
Kevin Chang
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str <- "Ani" rT <- terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z <- makeBlkDesMat(design1, blkTerm) trt.str <- "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factor") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) N <- makeOverDesMat(design1, trtTerm) Replist = getTrtRep(design1, trtTerm) Rep <- Replist$Rep trt.Sca <- Replist$Sca effFactors = lapply(makeOrthProjectors(Z), function(z) getEffFactor(z, T, N, Rep, trt.Sca)) effFactors <- effFactors[sort(1:length(effFactors), decreasing=TRUE)] getFixedEF.onePhase(effFactors = effFactors, trt.Sca = trt.Sca, T = T, Rep = Rep, table.legend = FALSE, decimal = FALSE, digits = 2, list.sep = TRUE)
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str <- "Ani" rT <- terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z <- makeBlkDesMat(design1, blkTerm) trt.str <- "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factor") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) N <- makeOverDesMat(design1, trtTerm) Replist = getTrtRep(design1, trtTerm) Rep <- Replist$Rep trt.Sca <- Replist$Sca effFactors = lapply(makeOrthProjectors(Z), function(z) getEffFactor(z, T, N, Rep, trt.Sca)) effFactors <- effFactors[sort(1:length(effFactors), decreasing=TRUE)] getFixedEF.onePhase(effFactors = effFactors, trt.Sca = trt.Sca, T = T, Rep = Rep, table.legend = FALSE, decimal = FALSE, digits = 2, list.sep = TRUE)
Calculate coefficients of fixed effects components of EMS and Treatment Efficiency Factors within each stratum in Single-Phase or two-phase experiment.
getFixedEF.twoPhase( effFactors, trt.Sca, T, Rep, table.legend, decimal, digits, list.sep )
getFixedEF.twoPhase( effFactors, trt.Sca, T, Rep, table.legend, decimal, digits, list.sep )
effFactors |
a list of numeric vector generated by
|
trt.Sca |
a numeric vector generated by |
T |
a list of matrices generated by |
Rep |
a numeric matrix generated by |
table.legend |
a logical allows users to generate a legend for the
variance components of the ANOVA table for large designs. Default is
|
decimal |
a logical allows users to display the coefficients as the
decimals. Default is |
digits |
a integer indicating the number of decimal places. Default is 2, resulting in 2 decimal places. |
list.sep |
a logical allows users to present the efficiency factors and coefficients of the fixed effects a list of separate matrices. |
Constructs a matrix containing the coefficients of the coefficients of fixed effects components of EMS within each stratum. Also calculates and the average efficiency factors of each treatment effect across all strata
Construct a matrix contain the coefficients of the fixed Components and the average efficiency factors of single-phase experiments.
The function uses the efficiency factors generated by getEffFactor
to calculated the coefficients of fixed Effects components of EMS and
insert the treatment efficiency factor within each stratum.
The complication arise in giving the row names of the matrix for the source of variation in the ANOVA table.
A matrix.
Kevin Chang
Compute the overall coefficients every treatment term including the interaction.
getTrtCoef(design.df, trtTerm)
getTrtCoef(design.df, trtTerm)
design.df |
a data frame containing the experimental design. Requires
every column be a |
trtTerm |
a vector of character containing the labels of the treatment
terms in the model generated by |
The numeric vector.
Kevin Chang
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) trt.str = "Trt" fT = terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm = attr(fT,"term.labels") effectsMatrix = attr(fT,"factor") trt.Coef = getTrtCoef(design1, trtTerm)
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) trt.str = "Trt" fT = terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm = attr(fT,"term.labels") effectsMatrix = attr(fT,"factor") trt.Coef = getTrtCoef(design1, trtTerm)
Calculate the replication number of every treatment term including the interaction. This is used to compute the treatment efficiency factors.
getTrtRep(design.df, trtTerm)
getTrtRep(design.df, trtTerm)
design.df |
a data frame containing the experimental design. Requires
every column be a |
trtTerm |
a vector of character containing the labels of the treatment
terms in the model generated by the |
A list containing two objects. The first object is a matrix called
Rep
which contains the replication numbers, where the rows
correspond to each treatment combination and the columns correspond to the
treatment factors, i.e. the replication number with respect to each
treatment factor based on the treatment combination. The second object
called Sca
which is a numeric vector for computing a coefficients of
the fixed effect parameter in EMS.
Kevin Chang
John J, Williams E (1987). Cyclic and computer generated Designs. Second edition. Chapman & Hall.
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) trt.str = "Trt" fT = terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm = attr(fT,"term.labels") effectsMatrix = attr(fT,"factor") getTrtRep(design1, trtTerm)
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) trt.str = "Trt" fT = terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm = attr(fT,"term.labels") effectsMatrix = attr(fT,"factor") getTrtRep(design1, trtTerm)
Construct the matrix for each variance components for the single-phase or two-phase experiment.
getVMat.onePhase(Z.Phase1, design.df, var.comp = NA)
getVMat.onePhase(Z.Phase1, design.df, var.comp = NA)
Z.Phase1 |
a list of block design matrix from |
design.df |
a data frame containing the experimental design. Requires
every column be a |
var.comp |
a vector of characters containing the variance components
of interest this allows the user to specify the variance components to be
shown on the ANOVA table. This also allows the user to specify artificial
stratum to facilitate decomposition. Default is |
A list of matrices.
Kevin Chang
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str = "Ani" rT = terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z = makeBlkDesMat(design1, rev(attr(rT,"term.labels"))) V = getVMat.onePhase(Z, design1)
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str = "Ani" rT = terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z = makeBlkDesMat(design1, rev(attr(rT,"term.labels"))) V = getVMat.onePhase(Z, design1)
Construct the matrix for each variance components for the single-phase or two-phase experiment.
getVMat.twoPhase(Z.Phase1, Z.Phase2, design.df, var.comp = NA)
getVMat.twoPhase(Z.Phase1, Z.Phase2, design.df, var.comp = NA)
Z.Phase1 |
a list of block design matrix from |
Z.Phase2 |
a list of block design matrix from |
design.df |
a data frame containing the experimental design. Requires
every column be a |
var.comp |
a vector of characters containing the variance components
of interest this allows the user to specify the variance components to be
shown on the ANOVA table. This also allows the user to specify artificial
stratum to facilitate decomposition. Default is |
A list of matrices.
Kevin Chang
design2 <- local({ Run = as.factor(rep(1:4, each = 4)) Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8, 3,4,1,2, 7,8,5,6)]) Tag = as.factor(c(114,115,116,117)[rep(1:4, 4)]) Trt = as.factor(letters[c(1,2,1,2, 2,1,2,1, 1,2,1,2, 2,1,2,1)]) data.frame(Run, Ani, Tag, Trt, stringsAsFactors = TRUE ) }) blk.str1 = "Ani" blk.str2 = "Run" rT1 = terms(as.formula(paste("~", blk.str1, sep = "")), keep.order = TRUE) #random terms phase 1 rT2 = terms(as.formula(paste("~", blk.str2, sep = "")), keep.order = TRUE) #random terms phase 2 blkTerm1 = attr(rT1,"term.labels") blkTerm2 = attr(rT2,"term.labels") Z1 = makeBlkDesMat(design2, rev(blkTerm1)) Z2 = makeBlkDesMat(design2, rev(blkTerm2)) V = getVMat.twoPhase(Z1, Z2, design2, var.comp = NA)
design2 <- local({ Run = as.factor(rep(1:4, each = 4)) Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8, 3,4,1,2, 7,8,5,6)]) Tag = as.factor(c(114,115,116,117)[rep(1:4, 4)]) Trt = as.factor(letters[c(1,2,1,2, 2,1,2,1, 1,2,1,2, 2,1,2,1)]) data.frame(Run, Ani, Tag, Trt, stringsAsFactors = TRUE ) }) blk.str1 = "Ani" blk.str2 = "Run" rT1 = terms(as.formula(paste("~", blk.str1, sep = "")), keep.order = TRUE) #random terms phase 1 rT2 = terms(as.formula(paste("~", blk.str2, sep = "")), keep.order = TRUE) #random terms phase 2 blkTerm1 = attr(rT1,"term.labels") blkTerm2 = attr(rT2,"term.labels") Z1 = makeBlkDesMat(design2, rev(blkTerm1)) Z2 = makeBlkDesMat(design2, rev(blkTerm2)) V = getVMat.twoPhase(Z1, Z2, design2, var.comp = NA)
Construct an identity matrix.
identityMat(n)
identityMat(n)
n |
a numeric describes the dimension of the identity matrix. |
This function returns a matrix with the diagonal elements equal to one and the off-diagonal elements equal to zero.
Kevin
John J, Williams E (1987). Cyclic and computer generated Designs. Second edition. Chapman & Hall.
identityMat(10)
identityMat(10)
Perform the information decomposition for either the block or treatment effects within a single stratum.
infoDecompMat(z, T, N)
infoDecompMat(z, T, N)
z |
a matrix containing the orthogonal projector for a single stratum
generated by |
T |
a list of contrast matrices generated by
|
N |
a matrix containing the design matrix generated by
|
The main purpose of this function is to construct a list of resultant matrices associated with each source of variation after the information decomposition.
This list of matrices are then used to compute the coefficient of the variance components in the expected mean squares.
A list of matrices.
Kevin Chang
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str = "Ani" rT = terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z = makeBlkDesMat(design1, blkTerm) Pb = makeOrthProjectors(Z) trt.str = "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factors") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) N = makeOverDesMat(design1, trtTerm) infoDecompMat(Pb[[1]], T, N)
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str = "Ani" rT = terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z = makeBlkDesMat(design1, blkTerm) Pb = makeOrthProjectors(Z) trt.str = "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factors") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) N = makeOverDesMat(design1, trtTerm) infoDecompMat(Pb[[1]], T, N)
Using the eigenvalue decomposition method to invert the information matrix.
invInfMat(C, N, T)
invInfMat(C, N, T)
C |
a matrix of block projector for a single stratum. |
N |
a matrix representation the smallest unit of block or treatment
effects generated by |
T |
a list of contrast matrices from |
This function returns a matrix.
Kevin Chang
Nelder JA (1965b). "The Analysis of Randomized Experiments with Orthogonal Block Structure. II. Treatment Structure and the General Analysis of Variance." Proceedings of the Royal Society of London. Series A, Mathematical and Physical Sciences, 283(1393), 163-178.
m <- matrix(rnorm(10), 10, 10) invInfMat(m, identityMat(10), identityMat(10))
m <- matrix(rnorm(10), 10, 10) invInfMat(m, identityMat(10), identityMat(10))
Construct a square matrix which the identity matrix minus the averging matrix.
J(n)
J(n)
n |
a numeric describes the dimension of the square matrix. |
This function return a square matrix which the identity matrix minus the averaging matrix.
Kevin Chang
J(10)
J(10)
Construct a n-by-n averaging matrix.
K(n)
K(n)
n |
a numeric describes the dimension of the averaging matrix. |
This function returns a square matrix with all
elements equal 1/n.
Kevin Chang
John J, Williams E (1987). Cyclic and computer generated Designs. Second edition. Chapman & Hall.
K(10)
K(10)
Construct a binary matrix representing the block design. The rows are corresponding to the observations and the columns are corresponding to the blocks.
makeBlkDesMat(design.df, blkTerm)
makeBlkDesMat(design.df, blkTerm)
design.df |
a data frame containing the experimental design. Requires
every column be a |
blkTerm |
a vector of character containing the labels of the block
terms in the model generated by the |
A list of the binary matrices.
Kevin Chang
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str = "Ani*Trt" rT = terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z = makeBlkDesMat(design1, blkTerm)
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str = "Ani*Trt" rT = terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z = makeBlkDesMat(design1, blkTerm)
Construct a list of contrast matrices for block for treatment effects.
makeContrMat(design.df, effectNames, effectsMatrix, contr.vec)
makeContrMat(design.df, effectNames, effectsMatrix, contr.vec)
design.df |
a data frame containing the experimental design. Requires
every column be a |
effectNames |
a vector of character containing the labels of the
treatment or block terms in the model generated by the |
effectsMatrix |
a matrix of variables by terms showing which variables
appear in which terms generated by the |
contr.vec |
a list of contrast vectors, this allows the user to
specify the contrasts for each treatment or block factor. Note that if this
argument is used, it is necessary to specify the contrasts for every
treatment or block factor with the same order as |
The main purpose of this function is to compute a list of C matrices described by John and Williams (1987). These C matrices are used for the information decomposition for every treatment effect in every stratum of the experiment.
If the user input their own defined contrasts for each treatment effects. This function will then transform the input contrasts to the C matrices for the treatment effects.
For the two-phase experiments, the same method of information decomposition is used for the block effects of Phase 1 experiment in the stratum defined from the block structure of the Phase 2 experiment. Hence, the C matrices for the block effects of Phase 1 experiment can also be constructed using this function.
A list of contrast matrices.
Kevin Chang
John J, Williams E (1987). Cyclic and computer generated Designs. Second edition. Chapman & Hall.
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) trt.str = "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factor") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) #Fit each treatment contrasts as a vector seperately Trt1 <- rep(c(1,-1), each = 4) Trt2 <- rep(c(1,-1), time = 4) Trt3 <- Trt1*Trt2 T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec =list(Trt = list(Trt1 = Trt1, Trt2 = Trt2, Trt3 = Trt3)))
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) trt.str = "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) #fixed terms trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factor") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) #Fit each treatment contrasts as a vector seperately Trt1 <- rep(c(1,-1), each = 4) Trt2 <- rep(c(1,-1), time = 4) Trt3 <- Trt1*Trt2 T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec =list(Trt = list(Trt1 = Trt1, Trt2 = Trt2, Trt3 = Trt3)))
Construct a list of orthogonal projector matrices corresponding to all strata of the experiment.
makeOrthProjectors(BlkDesList)
makeOrthProjectors(BlkDesList)
BlkDesList |
a list of block design matrices generated by
|
The strata decomposition is performed within this function. The first step
is to convert the list of block design matrices generated by
makeBlkDesMat
to projection matrices using
projMat
. The second step is to use these projection matrices
to project the raw data vector from one stratum to next stratum of the
experiment; the resulting matrix corresponds to each stratum is the
orthogonal projector matrix of the given stratum.
A list containing matrices.
Kevin Chang
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str = "Ani" rT = terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z = makeBlkDesMat(design1, blkTerm) Pb = makeOrthProjectors(Z)
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str = "Ani" rT = terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm = attr(rT,"term.labels") Z = makeBlkDesMat(design1, blkTerm) Pb = makeOrthProjectors(Z)
Construct the treatment or block matrix of the smallest unit based from the experimental design.
makeOverDesMat(design.df, effectNames)
makeOverDesMat(design.df, effectNames)
design.df |
a data frame containing the experimental design. Requires
every column be a |
effectNames |
a vector of character containing the labels of the
treatment or block terms in the model generated by the |
The main purpose this matrix is used in information decomposition. For the factorial experiment, this matrix is typically the treatment design matrix associated with the interaction effects, because the interaction effects are the smallest unit for the treatment effects.
For the two-phase experiments, the same method of information decomposition is used for the block effects of Phase 1 experiment in the stratum defined from the block structure of the Phase 2 experiment. Hence, the block design matrix of the smallest unit for the block effects of Phase 1 experiment can also be constructed using this function.
A matrix where the rows correspond to the observation and columns correspond to the overall combination of the treatment factors or the block factors of the Phase 1 experiment.
Kevin Chang
John J, Williams E (1987). Cyclic and computer generated Designs. Second edition. Chapman & Hall.
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) trt.str = "Trt" fT = terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) trtTerm = attr(fT,"term.labels") effectsMatrix = attr(fT,"factor") makeOverDesMat(design1, trtTerm)
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) trt.str = "Trt" fT = terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) trtTerm = attr(fT,"term.labels") effectsMatrix = attr(fT,"factor") makeOverDesMat(design1, trtTerm)
Compute the projection matrix from a square matrix.
projMat(X)
projMat(X)
X |
a square matrix. |
A square matrix.
Kevin Chang
m = matrix(1, nrow = 10, ncol = 3) projMat(m)
m = matrix(1, nrow = 10, ncol = 3) projMat(m)
Computes the coefficients of the variance components for the expected mean squares for single-phase experiments. The function accepts a data frame of the experimental design with the structural formulae of the block and treatment factors. Two tables containing the variance components of the random effects and fixed effects are returned.
summaryAovOnePhase( design.df, blk.str, trt.str, var.comp = NA, trt.contr = NA, table.legend = FALSE, response = NA, latex = FALSE, fixed.names = NA, decimal = FALSE, digits = 2, list.sep = TRUE )
summaryAovOnePhase( design.df, blk.str, trt.str, var.comp = NA, trt.contr = NA, table.legend = FALSE, response = NA, latex = FALSE, fixed.names = NA, decimal = FALSE, digits = 2, list.sep = TRUE )
design.df |
a data frame containing the experimental design. Requires
every column be a |
blk.str |
a single string of characters containing the structural formula for the block factors using the Wilkinson-Rogers' syntax. |
trt.str |
a single string of characters containing the structural formula for the treatment factors using the Wilkinson-Rogers' syntax. |
var.comp |
a vector of characters containing the variance components
of interest this allows the user to specify the variance components to be
shown on the ANOVA table. This also allows the user to specify artificial
stratum to facilitate decomposition. Default is |
trt.contr |
a list of treatment contrast vectors, this allows the user
to specify the contrasts for each treatment factor. Note that if this
argument is used, it is necessary to specify the contrasts for every
treatment factor with the same order as |
table.legend |
a logical allows the users to use the legend for the
variance components of the ANOVA table for a large design. Default is
|
response |
a numeric vector contains the responses from the experiment. |
latex |
a logical allows the users to output the Latex script to Latex
table. Once the Latex script is generated, it requires the user to install
and load two Latex packages: |
fixed.names |
a vector of character allows the users to modify symbols for the fixed effects for the Latex outputs. |
decimal |
a logical allows users to display the coefficients as the
decimals. Default is |
digits |
a integer indicating the number of decimal places. Default is 2, resulting in 2 decimal places. |
list.sep |
a logical allows users to present the efficiency factors
and coefficients of the fixed effects a list of separate matrices. Default
is |
The values returned depends on the value of the table.legend
argument. If table.legend = FALSE
, this function will return a list
of two data frames. The first data frame contains the random effects and
the second data frame contains the fixed effects. If the
table.legend
argument is TRUE
, then it will return a list
containing two lists. The first list consists of a data frame of random
effects and a character string for the legend. The second list consists of
a data frame of fixed effects and a character string for the legend. If
response
argument is used, the random effect table will have one
extra column with of mean squares computed from the responses from the
experiment.
Kevin Chang
John J, Williams E (1987). Cyclic and computer generated Designs. Second edition. Chapman & Hall.
Nelder JA (1965b). "The Analysis of Randomized Experiments with Orthogonal Block Structure. II. Treatment Structure and the General Analysis of Variance." Proceedings of the Royal Society of London. Series A, Mathematical and Physical Sciences, 283(1393), 163-178.
Wilkinson GN, Rogers CE (1973). "Symbolic Description of Factorial Models for Analysis of Variance." Applied Statistics, 22(3), 392-399.
terms
for more information on the structural
formula.
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE) }) summaryAovOnePhase(design1, blk.str = "Ani", trt.str = "Trt") summaryAovOnePhase(design1, blk.str = "Ani", trt.str = "Trt", latex = TRUE, fixed.names = c("\\tau"))
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE) }) summaryAovOnePhase(design1, blk.str = "Ani", trt.str = "Trt") summaryAovOnePhase(design1, blk.str = "Ani", trt.str = "Trt", latex = TRUE, fixed.names = c("\\tau"))
Computes the coefficients of the variance components for the expected mean squares for two-phase experiments. The function accepts a data frame of the experimental design with the structural formulae of the block and treatment factors. Two tables containing the variance components of the random effects and fixed effects are returned.
summaryAovTwoPhase( design.df, blk.str1, blk.str2, trt.str, var.comp = NA, blk.contr = NA, trt.contr = NA, table.legend = FALSE, response = NA, latex = FALSE, fixed.names = NA, decimal = FALSE, digits = 2, list.sep = TRUE )
summaryAovTwoPhase( design.df, blk.str1, blk.str2, trt.str, var.comp = NA, blk.contr = NA, trt.contr = NA, table.legend = FALSE, response = NA, latex = FALSE, fixed.names = NA, decimal = FALSE, digits = 2, list.sep = TRUE )
design.df |
a data frame containing the experimental design. Requires
every column be a |
blk.str1 |
a single string of characters containing the structural formula for the block factors of the first-phase experiment using the Wilkinson-Rogers' syntax. |
blk.str2 |
a single string of characters containing the structural formula for the block factors of the second-phase experiment using the Wilkinson-Rogers' syntax. |
trt.str |
a single string of characters containing the structural formula for the treatment factors using the Wilkinson-Rogers' syntax. |
var.comp |
a vector of characters containing the variance components
of interest this allows the user to specify the variance components to be
shown on the ANOVA table. This also allows the user to specify artificial
stratum to facilitate decomposition. Default is |
blk.contr |
a list of first-phase block contrast vectors, this allows
the user to specify the contrasts for each block factor in the first phase
experiment. Note that if this argument is used, it is necessary to specify
the contrasts for every treatment factor with the same order as
|
trt.contr |
a list of treatment contrast vectors, this allows the user
to specify the contrasts for each treatment factor. Note that if this
argument is used, it is necessary to specify the contrasts for every
treatment factor with the same order as |
table.legend |
a logical allows the users to use the legend for the
variance components of the ANOVA table for a large design. Default is
|
response |
a numeric vector contains the responses from the experiment. |
latex |
a logical allows the users to output the Latex script to Latex
table. Once the Latex script is generated, it requires the user to install
and load two Latex packages: |
fixed.names |
a vector of character allows the users to modify symbols for the fixed effects for the Latex outputs. |
decimal |
a logical allows users to display the coefficients as the
decimals. Default is |
digits |
a integer indicating the number of decimal places. Default is 2, resulting in 2 decimal places. |
list.sep |
a logical allows users to present the efficiency factors
and coefficients of the fixed effects a list of separate matrices. Default
is |
The values returned depends on the value of the table.legend
argument. If table.legend = FALSE
, this function will return a list
of two data frames. The first data frame contains the random effects and
the second data frame contains the fixed effects. If the
table.legend
argument is TRUE
, then it will return a list
containing two lists. The first list consists of a data frame of random
effects and a character string for the legend. The second list consists of
a data frame of fixed effects and a character string for the legend. If
response
argument is used, the random effect table will have one
extra column with of mean squares computed from the responses from the
experiment.
Kevin Chang
John J, Williams E (1987). Cyclic and computer generated Designs. Second edition. Chapman & Hall.
Nelder JA (1965b). "The Analysis of Randomized Experiments with Orthogonal Block Structure. II. Treatment Structure and the General Analysis of Variance." Proceedings of the Royal Society of London. Series A, Mathematical and Physical Sciences, 283(1393), 163-178.
Wilkinson GN, Rogers CE (1973). "Symbolic Description of Factorial Models for Analysis of Variance." Applied Statistics, 22(3), 392-399.
terms
for more information on the structural
formula.
#Phase 2 experiment design2 <- local({ Run = as.factor(rep(1:4, each = 4)) Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8, 3,4,1,2, 7,8,5,6)]) Sam = as.factor(as.numeric(duplicated(Ani)) + 1) Tag = as.factor(c(114,115,116,117)[rep(1:4, 4)]) Trt = as.factor(c("healthy", "diseased")[c(1,2,1,2, 2,1,2,1, 1,2,1,2, 2,1,2,1)]) data.frame(Run, Ani, Sam, Tag, Trt, stringsAsFactors = TRUE) }) design2 summaryAovTwoPhase(design2, blk.str1 = "Ani", blk.str2 = "Run", trt.str = "Tag + Trt") #Add the sample into the Phase 1 block structure summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "Run", trt.str = "Tag + Trt") #Assuming there is crossing between the animals and samples summaryAovTwoPhase(design2, blk.str1 = "Ani*Sam", blk.str2 = "Run", trt.str = "Tag + Trt") #Set Artificial stratum design2$AniSet = as.factor(c(2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1)) design2 summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "AniSet/Run", trt.str = "Tag + Trt", var.comp = c("Ani:Sam", "Ani", "Run")) #Define traetment contrasts TagA = rep(c(1,1,-1,-1),time = 4) TagB = rep(c(1,-1,1,-1),time = 4) TagC = TagA * TagB Tag = list(TagA = TagA, TagB = TagB, TagC = TagC) Tag Trt = as.numeric(design2$Trt)-1.5 Trt summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "Run", trt.str = "Tag + Trt", trt.contr = list(Tag = list(TagA = TagA, TagB = TagB, TagC = TagC), Trt = Trt), table.legend = TRUE) #Compute MS set.seed(527) summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "Run", trt.str = "Tag + Trt", response = rnorm(16))$ANOVA #Generate Latex scripts summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "Run", trt.str = "Tag + Trt", latex = TRUE, fixed.names = c("\\gamma", "\\tau")) #Generate Latex scripts with MS set.seed(527) summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "Run", trt.str = "Tag + Trt", response = rnorm(16), latex = TRUE, fixed.names = c("\\gamma", "\\tau") )
#Phase 2 experiment design2 <- local({ Run = as.factor(rep(1:4, each = 4)) Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8, 3,4,1,2, 7,8,5,6)]) Sam = as.factor(as.numeric(duplicated(Ani)) + 1) Tag = as.factor(c(114,115,116,117)[rep(1:4, 4)]) Trt = as.factor(c("healthy", "diseased")[c(1,2,1,2, 2,1,2,1, 1,2,1,2, 2,1,2,1)]) data.frame(Run, Ani, Sam, Tag, Trt, stringsAsFactors = TRUE) }) design2 summaryAovTwoPhase(design2, blk.str1 = "Ani", blk.str2 = "Run", trt.str = "Tag + Trt") #Add the sample into the Phase 1 block structure summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "Run", trt.str = "Tag + Trt") #Assuming there is crossing between the animals and samples summaryAovTwoPhase(design2, blk.str1 = "Ani*Sam", blk.str2 = "Run", trt.str = "Tag + Trt") #Set Artificial stratum design2$AniSet = as.factor(c(2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1)) design2 summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "AniSet/Run", trt.str = "Tag + Trt", var.comp = c("Ani:Sam", "Ani", "Run")) #Define traetment contrasts TagA = rep(c(1,1,-1,-1),time = 4) TagB = rep(c(1,-1,1,-1),time = 4) TagC = TagA * TagB Tag = list(TagA = TagA, TagB = TagB, TagC = TagC) Tag Trt = as.numeric(design2$Trt)-1.5 Trt summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "Run", trt.str = "Tag + Trt", trt.contr = list(Tag = list(TagA = TagA, TagB = TagB, TagC = TagC), Trt = Trt), table.legend = TRUE) #Compute MS set.seed(527) summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "Run", trt.str = "Tag + Trt", response = rnorm(16))$ANOVA #Generate Latex scripts summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "Run", trt.str = "Tag + Trt", latex = TRUE, fixed.names = c("\\gamma", "\\tau")) #Generate Latex scripts with MS set.seed(527) summaryAovTwoPhase(design2, blk.str1 = "Ani/Sam", blk.str2 = "Run", trt.str = "Tag + Trt", response = rnorm(16), latex = TRUE, fixed.names = c("\\gamma", "\\tau") )
Print the Latex scripts on the screen for the user to output the table from the Latex output.
toLatexTable(ANOVA, EF, fixed.names)
toLatexTable(ANOVA, EF, fixed.names)
ANOVA |
a matrix containing the coefficients of the variance
components in EMS of ANOVA table generated by
|
EF |
a matrix containing the coefficient of the fixed effects
components and the treatment average efficiency factors generated by
|
fixed.names |
a vector of character allows the users to modify symbols for the fixed effects. |
Once the Latex script is generated, it requires the user to install and
load two Latex packages: booktabs
and bm
to compile the Latex
script.
Kevin Chang
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str <- "Ani" rT <- terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm <- attr(rT,"term.labels") Z <- makeBlkDesMat(design1, blkTerm) trt.str = "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factor") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) N <- makeOverDesMat(design1, trtTerm) Replist = getTrtRep(design1, trtTerm) Rep <- Replist$Rep trt.Sca <- Replist$Sca effFactors = lapply(makeOrthProjectors(Z), function(z) getEffFactor(z, T, N, Rep, trt.Sca)) effFactors <- effFactors[sort(1:length(effFactors), decreasing=TRUE)] v.mat <- getVMat.onePhase(Z.Phase1 = Z, design.df = design.df, var.comp = NA) ANOVA <- getCoefVC.onePhase(Pb = effFactors, design.df = design1, v.mat = v.mat, response = NA, table.legend = FALSE, decimal = FALSE, digits = 2) EF <- getFixedEF.onePhase(effFactors = effFactors, trt.Sca = trt.Sca, T = T, Rep = Rep, table.legend = FALSE, decimal = FALSE, digits = 2, list.sep = FALSE) toLatexTable(ANOVA = ANOVA, EF = EF, fixed.names = c("\\tau"))
design1 <- local({ Ani = as.factor(LETTERS[c(1,2,3,4, 5,6,7,8)]) Trt = as.factor(letters[c(1,1,1,1, 2,2,2,2)]) data.frame(Ani, Trt, stringsAsFactors = TRUE ) }) blk.str <- "Ani" rT <- terms(as.formula(paste("~", blk.str, sep = "")), keep.order = TRUE) blkTerm <- attr(rT,"term.labels") Z <- makeBlkDesMat(design1, blkTerm) trt.str = "Trt" fT <- terms(as.formula(paste("~", trt.str, sep = "")), keep.order = TRUE) trtTerm <- attr(fT, "term.labels") effectsMatrix <- attr(fT, "factor") T <- makeContrMat(design1, trtTerm, effectsMatrix, contr.vec = NA) N <- makeOverDesMat(design1, trtTerm) Replist = getTrtRep(design1, trtTerm) Rep <- Replist$Rep trt.Sca <- Replist$Sca effFactors = lapply(makeOrthProjectors(Z), function(z) getEffFactor(z, T, N, Rep, trt.Sca)) effFactors <- effFactors[sort(1:length(effFactors), decreasing=TRUE)] v.mat <- getVMat.onePhase(Z.Phase1 = Z, design.df = design.df, var.comp = NA) ANOVA <- getCoefVC.onePhase(Pb = effFactors, design.df = design1, v.mat = v.mat, response = NA, table.legend = FALSE, decimal = FALSE, digits = 2) EF <- getFixedEF.onePhase(effFactors = effFactors, trt.Sca = trt.Sca, T = T, Rep = Rep, table.legend = FALSE, decimal = FALSE, digits = 2, list.sep = FALSE) toLatexTable(ANOVA = ANOVA, EF = EF, fixed.names = c("\\tau"))
Compute the trace of the square matrix.
tr(X)
tr(X)
X |
a square matrix. |
A numeric value.
Kevin
John J, Williams E (1987). Cyclic and computer generated Designs. Second edition. Chapman & Hall.
m = matrix(1, nrow = 10, ncol = 10) tr(m)
m = matrix(1, nrow = 10, ncol = 10) tr(m)
Construct a vector with all elements unity.
unity(n)
unity(n)
n |
a numeric describe the length of vector. |
This function returns a matrix will all elements
unity.
Kevin Chang
John J, Williams E (1987). Cyclic and computer generated Designs. Second edition. Chapman & Hall.
unity(10)
unity(10)