predict.standardized: Place new data into an already existing standardized space.

Description Usage Arguments Value Note Author(s) Examples

View source: R/standardized-class.R

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

1
2
3
4
5
6
7
8
9
## S3 method for class 'standardized'
predict(
  object,
  newdata = NULL,
  response = FALSE,
  fixed = TRUE,
  random = TRUE,
  ...
)

Arguments

object

An object of class standardized.

newdata

Data to be placed into the same standardized space as the data in the call to standardize which produced the standardized object.

response

A logical (default FALSE) indicating whether newdata contains the response variable.

fixed

A logical (default TRUE) indicating whether newdata contains variables pertaining to the fixed effects.

random

A logical (default TRUE) indicating whether newdata contains variables pertaining to the random effects.

...

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## 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)

CDEager/standardize documentation built on March 13, 2021, 3:48 p.m.