Learn R Programming

pammtools (version 0.1.9)

make_newdata: Construct a data frame suitable for prediction

Description

Given a data set, returns a data set that can be used as newdata argument in a call to predict and similar functions. The function is particularly useful in combination with one of the add_* functions, e.g., add_term, add_hazard, etc.

Usage

make_newdata(x, ...)

# S3 method for default make_newdata(x, ...)

# S3 method for ped make_newdata(x, ...)

# S3 method for fped 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

Run this code
# NOT RUN {
tumor %>% make_newdata()
tumor %>% make_newdata(age=c(50))
tumor %>% make_newdata(days=seq_range(days, 3), age=c(50, 55))
tumor %>% make_newdata(days=seq_range(days, 3), status=unique(status), age=c(50, 55))
# mean/modus values of unspecified variables are calculated over whole data
tumor %>% make_newdata(sex=unique(sex))
tumor %>% group_by(sex) %>% make_newdata()
# You can also pass a part of the data sets as data frame to make_newdata
purrr::cross_df(list(days = c(0, 500, 1000), sex = c("male", "female"))) %>%
  make_newdata(x=tumor)

# Examples for PED data
ped <- tumor %>% slice(1:3) %>% as_ped(Surv(days, status)~., cut = c(0, 500, 1000))
ped %>% make_newdata(age=c(50, 55))
# if time information is specified, other time variables will be specified
# accordingly and offset calculated correctly
ped %>% make_newdata(tend = c(1000), age = c(50, 55))
ped %>% make_newdata(tend = unique(tend))
ped %>% group_by(sex) %>% make_newdata(tend = unique(tend))
# }

Run the code above in your browser using DataLab