Class ANCOVA
- All Implemented Interfaces:
Serializable,Cloneable
ANCOVA performs analysis for models that combine the
features of a oneway analysis of variance model with that of a multiple
linear regression model. The basic one-way analysis of covariance model is
$$y_{ij}=\beta_{0i}+\beta_{1}x_{ij1}+\beta_{2}x_{ij2}
+\ldots+\beta_mx_{ijm}+\varepsilon_{ij}$$
$$i=1,2,\ldots,ngroup$$
$$j=1,2,\ldots,n_i$$
where, ngroup is the number of treatment groups, the observed value of
\(y_{ij}\) constitutes the j-th response in the i
-th group, \(\beta_{0i}\) denotes the y intercept for
the regression function for the i-th group, \(\beta_{1}
\), \(\beta_{2}\), ..., \(\beta_{m}
\) are the regression coefficients for the covariates, and the
\(\varepsilon_{ij}\)'s are independently distributed normal
errors with mean zero and variance \(\sigma^2\). This model
allows the regression function for each group to have different intercepts.
However, the remaining m regression coefficients are the same for each
group, i.e., the regression functions are parallel.
In practice, sometimes the regression functions are not parallel. In
addition to estimates for the model assuming parallelism (parallel regression
planes), ANCOVA computes estimates and summary statistics for
the separate regressions of each group. These estimates can be examined using
the methods getCoefficientTables and
getANOVATables.
Estimates for the \(\beta_{0i}\)'s and \(
\beta_{1}\), \(\beta_{2}\), ..., \(
\beta_{m}\) in the model assuming parallelism are returned using the
method getModelCoefficients. Summary statistics are
also computed for this model and returned by the compute method.
The adjusted group means, stored in the last column of xymean, are computed using the formula:
$$\hat{\beta}_{0i}+\hat{\beta}_{1}\overline{x}_{1}+ \hat{\beta}_{2}\overline{x}_{2}+\ldots+\hat{\beta}_{ncov}\overline{x}_{ncov} $$where xymean is the matrix returned by getMeans and
ncov is the number of covariates.
The estimated covariance between the \(i_{1}\)-th and \(i_{2}\)-th adjusted group mean is given by
$$\nu_{i_{1}i_{2}}+\sum_{r=1}^{m}\sum_{s=1}^{m} \overline{x}_{r}\nu_{k+r, k+s}\overline{x}_{s}+\sum_{r=1}^{m}\overline{x}_{r} \nu_{i_{1}, k+r}+\sum_{r=1}^{m}\overline{x}_{r}\nu_{i_{2}, k+r}$$where \(\nu_{pq}\) is the entry in
covb[p-1][q-1], where covb is returned by
getVarCovCoefficients and is the estimated covariance between
the p-th and q-th estimated coefficients in the regression
function.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionANCOVA(double[][] responses, double[][][] covariates) Constructs a one-way classification model with covariates. -
Method Summary
Modifier and TypeMethodDescriptiondouble[]compute()Performs one-way analysis of covariance assuming parallelism and returns an array containing the parallelism tests for the one-way analysis of covariance.double[]Returns the partial sum of squares for the one-way analysis of covariance.double[]Returns an array containing the one-way analysis of covariance assuming parallelism.double[][]Returns a matrix of size ngroup by 15 containing the analysis of variance tables for each linear regression model fitted separately to each treatment group.double[][]getCoefficientTable(int group) Returns a matrix of size ncov + 1 by 4 containing statistics for a linear regression model fitted separately for each of the ngroup treatment groups.double[][][]Returns an array containing statistics for a linear regression model fitted separately for all ngroup treatments.double[][]getMeans()Returns a matrix containing the unadjusted means for the covariates and the response variate and the means for the response variate adjusted for the covariates.double[][]Returns a matrix containing statistics for the regression coefficients for the model assuming parallelism.intReturns the number of cases with missing values incovariatesorresponses.double[][]getR()Returns the R matrix from the QR decomposition.double[][]Returns a matrix containing the estimated variances and covariances for the adjusted means assuming parallelism.double[][]Returns a matrix containing the estimated variances and covariances for the coefficients returned usinggetModelCoefficients.
-
Constructor Details
-
ANCOVA
public ANCOVA(double[][] responses, double[][][] covariates) Constructs a one-way classification model with covariates.- Parameters:
responses- adoublematrix containing the responses. Each row inresponsescorresponds to a treatment group. Each row ofresponsescan contain a different number of observations. There must be at least two groups (\(responses.length > 1 \)).covariates- is a three-dimensionaldoublearray containing the covariates. The first dimension corresponds to the number of covariates (consider each element an individual covariate matrix orcovariates.length= number of covariates). Each row incovariates[i]corresponds to a treatment group. There must be the same number of rows, for each covariate, as there are in the responses matrix (covariates[i].length = responses.length). There must be at least one covariate (\(covariate.length > 1\)). Each row ofcovariates[i]must contain the same number of elements as the corresponding row inresponses
(covariates[i][j].length = responses[j].length).
-
-
Method Details
-
getANCOVA
public double[] getANCOVA()Returns an array containing the one-way analysis of covariance assuming parallelism.- Returns:
- a
doublearray of length 15 containing the following values:index ANCOVA Table Value 0 Degrees of freedom for model 1 Degrees of freedom for error 2 Total degrees of freedom 3 Sum of squares for model 4 Sum of squares for error 5 Total sum of squares 6 Model mean square 7 Error mean square 8 F statistic 9 p-value 10 R-squared (in percent) 11 Adjusted R-squared (in percent) 12 Estimated standard deviation of the model error 13 Mean of the response (dependent variable) 14 Coefficient of variation (in percent)
-
getNumberOfMissing
public int getNumberOfMissing()Returns the number of cases with missing values incovariatesorresponses. Cases with any missing values are not used in the analysis.- Returns:
- an
intscalar value indicating the number of cases with missing values incovariatesorresponses.
-
getAdjustedANOVA
public double[] getAdjustedANOVA()Returns the partial sum of squares for the one-way analysis of covariance.- Returns:
- a
doublearray containing the partial sum of squares for the one-way analysis of covariance organized as follows:index Description 0 Degrees of freedom for groups after covariates. 1 Degrees of freedom for covariates after groups. 2 Sum of squares for groups after covariates. 3 Sum of squares for model (groups and covariates combined). 4 F-statistic for groups. 5 F-statistic for covariates. 6 p-value for groups. 7 p-value for covariates.
-
getMeans
public double[][] getMeans()Returns a matrix containing the unadjusted means for the covariates and the response variate and the means for the response variate adjusted for the covariates.- Returns:
- a
doublematrix of size ngroup + 1 by ncov + 3 containing the unadjusted means for the covariates and the response variate and the means for the response variate adjusted for the covariates. Each row for i = 0, 1, ..., ngroup - 1 corresponds to a group. Row ngroup contains overall statistics. The means are organized in columns as follows:Column Description 0 Number of non-missing cases 1 thru ncov Covariate means. ncov + 1 Response mean. ncov + 2 Response mean adjusted assuming parallelism.
-
getModelCoefficients
public double[][] getModelCoefficients()Returns a matrix containing statistics for the regression coefficients for the model assuming parallelism.- Returns:
- a
doublematrix of size ngroup + ncov by 4 containing statistics for the regression coefficients for the model assuming parallelism. Each row corresponds to a coefficient in the model. For i = 0, 1, ..., ngroup - 1, rowiis for the y intercept for the i -th group. The remaining ncov rows are for the covariate coefficients. The statistics in the columns are organized as follows:Column Description 0 Coefficient estimate. 1 Estimated standard error of the estimate. 2 t-statistic. 3 p-value.
-
getCoefficientTable
public double[][] getCoefficientTable(int group) Returns a matrix of size ncov + 1 by 4 containing statistics for a linear regression model fitted separately for each of the ngroup treatment groups.- Parameters:
group- anintspecifying the group that regression statistics will be retreived for.- Returns:
- a
doublematrix containing statistics for agroup. Each row corresponds to the model coefficients. For row = 0, the statistics relate to the intercept in the regression model. For row = 1, 2, ..., ncov, the statistics relate to the slopes for the covariates. The column dimension corresponds to the row described forgetModelCoefficientsas follows:Column Description 0 Coefficient estimate. 1 Estimated standard error of the estimate. 2 t-statistic. 3 p-value.
-
getCoefficientTables
public double[][][] getCoefficientTables()Returns an array containing statistics for a linear regression model fitted separately for all ngroup treatments.- Returns:
- a
double[][][]array containing statistics for a linear regression model fitted separately for each of the ngroup treatment groups. The 3 dimensional array organized with ngroup rows, ncov + 1 columns, and depth of 4. Each row corresponds to one of the ngroup treatment groups. Each column corresponds to the model coefficients. For column = 0, the statistics relate to the intercept in the regression model. For column = 1, 2, ..., ncov, the statistics relate to the slopes for the covariates. The depth dimension corresponds to the columns described forgetModelCoefficientsas follows:Column Description 0 Coefficient estimate. 1 Estimated standard error of the estimate. 2 t-statistic. 3 p-value.
-
getANOVATables
public double[][] getANOVATables()Returns a matrix of size ngroup by 15 containing the analysis of variance tables for each linear regression model fitted separately to each treatment group.- Returns:
- a
doublematrix containing the analysis of variance tables for each linear regression model fitted separately to each treatment group. The 15 values in the i-th row are for treatment group i organized as follows:index Description 0 Degrees of freedom for model 1 Degrees of freedom for error 2 Total degrees of freedom 3 Sum of squares for model 4 Sum of squares for error 5 Total sum of squares 6 Model mean square 7 Error mean square 8 F statistic 9 p-value 10 R-squared (in percent) 11 Adjusted R-squared (in percent) 12 Estimated standard deviation of the model error 13 Mean of the response (dependent variable) 14 Coefficient of variation (in percent)
-
getR
public double[][] getR()Returns the R matrix from the QR decomposition. The R matrix is from the regression assuming parallelism.- Returns:
- a
doublematrix of size ngroup + ncov by ngroup + ncov which contains the R from the QR decomposition. The R matrix is from the regression assuming parallelism.
-
getVarCovAdjustedMeans
public double[][] getVarCovAdjustedMeans()Returns a matrix containing the estimated variances and covariances for the adjusted means assuming parallelism.- Returns:
- a
doublematrix of size ngroup by ngroup containing the estimated variances and covariances for the adjusted means assuming parallelism.
-
getVarCovCoefficients
public double[][] getVarCovCoefficients()Returns a matrix containing the estimated variances and covariances for the coefficients returned usinggetModelCoefficients.- Returns:
- a
matrixof size ngroup + ncov by ngroup + ncov containing the estimated variances and covariances for the coefficients returned usinggetModelCoefficients.
-
compute
public double[] compute()Performs one-way analysis of covariance assuming parallelism and returns an array containing the parallelism tests for the one-way analysis of covariance.- Returns:
- a
doublearray containing the parallelism tests for the one-way analysis of covariance organized as follows:indexDescription0 Extra degrees of freedom for model not assuming parallelism. 1 Degrees of freedom for error for model not assuming parallelism. 2 Degrees of freedom for error for model assuming parallelism. 3 Extra sum of squares for model not assuming parallelism. 4 Sum of squares for error for model not assuming parallelism. 5 Sum of squares for error for model assuming parallelism. 6 Mean square for index = 0. 7 Mean square for index = 1. 8 F statistic 9 p-value
-