newdata: Construct a data frame suitable for prediction

Description Usage Arguments Details Examples

Description

Given a data set, returns a data set that can be used as newdata argument in a call to predict and similar functions.

Usage

1
2
3
4
make_newdata(x, ...)

## Default S3 method:
make_newdata(x, ...)

Arguments

x

A data frame (or object that inherits from data.frame).

...

Covariate specifications (expressions) that will be evaluated by looking for variables in x (or data). Must be of the form z = f(z) where z is a variable in the data set x and f a known function that can be usefully applied to z. See examples below.

Details

Depending on the class of x, mean or modus values will be used for variables not specified in ellipsis. If x is an object that inherits from class ped, useful data set completion will be attempted depending on variables specified in ellipsis.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
library(dplyr)
iris %>% make_newdata()
iris %>% make_newdata(Sepal.Length=c(5))
iris %>% make_newdata(Sepal.Length=seq_range(Sepal.Length, 3),
 Sepal.Width=c(2, 3))
iris %>% make_newdata(Sepal.Length=seq_range(Sepal.Length, 3),
 Species=unique(Species), Sepal.Width=c(2, 3))
# mean/modus values of unspecified variables are calculated over whole data
iris %>% make_newdata(Species=unique(Species))
iris %>% group_by(Species) %>% make_newdata()
# You can also pass a part of the data sets as data frame to make_newdata
purrr::cross_df(list(Sepal.Length = c(0, 500, 1000),
 Species = c("setosa", "versicolor"))) %>%
  make_newdata(x=iris)

adibender/mgcvtools documentation built on May 14, 2019, 7:55 p.m.