inmoose.limma.contrasts_fit

inmoose.limma.contrasts_fit(fit, contrasts=None, coefficients=None)

Compute contrasts from linear model fit

Given a linear model fit to microarray data, compute estimated coefficients and standard errors for a given set of contrasts.

This function accepts input from any of the functions lmFit(), lm_series(), mrlm(), gls_series() or lmscFit(). The function reorientates the fitted model object from the coefficients of the original design matrix to any set of contrasts of the original coefficients. The coefficients, unscaled standard deviations and correlation matrix are re-calculated in terms of the contrasts.

The idea of this function is to fit a full-rank model using lmFit() or equivalent, then use contrasts_fit() to obtain coefficients and standard errors for any number of contrasts of the coefficients of the original model. Unlike the design matrix input to lmFit(), which normally has one column for each treatment in the experiment, the matrix contrasts may have any number of columns and these are not required to be linearly independent. Methods of assessing differential expression, such as eBayes() or classifyTestsF(), can then be applied to fitted model object.

The coefficients argument provides a simpler way to specify the contrasts matrix when the desired contrasts are just a subset of the original coefficients.

Note

For efficiency reasons, this function does not re-factorize the design matrix for each probe. A consequence is that, if the design matrix is non-orthogonal and original fit included precision weights or missing values, then the unscaled standard deviations produced by this function are approximate rather than exact. The approximation is usually acceptable. If not, then the issue can be avoided by redefining the design matrix to fit the contrasts directly.

Even with precision weights, the results from contrasts_fit() are always exact if the coefficients being compared are statistically independent. This will be true, for example, if the original fit was a oneway model without blocking and the group-means (no-intercept) parameterization was used for the design matrix.

Parameters:
  • fit (MArrayLM) – object produced by lm_series() or equivalent. Must contain components coefficients and stdev_unscaled.

  • contrasts (pd.DataFrame) – numeric matrix with rows corresponding to coefficients in fit and columns containing contrasts. May be a vector if there is only one contrast. NA are not allowed.

  • coefficients (array_like) – array indicating which coefficients are to be kept in the revised fit object. An alternative way to specify the contrasts.

Returns:

an object of the same class as fit, with components:

  • coefficients: matrix containing the estimated coefficients for each contrast for each probe

  • stdev_unscaled: matrix conformal with coefficients containing the unscaled standard deviations for the coefficient estimators

  • cov_coefficients: matrix giving the unscaled covariance matrix of the estimable coefficients

Most other attributes of fit are pass through unchanged, but t, p_value, lods, F and F_p_value will all be removed.

Return type:

MArrayLM