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 Details

    • 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 model
      strict - 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

      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 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 -
    • getAssign

      public List<Integer> getAssign()
      Returns:
    • getBaseline

      public String getBaseline(String factorName)
    • getDoubleMatrix

      public DoubleMatrix2D getDoubleMatrix()
    • getLevelsForFactors

      public Map<String,List<String>> getLevelsForFactors()
    • getMatrix

      public DoubleMatrix<String,String> getMatrix()
    • getTerms

      public List<String> getTerms()
    • getValuesForFactors

      public Map<String,List<Object>> getValuesForFactors()
    • hasIntercept

      public boolean hasIntercept()
    • isHasIntercept

      public boolean isHasIntercept()
    • setBaseline

      public void setBaseline(String factorName, String baselineFactorValue)
      Parameters:
      factorName -
      baselineFactorValue -
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • rebuild

      protected void rebuild()
      Refresh the design matrix, for example after releveling.