calculate_vcs {stgam} | R Documentation |
Extracts varying coefficient estimates (for SVC, TVC and STVC models).
Description
Extracts varying coefficient estimates (for SVC, TVC and STVC models).
Usage
calculate_vcs(input_data, mgcv_model, terms = NULL)
Arguments
input_data |
the data used to create the GAM model in |
mgcv_model |
a GAM model with smooths created using the |
terms |
a vector of names starting with "Intercept" plus the names of the covariates used in the GAM model (these are the names of the variables in the |
Value
A data.frame
of the input data and the coefficient and standard error estimates for each covariate. It can be used to generate coefficient estimates for specific time slices and over grided surfaces as described in the package vignette.
Examples
require(dplyr)
require(doParallel)
# define input data
data("hp_data")
input_data <-
hp_data |>
# create Intercept as an addressable term
mutate(Intercept = 1)
# create a model for example as result of running `evaluate_models`
gam.m = gam(priceper ~ Intercept - 1 + s(X, Y, by = Intercept) +
s(X, Y, by = pef) + s(X, Y, by = beds), data = input_data)
# calculate the Varying Coefficients
terms = c("Intercept", "pef", "beds")
vcs = calculate_vcs(input_data, gam.m, terms)
vcs |> select(priceper, X, Y, starts_with(c("b_", "se_")), yhat)
[Package stgam version 1.0.2 Index]