Description Usage Arguments Details See Also Examples
This function converts a fitted GAM model into a tidy data frame
1 |
model |
A fitted GAM(M). |
pred |
Predictor name for which to calculate the odds ratio. |
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()
.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.