Use cov.mcd with a formula Object

DESCRIPTION:

Returns a list of class mcd containing estimates of the robust multivariate location, the robust covariance matrix, and optionally the robust correlation matrix. Specifically, the cov.mcd.formula function first returns the minimum covariance determinant (MCD) estimator of Rousseeuw (1984, 1985). Then the MCD estimate is used to assign weights to the objects, and also weighted estimates of location and covariance are returned. This is a method for the function cov.mcd for formula objects.

USAGE:

cov.mcd.formula(formula, data=<<see below>>, weights,  
                subset=<<see below>>, na.action=na.fail, model=F, 
                x=F, cor=F, print=T, quan=<<see below>>, 
                ntrial=<<see below>>) 

REQUIRED ARGUMENTS:

formula
a formula object, with terms separated by + operators, to the right of a ~ operator.

OPTIONAL ARGUMENTS:

data
a data frame in which to interpret the variables named in the formula, or in the subset argument. If this is missing, then the variables in the formula should be on the search list. This may also be a single number to handle some special cases -- see below for details.
subset
expression saying which subset of the rows of the data should be used. This can be a logical vector which is replicated to have length equal to the number of observations, a numeric vector indicating which observation numbers are to be included, or a character vector of the row names to be included. By default, all observations are included.
weights
The current version of cov.mcd.formula does not allow input weights.
na.action
a function to filter missing data. This is applied to the model.frame after any subset argument has been used. The default (with na.fail) is to create an error if any missing values are found. A possible alternative is na.exclude, which deletes observations that contain one or more missing values.
model
logical flag: if TRUE, the model frame is returned in component model.
x
logical flag: if TRUE, the model matrix is returned in component x.
cor
logical flag: if TRUE, then the estimated correlation matrix will be returned as well.
print
logical flag: if TRUE, information about the method will be printed.
quan
the number of observations that will determine the minimum covariance determinant estimator. The default is floor((n+p+1)/2), where n is the number of observations and p is the number of variables.
ntrial
the number of random trial subsamples that are drawn for large datasets. The default is 500.

VALUE:

an object of class "mcd" representing the minimum covariance determinant estimates. See the mcd.object help file for details.

SIDE EFFECTS:

If print is TRUE, then a message is printed.

DETAILS:

The formula argument is passed around unevaluated; that is, the variables mentioned in the formula will be defined when the model frame is computed, not when cov.mcd.formula is initially called. In particular, if data is given, all these names should generally be defined as variables in that data frame.

The subset argument, like the terms in the formula, is evaluated in the context of the data frame, if present. The specific action of the argument is as follows: the model frame, including subset, is computed on all the rows, and then the appropriate subset is extracted. A variety of special cases make such an interpretation desirable (e.g., the use of lag or other functions that may need more than the data used in the computation to be fully defined). On the other hand, if you meant the subset to avoid computing undefined values or to escape warning messages, you may be surprised. For example, cov.mcd(~ log(x), mydata, subset = x > 0) will still generate warnings from log. If this is a problem, do the subsetting on the data frame directly: cov.mcd(~ log(x), mydata[,mydata$x > 0])

cov.mcd.default is called when the model frame has been computed. See the cov.mcd.default help file for details on the computational algorithm.

NAMES. Variables occurring in a formula are evaluated differently from arguments to S-PLUS functions, because the formula is an object that is passed around unevaluated from one function to another. The functions, such as cov.mcd.formula, that finally arrange to evaluate the variables in the formula try to establish a context based on the data argument. More precisely, the function model.frame.default does the actual evaluation, assuming that its caller behaves in the way described here. If the data argument to cov.mcd.formula is missing or is an object (typically, a data frame), then the local context for variable names is the frame of the function that called cov.mcd.formula, or the top-level expression frame if the user called cov.mcd.formula directly. Names in the formula can refer to variables in the local context as well as global variables or variables in the data object.

The data argument can also be a number, in which case that number defines the local context. This can arise, for example, if a function is written to call cov.mcd.formula , perhaps in a loop, but the local context is definitely not that function. In this case, the function can set data to sys.parent(), and the local context will be the next function up the calling stack. See the second example below. A numeric value for data can also be supplied if a local context is being explicitly created by a call to new.frame. Notice that supplying data as a number implies that this is the only local context; local variables in any other function will not be available when the model frame is evaluated. This is potentially subtle. Fortunately, it is not something the ordinary user of cov.mcd.formula needs to worry about. It is relevant for those writing functions that call cov.mcd.formula.

REFERENCES:

Rousseeuw, P. J. (1984). Least median of squares regression. Journal of American Statistical Association, 79, 871-881.

Rousseeuw, P. J. (1985). Multivariate estimation with high breakdown point. In Mathematical Statistics and Applications. W. Grossmann, G. Pflug, I. Vincze and W. Wertz, eds. Reidel: Dordrecht, 283-297.

Rousseeuw, P. J. and Leroy, A. M. (1987). Robust Regression and Outlier Detection. Wiley-Interscience, New York. [Chapter 7]

Rousseeuw, P. J. and van Zomeren, B. C. (1990). Unmasking multivariate outliers and leverage points. Journal of the American Statistical Association, 85, 633-639.

Rousseeuw, P.J. and Van Driessen, K. (1997). A fast algorithm for the minimum covariance determinant estimator. in preparation.

SEE ALSO:

, , , , , , .

EXAMPLES:

cov.mcd(~wind+radiation+temperature, data=air) 
# mymcd calls cov.mcd, using the caller to mymcd 
# as the local context for variables in the formula 
# (see aov for an actual example) 
mymcd <- function(formula, data = sys.parent(), ...) { 
    .. .. 
    mcd <- cov.mcd(formula, data, ...) 
    .. .. 
}