Make Predictions from a Fitted fac.aov Object

DESCRIPTION:

Predictions for a fac.aov object that are useful in the context of robust design. This function allows factors to be interpreted as numeric variables, so predicted values can be estimated at intermediate values.

USAGE:

predict.fac.aov(object, newdata, type=c("response", "terms"), 
     se.fit=F, numeric.levels=NULL, coerce = F, ...) 

REQUIRED ARGUMENTS:

object
a fitted fac.aov object.

OPTIONAL ARGUMENTS:

newdata
a data frame containing the values at which predictions are required. If this argument is missing, predictions are made at the same values used to compute the object. Only those predictors referred to in the right hand side of the formula in object need to be present by name in newdata.
type
the type of predictions, with choices "response" (the default), or "terms". The default gives predictions of the response, terms gives a matrix of predictions with a column for each term in the model.
se.fit
logical value. If TRUE, pointwise standard errors are computed along with the predictions.
numeric.levels
a list specifying the number corresponding to levels of the factors in the original model object.
coerce
logical value for whether to allow the factor levels to be coerced to integers.

VALUE:

A vector or matrix of predictions, or a list consisting of the predictions and their standard errors if se.fit = T. If type = "terms", a matrix of fitted terms is produced, with one column for each terms in the model. There is no column for the intercept, and each of the terms is centered so that its average over the original data is zero. The matrix of fitted terms has a "constant" attribute, which, when added to the sum of these centered terms, gives the prediction.

DETAILS:

This function is a method for the generic function for class fac.aov. It can be invoked by calling for an object x of the appropriate class, or directly by calling regardless of the class of the object.

This predict function allows the factors to be interpreted as numeric variables, so that predictions can be computed between the factor levels. For example, if the factor settings are 100 and 200, you can ask for a prediction at 120. To do this the factor levels of the data for the model object must be assigned numeric levels. If the factor levels can be coerced to numeric via as.numeric(levels(factor)), you do not have to specify numeric.levels. If not, this argument is used to associate levels with the factor levels. Each factor to be interpreted numerically is named in the list, with a vector of numeric levels matching the length of the levels for that factor.

This function is particularly useful with robust designs, generated by robust.sn on designs of class robust.design. In these designs, where the factors levels are two or three evenly spaced numeric values of some continuous factor, it is reasonable to want to predict the response at some intermediate level of the factor. In S-PLUS, since factors and numeric variables are different data types, this can only be done with special purpose code provided by safe.predict.fac.aov .

safe.predict.fac.aov is called if new.data, the data frame for prediction, contains numeric data, where the original model has a factor. The original data is converted to a numeric data set, using numeric levels for the factor levels, as described in the argument numeric.levels. An equivalent model to the original model the refit to these data, and the prediction for new.data is based on this new model. This procedure requires the factor levels of the original data to be equally spaced (if there are more than two levels).

SEE ALSO:

, , , .

EXAMPLES:

mold.sn <- robust.sn(mold.df) 
mold.facs <- fac.aov(shrink.mean~ A + C + H, mold.sn) 
newdata <- data.frame(A = c(.7, .5,-.5, -.7), C = rep(-1,4),  
      H = rep(-1,4)) 
mold.pred <- predict(mold.facs, newdata, numeric.levels =  
      list(A = c(-1, 1),C = c(-1, 1), H = c(-1,1))) 
mold.pred <- predict(mold.facs, newdata, coerce = T)