Package ubic.basecode.math.linearmodels
Class DesignMatrix
- java.lang.Object
-
- ubic.basecode.math.linearmodels.DesignMatrix
-
public class DesignMatrix extends Object
Represents the A matrix in regression problems posed as Ax=b. The starting point is a matrix of sample information, where the rows are sample names and the columns are the names of factors or covariates. Intercept and interaction terms can be added.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
Constructors Constructor Description DesignMatrix(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(ObjectMatrix<String,String,Object> sampleInfo)
Append additional factors/covariates to thisvoid
addInteraction()
Add interaction term; only works if there exactly two factors so this can figure out which interaction to add.void
addInteraction(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.List<Integer>
getAssign()
String
getBaseline(String factorName)
cern.colt.matrix.DoubleMatrix2D
getDoubleMatrix()
Collection<String[]>
getInteractionTerms()
Map<String,List<String>>
getLevelsForFactors()
DoubleMatrix<String,String>
getMatrix()
List<String>
getTerms()
Map<String,List<Object>>
getValuesForFactors()
boolean
hasIntercept()
boolean
isHasIntercept()
cern.colt.matrix.DoubleMatrix2D
makeContrasts()
In limma, the contrasts are built by referring to the coefficients by name, which isn't what we want.protected void
rebuild()
Refresh the design matrix, for example after releveling.void
setBaseline(String factorName, String baselineFactorValue)
String
toString()
-
-
-
Constructor Detail
-
DesignMatrix
public DesignMatrix(Object[] factor, int start, String factorName)
- Parameters:
factor
- in form of Doubles or Strings. Any other types will yield errors.start
-
-
DesignMatrix
public DesignMatrix(ObjectMatrix<String,String,? extends Object> sampleInfo)
- Parameters:
sampleInfo
- in form of Doubles or Strings. Any other types will yield errors.
-
DesignMatrix
public DesignMatrix(ObjectMatrix<String,String,?> sampleInfo, boolean intercept)
- Parameters:
sampleInfo
- in form of Doubles or Strings. Any other types will yield errors.intercept
-
-
DesignMatrix
public DesignMatrix(StringMatrix<String,String> sampleInfo)
-
DesignMatrix
public DesignMatrix(ObjectMatrix<String,String,Object> design, boolean intercept, boolean strict)
- 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 Detail
-
getInteractionTerms
public Collection<String[]> 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
public cern.colt.matrix.DoubleMatrix2D makeContrasts()
In limma, the contrasts are built by referring to the coefficients by name, which isn't what we want.- Returns:
-
add
public void add(ObjectMatrix<String,String,Object> sampleInfo)
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
public void addInteraction(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.- Parameters:
interactionTerms
-
-
getDoubleMatrix
public cern.colt.matrix.DoubleMatrix2D getDoubleMatrix()
-
getMatrix
public DoubleMatrix<String,String> getMatrix()
-
hasIntercept
public boolean hasIntercept()
-
isHasIntercept
public boolean isHasIntercept()
-
setBaseline
public void setBaseline(String factorName, String baselineFactorValue)
- Parameters:
factorName
-baselineFactorValue
-
-
rebuild
protected void rebuild()
Refresh the design matrix, for example after releveling.
-
-