gam_to_df: Converts a fitted GAM model into a tidy data frame

View source: R/helper_funs.R

gam_to_dfR Documentation

Converts a fitted GAM model into a tidy data frame

Description

This function converts a fitted GAM model into a tidy data frame

Usage

gam_to_df(model = NULL, pred = NULL)

Arguments

model

A fitted GAM(M).

pred

Predictor name for which to calculate the odds ratio.

Details

To be able to plot the smoothing function of a GAM using ggplot2, some preprocessing is needed coming from the raw fitted GAM model output.

Used in plot_gam().

See Also

plot_gam()

Examples

# load data (Source: ?mgcv::gam)
library(mgcv)
n <- 200
sig <- 2
dat <- gamSim(1, n = n, scale = sig, verbose = FALSE)
dat$x4 <- as.factor(c(
  rep("A", 50), rep("B", 50), rep("C", 50),
  rep("D", 50)
))
fit_gam <- gam(y ~ s(x0) + s(I(x1^2)) + s(x2) +
  offset(x3) + x4, data = dat) # fit model

tmp <- gam_to_df(fit_gam, "x2")

pat-s/oddsratio documentation built on June 6, 2023, 7:50 a.m.