Class 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 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​(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 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 -
      • getAssign

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

        public String getBaseline​(String factorName)
      • getDoubleMatrix

        public cern.colt.matrix.DoubleMatrix2D getDoubleMatrix()
      • 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.