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()orlmscFit(). 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 usecontrasts_fit()to obtain coefficients and standard errors for any number of contrasts of the coefficients of the original model. Unlike the design matrix input tolmFit(), which normally has one column for each treatment in the experiment, the matrixcontrastsmay have any number of columns and these are not required to be linearly independent. Methods of assessing differential expression, such aseBayes()orclassifyTestsF(), can then be applied to fitted model object.The
coefficientsargument provides a simpler way to specify thecontrastsmatrix 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 componentscoefficientsandstdev_unscaled.contrasts (pd.DataFrame) – numeric matrix with rows corresponding to coefficients in
fitand columns containing contrasts. May be a vector if there is only one contrast.NAare 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 probestdev_unscaled: matrix conformal withcoefficientscontaining the unscaled standard deviations for the coefficient estimatorscov_coefficients: matrix giving the unscaled covariance matrix of the estimable coefficients
Most other attributes of
fitare pass through unchanged, butt,p_value,lods,FandF_p_valuewill all be removed.- Return type: