g02bx calculates the sample means, the standard deviations, the variance-covariance matrix, and the matrix of Pearson product-moment correlation coefficients for a set of data. Weights may be used.
Syntax
C# |
---|
public static void g02bx( string weight, int n, int m, double[,] x, double[] wt, double[] xbar, double[] std, double[,] v, double[,] r, out int ifail ) |
Visual Basic |
---|
Public Shared Sub g02bx ( _ weight As String, _ n As Integer, _ m As Integer, _ x As Double(,), _ wt As Double(), _ xbar As Double(), _ std As Double(), _ v As Double(,), _ r As Double(,), _ <OutAttribute> ByRef ifail As Integer _ ) |
Visual C++ |
---|
public: static void g02bx( String^ weight, int n, int m, array<double,2>^ x, array<double>^ wt, array<double>^ xbar, array<double>^ std, array<double,2>^ v, array<double,2>^ r, [OutAttribute] int% ifail ) |
F# |
---|
static member g02bx : weight : string * n : int * m : int * x : float[,] * wt : float[] * xbar : float[] * std : float[] * v : float[,] * r : float[,] * ifail : int byref -> unit |
Parameters
- weight
- Type: System..::..StringOn entry: indicates whether weights are to be used.
- Weights are not used and unit weights are assumed.
- or
- Weights are used and must be supplied in wt. The only difference between or is in computing the variance. If the divisor for the variance is the sum of the weights minus one and if the divisor is the number of observations with nonzero weights minus one. The former is useful if the weights represent the frequency of the observed values.
Constraint: , or .
- n
- Type: System..::..Int32On entry: the number of data observations in the sample.Constraint: .
- m
- Type: System..::..Int32On entry: the number of variables.Constraint: .
- x
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, m]Note: dim1 must satisfy the constraint:On entry: must contain the th observation for the th variable, for and .
- wt
- Type: array<System..::..Double>[]()[][]An array of size [dim1]Note: the dimension of the array wt must be at least if or , and at least otherwise.On entry: , the optional frequency weighting for each observation, with . Usually will be an integral value corresponding to the number of observations associated with the th data value, or zero if the th data value is to be ignored. If , is set to for all and wt is not referenced.Constraint: if or , , , for .
- xbar
- Type: array<System..::..Double>[]()[][]An array of size [m]On exit: the sample means. contains the mean of the th variable.
- std
- Type: array<System..::..Double>[]()[][]An array of size [m]On exit: the standard deviations. contains the standard deviation for the th variable.
- v
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, m]Note: dim1 must satisfy the constraint:On exit: the variance-covariance matrix. contains the covariance between variables and , for and .
- r
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, m]Note: dim1 must satisfy the constraint:On exit: the matrix of Pearson product-moment correlation coefficients. contains the correlation coefficient between variables and .
- ifail
- Type: System..::..Int32%On exit: unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).
Description
For observations on variables the one-pass algorithm of West (1979) as implemented in g02bu is used to compute the means, the standard deviations, the variance-covariance matrix, and the Pearson product-moment correlation matrix for selected variables. Suitables weights may be used to indicate multiple observations and to remove missing values. The quantities are defined by:
(a) The means
(b) The variance-covariance matrix
(c) The standard deviations
(d) The Pearson product-moment correlation coefficients
where is the value of the th observation on the th variable and is the weight for the th observation which will be 1 in the unweighted case.
Note that the denominator for the variance-covariance is , so the weights should be scaled so that the sum of weights reflects the true sample size.
References
Chan T F, Golub G H and Leveque R J (1982) Updating Formulae and a Pairwise Algorithm for Computing Sample Variances Compstat, Physica-Verlag
West D H D (1979) Updating mean and variance estimates: An improved method Comm. ACM 22 532–555
Error Indicators and Warnings
Note: g02bx may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface
(LDX, LDV) In these
cases, an error in another parameter has usually caused an incorrect value to be inferred.
On entry, , or ,
On entry, , or .
On entry, or and a value of .
- and the sum of weights is not greater than , or and fewer than observations have nonzero weights.
Accuracy
For a discussion of the accuracy of the one pass algorithm see Chan et al. (1982) and West (1979).
Parallelism and Performance
None.
Further Comments
None.
Example
The data are some of the results from 1988 Olympic Decathlon. They are the times (in seconds) for the 100m and 400m races and the distances (in metres) for the long jump, high jump and shot. Twenty observations are input and the correlation matrix is computed and printed.
Example program (C#): g02bxe.cs