Learn R Programming

pammtools (version 0.1.9)

gg_slice: Plot 1D (smooth) effects

Description

Flexible, high-level plotting function for (non-linear) effects conditional on further covariate specifications and potentially relative to a comparison specification.

Usage

gg_slice(data, model, term, ..., reference = NULL, ci = TRUE)

Arguments

data

Data used to fit the model.

model

A suitable model object which will be used to estimate the partial effect of term.

term

A character string indicating the model term for which partial effects should be plotted.

...

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.

reference

If specified, should be a list with covariate value pairs, e.g. list(x1 = 1, x2=50). The calculated partial effect will be relative to an observation specified in reference.

ci

Logical. Indicates if confidence intervals for the term of interest should be calculated/plotted. Defaults to TRUE.

Examples

Run this code
# NOT RUN {
ped <- tumor[1:200, ] %>% as_ped(Surv(days, status) ~ . )
model <- mgcv::gam(ped_status~s(tend) + s(age, by = complications), data=ped,
  family = poisson(), offset=offset)
make_newdata(ped, age = seq_range(age, 20), complications = levels(complications))
gg_slice(ped, model, "age", age=seq_range(age, 20), complications=levels(complications))
gg_slice(ped, model, "age", age=seq_range(age, 20), complications=levels(complications),
 ci = FALSE)
gg_slice(ped, model, "age", age=seq_range(age, 20), complications=levels(complications),
  reference=list(age = 50))
# }

Run the code above in your browser using DataLab