Class PooledCovariances
- All Implemented Interfaces:
Serializable,Cloneable
Class PooledCovariances computes the pooled variance-covariance
matrix from one or more matrices of observations. The within-groups means are
also computed. Listwise deletion of missing values is assumed so that all
observations used are complete; for any row of x, if any element
of the observation is missing (with a value of Double.NaN), the
row is not used. This class should be used whenever the user suspects that
the data has been sampled from populations with different means but identical
variance-covariance matrices. If these assumptions cannot be made, a
different variance-covariance matrix should be estimated within each
group.
Group observation totals, \(T_i\) for i = 1, ..., g, where g is the number of groups, are computed as: $$T_i=\sum\limits_{j}w_{ij}f_{ij}x_{ij}$$
where \(w_{ij}\) is the observation weight, \(x_{ij}\) is the j-th observation in the i-th group, and \(f_{ij}\) is the observation frequency.
Modified Givens rotations are used in computing the Cholesky decomposition of the pooled sums of squares and crossproducts matrix (Golub and Van Loan 1983).
The group means and the pooled sample covariance matrix S are computed from intermediate results. These quantities are defined by
$$ \bar{x}_i=\frac{{T_i}}{{\sum\limits_{j}w_{ij}f_{ij}}} $$ $$ S=\frac{1}{\sum\limits_{ij}f_{ij}-g}\sum\limits_{ij}w_{ij}f_{ij} \big(x_{ij}-\bar{x}_i\big)\big(x_{ij}-\bar{x}_i\big)^T $$- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]Returns the number of observations in each group.double[][]getMeans()Returns the means of each group.intReturns the number of groups used in the analysis.intReturns the total number of observations that contain missing values (Double.NaNorgroup[i] == 0).intReturns the number of variables used in the analysis.double[][]Computes and returns the pooled covariances.double[]Returns the sum of the weights times the frequencies in the groups.intReturns the total number of observations used in the analysis.double[][]getU()Returns the lower matrix U, the lower triangular for the pooled sample crossproducts matrix.voidupdate(double[][] x) Updates the pooled covariances with new observations from one group.voidupdate(double[][] x, int[] groups) Updates the pooled covariances with new group observations.voidupdate(double[][] x, int[] groups, double[] frequencies, double weight) Updates the pooled covariances with new group observations, frequencies and a scalar weight.voidupdate(double[][] x, int[] groups, double[] frequencies, double[] weights) Updates the pooled covariances with new group observations, frequencies and weights.voidupdate(double[][] x, int[] groups, double frequency, double weight) Updates the pooled covariances with new group observations and a scalar frequency and weight.voidupdate(double[][] x, int[] groups, double frequency, double[] weights) Updates the pooled covariances with new group observations, a scalar frequency and weights.
-
Constructor Details
-
PooledCovariances
public PooledCovariances(int nGroups) Constructor forPooledCovariances.- Parameters:
nGroups- anint, the number of groups in the data. The groups are numbered 1, 2,...,nGroups.
-
-
Method Details
-
update
public void update(double[][] x) Updates the pooled covariances with new observations from one group.- Parameters:
x- adoublematrix containing the observed data. Each row ofxcontains one observation consisting ofx[0].lengthvariables. Ifx[i][j]has valueDouble.NaN, then row i of the observations will be skipped and counted as missing.The number of observation variables is determined in the first call to any of the
updatemethods. In all subsequentupdatecalls, the number of observation variables must be the same.This method assumes that all observations belong to group 1 and have frequencies and weights of 1.0.
-
update
public void update(double[][] x, int[] groups) Updates the pooled covariances with new group observations.- Parameters:
x- adoublematrix containing the observed data. Each row ofxcontains one observation consisting ofx[0].lengthvariables. Ifx[i][j]has valueDouble.NaN, then row i of the observations will be skipped and counted as missing.The number of observation variables is determined in the first call to any of the
updatemethods. In all subsequentupdatecalls, the number of observation variables must be the same.This method assumes that all observations have frequencies and weights of 1.0.
groups- anintarray containing the group number of the observations inx. Group numbers must be numbered 1, 2,...,nGroups. Ifgroups[i] == 0, the row of observations will be skipped and counted as missing. Forgroups[i]< 0 orgroups[i]>nGroups, a warning will be issued indicating that the row of observations will be skipped (not marked as missing).
-
update
public void update(double[][] x, int[] groups, double[] frequencies, double[] weights) Updates the pooled covariances with new group observations, frequencies and weights.- Parameters:
x- adoublematrix containing the observed data. Each row ofxcontains one observation consisting ofx[0].lengthvariables. Ifx[i][j]has valueDouble.NaN, then row i of the observations will be skipped and counted as missing.The number of observation variables is determined in the first call to any of the
updatemethods. In all subsequentupdatecalls, the number of observation variables must be the same.groups- anintarray containing the group number of the observations inx. Group numbers must be numbered 1, 2,...,nGroups. Ifgroups[i] == 0, the row of observations will be skipped and counted as missing. Forgroups[i]< 0 orgroups[i]>nGroups, a warning will be issued indicating that the row of observations will be skipped (not marked as missing).frequencies- adoublearray of sizex.lengthcontaining the frequency for each observation. Each value must be positive. AnyDouble.NaNvalue results in that observation being skipped and marked missing.weights- adoublearray of sizex.lengthcontaining the weight for each observation. Each value must be positive. AnyDouble.NaNvalue results in that observation being skipped and marked missing.
-
update
public void update(double[][] x, int[] groups, double frequency, double[] weights) Updates the pooled covariances with new group observations, a scalar frequency and weights.- Parameters:
x- adoublematrix containing the observed data. Each row ofxcontains one observation consisting ofx[0].lengthvariables. Ifx[i][j]has valueDouble.NaN, then row i of the observations will be skipped and counted as missing.The number of observation variables is determined in the first call to any of the
updatemethods. In all subsequentupdatecalls, the number of observation variables must be the same.groups- anintarray containing the group number of the observations inx. Group numbers must be numbered 1, 2,...,nGroups. Ifgroups[i] == 0, the row of observations will be skipped and counted as missing. Forgroups[i]< 0 orgroups[i]>nGroups, a warning will be issued indicating that the row of observations will be skipped (not marked as missing).frequency- a positivedoublecontaining the frequency valid for each observationweights- adoublearray of sizex.lengthcontaining the weight for each observation. Each value must be positive. AnyDouble.NaNvalue results in that observation being skipped and marked missing.
-
update
public void update(double[][] x, int[] groups, double[] frequencies, double weight) Updates the pooled covariances with new group observations, frequencies and a scalar weight.- Parameters:
x- adoublematrix containing the observed data. Each row ofxcontains one observation consisting ofx[0].lengthvariables. Ifx[i][j]has valueDouble.NaN, then row i of the observations will be skipped and counted as missing.The number of observation variables is determined in the first call to any of the
updatemethods. In all subsequentupdatecalls, the number of observation variables must be the same.groups- anintarray containing the group number of the observations inx. Group numbers must be numbered 1, 2,...,nGroups. Ifgroups[i] == 0, the row of observations will be skipped and counted as missing. Forgroups[i]< 0 orgroups[i]>nGroups, a warning will be issued indicating that the row of observations will be skipped (not marked as missing).frequencies- adoublearray of sizex.lengthcontaining the frequency for each observation. Each value must be positive. AnyDouble.NaNvalue results in that observation being skipped and marked missing.weight- a positivedoublecontaining the weight valid for each observation
-
update
public void update(double[][] x, int[] groups, double frequency, double weight) Updates the pooled covariances with new group observations and a scalar frequency and weight.- Parameters:
x- adoublematrix containing the observed data. Each row ofxcontains one observation consisting ofx[0].lengthvariables. Ifx[i][j]has valueDouble.NaN, then row i of the observations will be skipped and counted as missing.The number of observation variables is determined in the first call to any of the
updatemethods. In all subsequentupdatecalls, the number of observation variables must be the same.groups- anintarray containing the group number of the observations inx. Group numbers must be numbered 1, 2,...,nGroups. Ifgroups[i] == 0, the row of observations will be skipped and counted as missing. Forgroups[i]< 0 orgroups[i]>nGroups, a warning will be issued indicating that the row of observations will be skipped (not marked as missing).frequency- a positivedoublecontaining the frequency valid for each observationweight- a positivedoublecontaining the weight valid for each observation
-
getPooledCovariances
public double[][] getPooledCovariances()Computes and returns the pooled covariances.Note that one of the
updatemethods must be invoked first before invoking this method. Otherwise, the method throws anIllegalStateExceptionexception.- Returns:
- a square
doublematrix of ordernVar, the number of observation variables, containing the pooled covariances
-
getGroupCounts
public int[] getGroupCounts()Returns the number of observations in each group.- Returns:
- an
intarray of lengthnGroupscontaining the number of observations in each group
-
getSumOfWeights
public double[] getSumOfWeights()Returns the sum of the weights times the frequencies in the groups.- Returns:
- a
doublearray of lengthnGroupscontaining the sum of the weights times the frequencies in the groups
-
getMeans
public double[][] getMeans()Returns the means of each group.Note that one of the
updatemethods must be invoked first before invoking this method. Otherwise, the method throws anIllegalStateExceptionexception.- Returns:
- a
doublematrix withnGroupsrows. The i-th row contains the group i variable means.
-
getU
public double[][] getU()Returns the lower matrix U, the lower triangular for the pooled sample crossproducts matrix. U is computed from the pooled sample covariance matrix, S, as \(S=U^TU\).Note that one of the
updatemethods must be invoked first before invoking this method. Otherwise, the method throws anIllegalStateExceptionexception.- Returns:
- a square
doublematrix of ordernVar, the number of observation variables, containing U
-
getNumberOfMissingRows
public int getNumberOfMissingRows()Returns the total number of observations that contain missing values (Double.NaNorgroup[i] == 0).- Returns:
- an
intcontaining the total number of observations with missing values
-
getTotalNumberOfObservations
public int getTotalNumberOfObservations()Returns the total number of observations used in the analysis.- Returns:
- an
int, the total number of observations from allupdateinvocations
-
getNumberOfVariables
public int getNumberOfVariables()Returns the number of variables used in the analysis.- Returns:
- an
int, the number of variables
-
getNumberOfGroups
public int getNumberOfGroups()Returns the number of groups used in the analysis.- Returns:
- an
int, the number of groups
-