Questions tagged [gam]

GAM (Generalized Additive Model) is a statistical model used to combine Generalized Linear Models with Additive Models.

GAM (Generalized Additive Model) is a statistical model used to combine Generalized Linear models with Additive Models. It is found in both the CRAN packages gam and mgcv for the R language.

683 questions
4
votes
0 answers

Random effects modeling using mgcv and using lmer. Basically identical fits but VERY different likelihoods and DF. Which to use for testing?

I am aware that there is a duality between random effects and smooth curve estimation. At this link, Simon Wood describes how to specify random effects using mgcv. Of particular note is the following passage: For example if g is a factor then…
4
votes
1 answer

How can I fit all variables using splines with gam in R without typing each one?

Lets say I have a data set with y and x1, x2, xp variables. I want to fit all of my predictors with splines. For example : gam_object = gam(y ~ s(x1) + s(x2) + s(xp), data) How can I do this without typing every single variable? If I would like to…
Jixxi
  • 111
  • 1
  • 11
4
votes
0 answers

extract automatically generated knots mgcv package r

Is there any way of identifying the number and position of the knots when using gam in the mgcv package in r? So I have something like this: fit.add <- gam( rep.pos ~ 0 + factor(AY) + s(dur), family=quasipoisson(link='log') ,…
4
votes
1 answer

Error: could not find function "Lag"

While running model0 found below I got an error message “ Error in eval(expr, envir, enclos) : could not find function "Lag" . Before posting this message I have scanned this forum and the web, but could not find relevant solution. I believe the…
Meso
  • 1,375
  • 5
  • 17
  • 36
3
votes
0 answers

Overlaying Basis Functions for GAM Plot Part II: Random Effects

I recently posted a question about overlaying basis function on a GAM plot. This was quite helpful for modeling fixed effects models. However, I want to do the same thing for GAMMs and I'm running into a bit of a road block. I've tried simulating…
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
3
votes
1 answer

r gamlss: prediction of z-scores using regression with multiple explanatory variables

The function centiles.pred is a great option to extract z-scores based on a gamlss model like in the following code: library(gamlss) FIT = gamlss(mpg ~ disp, data = mtcars, family = BCPE) NEWDATA = data.frame(disp = 300, mpg =…
ehi
  • 409
  • 8
  • 23
3
votes
2 answers

How to visualize GAM results with contour & tile plot (using ggplot2)

I would like to make a contour plot with ggplot2 by using gam results. Below is a detailed explanation of what I want: #packages library(mgcv) library(ggplot2) library(tidyr) #prepare data df <- data.frame(x = iris$Sepal.Width, y…
imtaiky
  • 191
  • 1
  • 12
3
votes
1 answer

Calculate annual rates from the gam model over time?

Question moved to CrossValidated I am trying to express the difference in the 'speed of increase' between two categories in gam modelling. My data represents the cumulative values over time [0-100%], but I wish (for comparability with other…
maycca
  • 3,848
  • 5
  • 36
  • 67
3
votes
1 answer

Gtsummary output with mgcv gam

I have the following data set: structure(list(Age = c(83L, 26L, 26L, 20L, 20L, 77L, 32L, 21L, 15L, 75L, 27L, 81L, 81L, 15L, 24L, 16L, 35L, 27L, 30L, 31L, 24L, 24L, 31L, 79L, 30L, 19L, 20L, 42L, 62L, 83L, 79L, 18L, 26L, 66L, 23L, 83L, 77L, 80L,…
CanyonView
  • 401
  • 3
  • 15
3
votes
1 answer

Adjusting p value with GAM in R?

I am interested in understanding how X predicts three different Y values across four different age groups, controlling for Sex. Some data for Y1: structure(list(Y = c(0.2801485, 0.281114, 0.2556435, 0.2670325, 0.2509095, 0.440258, 0.410253,…
CanyonView
  • 401
  • 3
  • 15
3
votes
1 answer

Creating an editable partial effect plot in R with the gratia::draw() function that also has a rugplot

The question I have has mostly been answered by the following post: Cannot update/edit ggplot2 object exported from a package (`gratia`) in R. When I refer to the mydraw.gam function, it comes from code in that post. What I am trying to do is use…
David Smith
  • 305
  • 1
  • 8
3
votes
1 answer

How to specify a hierarchical GAM (HGAM) model with two categorical & a continuous predictor using s(y1, by=y2:y3)) in mgcv?

Starting with dummy data for the question: zone <- c(rep("Z1",1000),rep("Z2",1000),rep("Z3",1000),rep("Z4",1000)) scenario <- rep(c(rep("S1",250),rep("S2",250),rep("S3",250),rep("S4",250)),4) model <-…
Thomas Moore
  • 192
  • 1
  • 12
3
votes
3 answers

mgcv GAM: more than one variable in `by` argument (smooth varying by more than 1 factor)

I need to model a smooth term over more than one factor. The by argument allows me to model one smooth per factor level, but I cannot find how to do that over multiple factors. I tried solutions akin to the following, but with no success: data <-…
Dominique Makowski
  • 1,511
  • 1
  • 13
  • 30
3
votes
0 answers

R gam model cooks.distance and influence.gam

I would start by saying immediately my background in statistics is extremely basic (even though I'm working on it) and for some work-related reason I have to handle quite big gam models that have both smoothed factors as well as categorical factors.…
Angelo
  • 1,594
  • 5
  • 17
  • 50
3
votes
0 answers

Can I have a "coefficient" like interpretation of my y-axis in a mgcv::gam.plot()?

I had already read some interesting alternatives to interpret the plot(mymodel) function from a gam fit like in this answer. # I included just a sample of the data used to plot, as the whole data set would be too big to include. dd <-…