data_slice | R Documentation |
Prepare a data slice through model covariates
data_slice(object, ...) ## Default S3 method: data_slice(object, ...) ## S3 method for class 'gam' data_slice(object, ..., data = NULL) ## S3 method for class 'gamm' data_slice(object, ...) ## S3 method for class 'list' data_slice(object, ...)
object |
an R model object. |
... |
< |
data |
an alternative data frame of values containing all the variables
needed to fit the model. If |
load_mgcv() # simulate some Gaussian data df <- data_sim("eg1", n = 50, seed = 2) # fit a GAM with 1 smooth and 1 linear term m1 <- gam(y ~ s(x2, k = 7) + x1, data = df, method = "REML") # Want to predict over f(x2) while holding `x1` at some value. # Default will use the observation closest to the median for unspecified # variables. ds <- data_slice(m1, x2 = evenly(x2, n = 50)) # for full control, specify the values you want ds <- data_slice(m1, x2 = evenly(x2, n = 50), x1 = 0.3) # or provide an expression (function call) which will be evaluated in the # data frame passed to `data` or `model.frame(object)` ds <- data_slice(m1, x2 = evenly(x2, n = 50), x1 = mean(x1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.