Learn R Programming

optmatch (version 0.9-3)

scores: Wrapper for predict to cleanly look for new data to predict on.

Description

When called without a newdata argument, it will attempt to determine the correct new data to predict on; e.g. in a lm or glm model, will use the data in that model.

Usage

scores(object, newdata = NULL, ...)

Arguments

object
a model object from which prediction is desired.
newdata
optionally, specifies a data frame in which to look for variables to predict with. When omitted, attempts to intelligently use the correct data frame as opposed to predict using the data originally used to create object.
...
additional arguments passed to predict.

Value

  • See individual predict functions.

Details

If newdata (either the explicit argument, or the implicit data generated from object) has NA values, imputation will be performed on the missing data via the fill.NAs function and object will be refit using the imputed data frame, before calling predict

If newdata is specified and contains no missing data, this is identical to calling predict.

If the call to create object is involved, particularly if it includes optional arguments such as subset or weights whose values reference the data, this function may fail or otherwise have undesirable results if the newdata argument is not given. It is therefore strongly recommended to include the newdata argument in these sort of situations.

See Also

predict

Examples

Run this code
data(nuclearplants)
pg <- lm(cost~., data=nuclearplants, subset=(pr==0))
# The following two lines produce identical results.
ps1 <- glm(pr~cap+date+t1+bw+predict(pg, newdata=nuclearplants), data=nuclearplants)
ps2 <- glm(pr~cap+date+t1+bw+scores(pg), data=nuclearplants)

Run the code above in your browser using DataLab