fitted_values {gratia} | R Documentation |
Generate fitted values from a estimated GAM
Description
Generate fitted values from a estimated GAM
Usage
fitted_values(object, ...)
## S3 method for class 'gam'
fitted_values(
object,
data = NULL,
scale = c("response", "link", "linear predictor"),
ci_level = 0.95,
...
)
## S3 method for class 'gamm'
fitted_values(object, ...)
## S3 method for class 'scam'
fitted_values(object, ...)
Arguments
object |
a fitted model. Currently only models fitted by |
... |
arguments passed to |
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?
|
ci_level |
numeric; a value between 0 and 1 indicating the coverage of the credible interval. |
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: whenscale = "repsonse"
, the returned object will contain arow
column and acategory
column, which indicate to which row of thedata
each row of the returned object belongs. Additionally, there will benrow(data) * n_categories
rows in the returned object; each row is the predicted probability for a single category of the response.
Note
For most families, regardless of the scale on which the fitted values
are returned, the se
component of the returned object is on the link
(linear predictor) scale, not the response scale. An exception is the
mgcv::ocat()
family, for which the se
is on the response scale if
scale = "response"
.
Examples
load_mgcv()
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