predict.standardized {standardize} | R Documentation |
Place new data into an already existing standardized space.
Description
To put new data into the same standardized space as the data in the
standardized
object,
predict
can be used with the standardized
object as the first
argument. The predict
method also allows logicals response
,
fixed
, and random
to be used to specify which elements of the
original data frame are present in newdata
. A regression model
fit with the formula
and data
elements of a
standardized
object cannot be used to
directly predict the response variable for new data. The new data must
first be placed into the standardized space. If offsets were included
in the formula
argument used to create the standardized
object,
then when fixed = TRUE
the offset variables must be in newdata
.
If an offset was passed to the offset
argument in the call to
standardize
, then the offset cannot be passed to predict
.
Usage
## S3 method for class 'standardized'
predict(
object,
newdata = NULL,
response = FALSE,
fixed = TRUE,
random = TRUE,
...
)
Arguments
object |
An object of class |
newdata |
Data to be placed into the same standardized space as the
data in the call to |
response |
A logical (default |
fixed |
A logical (default |
random |
A logical (default |
... |
Ignored with a warning. |
Value
A data.frame with the newdata
standardized using the
pred
element of the standardized
object.
Note
You may see a warning "contrasts dropped from factor <x>" for each factor when predicting new data with a fitted model object, but this warning can be ignored (the actual predictions will still be correct).
Author(s)
Christopher D. Eager <eager.stats@gmail.com>
Examples
## Not run:
train <- subset(mydata, train)
test <- subset(mydata, !train)
train.s <- standardize(y ~ x1 + f1 + (1 | g1), train)
mod <- lmer(train.s$formula, train.s$data)
test.s <- predict(train.s, test, response = TRUE)
preds <- predict(mod, newdata = test.s) # can ignore warning about dropped contrasts
res <- test.s$y - preds
## End(Not run)