Learn R Programming

gratia (version 0.9.0)

fitted_values: Generate fitted values from a estimated GAM

Description

Generate fitted values from a estimated GAM

Usage

fitted_values(object, ...)

# S3 method for gam fitted_values( object, data = NULL, scale = c("response", "link", "linear predictor"), ci_level = 0.95, ... )

# S3 method for gamm fitted_values(object, ...)

# S3 method for scam fitted_values(object, ...)

Value

A tibble (data frame) whose first m columns contain either the data used to fit the model (if data was NULL), or the variables supplied to data. Four further columns are added:

  • fitted: the fitted values on the specified scale,

  • se: the standard error of the fitted values (always on the link scale),

  • lower, upper: the limits of the credible interval on the fitted values, on the specified scale.

Models fitted with certain families will include additional variables

  • mgcv::ocat() models: when scale = "repsonse", the returned object will contain a row column and a category column, which indicate to which row of the data each row of the returned object belongs. Additionally, there will be nrow(data) * n_categories rows in the returned object; each row is the predicted probability for a single category of the response.

Arguments

object

a fitted model. Currently only models fitted by mgcv::gam() and mgcv::bam() are supported.

...

arguments passed to mgcv::predict.gam(). Note that type, newdata, and se.fit are already used and passed on to mgcv::predict.gam().

data

optional data frame of covariate values for which fitted values are to be returned.

scale

character; what scale should the fitted values be returned on? "linear predictor" is a synonym for "link" if you prefer that terminology.

ci_level

numeric; a value between 0 and 1 indicating the coverage of the credible interval.

Examples

Run this code
load_mgcv()
# \dontshow{
op <- options(cli.unicode = FALSE, pillar.sigfig = 6)
# }
sim_df <- data_sim("eg1", n = 400, dist = "normal", scale = 2, seed = 2)
m <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = sim_df, method = "REML")
fv <- fitted_values(m)
fv
# \dontshow{
options(op)
# }

Run the code above in your browser using DataLab