Class DesignMatrix
Baseline levels are initially determined by the order in which factor levels appear. You can re-level using the setBaseline method.
- Author:
- paul
-
Constructor Summary
ConstructorsConstructorDescriptionDesignMatrix(Object[] factor, int start, String factorName) DesignMatrix(ObjectMatrix<String, String, ?> sampleInfo, boolean intercept) DesignMatrix(ObjectMatrix<String, String, ? extends Object> sampleInfo) DesignMatrix(ObjectMatrix<String, String, Object> design, boolean intercept, boolean strict) DesignMatrix(StringMatrix<String, String> sampleInfo) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(ObjectMatrix<String, String, Object> sampleInfo) Append additional factors/covariates to thisvoidAdd interaction term; only works if there exactly two factors so this can figure out which interaction to add.voidaddInteraction(String... interactionTerms) This will not add the interaction unless all of the terms are already part of the design, and interactions that obviously can't be estimated will be dropped if possible, but otherwise this is fairly brain dead.getBaseline(String factorName) getContrastCoding(String factorName) How the given factor's levels are coded into columns;ContrastCoding.TREATMENTunless set.The contrasts aContrastCoding.SUM_TO_ZEROfactor needs but has no column for, as a map from the name such a column would have had to the design columns that determine it.Collection<String[]> getTerms()booleanbooleanIn limma, the contrasts are built by referring to the coefficients by name, which isn't what we want.protected voidrebuild()Refresh the design matrix, for example after releveling.voidsetBaseline(String factorName, String baselineFactorValue) voidsetContrastCoding(String factorName, ContrastCoding coding) Choose how one categorical factor's levels are coded, and rebuild the design.toString()
-
Constructor Details
-
DesignMatrix
-
DesignMatrix
- Parameters:
sampleInfo- in form of Doubles or Strings. Any other types will yield errors.
-
DesignMatrix
- Parameters:
sampleInfo- in form of Doubles or Strings. Any other types will yield errors.intercept-
-
DesignMatrix
-
DesignMatrix
- Parameters:
design-intercept- whether to include an intercept in the modelstrict- whether to remove columns from the design matrix that are unlikely to be useable. By default this is "true" for other constructors.
-
-
Method Details
-
getInteractionTerms
- Returns:
- a collection of String arrays. If empty, there are no interactions. Each array represents an interaction in the model. The elements of the array are the terms included in the interaction, as Strings provided when calling addInteraction.
-
makeContrasts
In limma, the contrasts are built by referring to the coefficients by name, which isn't what we want.- Returns:
-
add
Append additional factors/covariates to this- Parameters:
sampleInfo-
-
addInteraction
public void addInteraction()Add interaction term; only works if there exactly two factors so this can figure out which interaction to add. For more control use the other method. -
addInteraction
This will not add the interaction unless all of the terms are already part of the design, and interactions that obviously can't be estimated will be dropped if possible, but otherwise this is fairly brain dead.- Parameters:
interactionTerms-
-
getAssign
-
getBaseline
-
getDoubleMatrix
-
getLevelsForFactors
-
getMatrix
-
getDerivedLevelColumns
The contrasts aContrastCoding.SUM_TO_ZEROfactor needs but has no column for, as a map from the name such a column would have had to the design columns that determine it.A derived level's deviation is minus the sum of its factor's coefficients, and the variance of that sum needs the whole covariance block for those columns, not the individual variances -- which is why the columns are handed over rather than just the name.
LeastSquaresFitdoes the arithmetic per row, where the QR for that row is in hand.A factor's columns are identified by exact name (
factorName + level) rather than by prefix: factor names arefplus an id, sof10is a prefix off100and matching on prefixes would quietly pull another factor's columns into the sum.🛑 A factor whose columns do not come out at one per non-derived level is left out entirely. Dropped factors, interactions and any future change to how columns are named all land here, and a contrast that is missing is something a caller notices, whereas one computed over the wrong columns is not.
- Returns:
- derived-level column name to design column indices, empty when no factor is sum-coded
-
getTerms
-
getValuesForFactors
-
hasIntercept
public boolean hasIntercept() -
isHasIntercept
public boolean isHasIntercept() -
getContrastCoding
How the given factor's levels are coded into columns;ContrastCoding.TREATMENTunless set. -
setContrastCoding
Choose how one categorical factor's levels are coded, and rebuild the design.Per factor rather than per matrix on purpose: a design can hold a genotype factor with a real wild-type control and a tissue factor with no control at all, and those two want different codings in the same model.
The level that has no column of its own is the same one under either coding, so
setBaseline(String, String)still decides which level is derived rather than estimated — underContrastCoding.SUM_TO_ZEROit is not a baseline anything is measured against, only the one whose deviation is recovered from the others.- Throws:
IllegalArgumentException- if the factor is not in this design, or is continuous — a continuous covariate has one column and no levels, so there is nothing to code
-
setBaseline
-
toString
-
rebuild
protected void rebuild()Refresh the design matrix, for example after releveling.
-