Questions tagged [mgcv]

mgcv (Mixed GAM Computation Vehicle) is a CRAN package for the R language, it contains routines for GAMs and other generalized ridge regression with multiple smoothing parameter selection by GCV, REML or UBRE/AIC. Also GAMMs.

mgcv (Mixed GAM Computation Vehicle) is an package for analysing s and other generalized ridge models with multiple parameter selection by GCV, REML or UBRE/AIC. Also GAMMs.

Repositories

Books

Other resources

Related tags

461 questions
3
votes
1 answer

guarantee timeout with `mgcv::gam`

I'm fitting some GAMs with mgcv where I need a high k value to capture complicated behavior in some cases. But I've noticed that sometimes (some datasets), fitting the GAM takes forever when k is high, and it seems like in these cases, I also don't…
Michael Roswell
  • 1,300
  • 12
  • 31
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
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

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
0 answers

Multithreading/parallelization for MGCV summary function

I am fitting a gam using the MGCV package in R with the bam function (~60,000 samples) using 3 fixed effects and one random effect. The number of factors for the random effect is very high (several thousand). The model fits after ~4 hours. Until…
geedigit
  • 63
  • 3
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
1 answer

Combine gam smooths of multiple clusters in an mgcViz plot

I have gam smooths for several clusters coming from a model-based clustering code combining unequal length time series and I would like to display them along with the data. The mgcViz package provides excellent visualizations for individual clusters…
3
votes
1 answer

How to interpret Random Effects Plot from mgcv

I have a few questions regarding using a random effect in a GAM. First, how do you interpret and communicate the output graph? I have fire modeled as a random effect in this GAM because it is largely a random occurrence at my different field sites…
3
votes
0 answers

Calculating between and within variance (mean squares) in mgcv::gam

I would like to calculate the between and within variability of a parametric term (or mean squares of parametric term and residuals) in a mgcv::gam, but can't figure out how to do that with mgcv. Below is an example. I've created a gam object. Then…
huang
  • 31
  • 4
3
votes
0 answers

GAM with binomial distribution and with spatial autocorrelation in R

I am using gam (from mgcv package in R) to model presence/absence data in 3355 cells of 1x1km (151 presences and 3204 absences). Even though I include a smooth with the spatial locations in the model to address the spatial dependence in my data, the…
3
votes
1 answer

How can I load a library in R to call it from Excel with bert-toolkit?

Bert-toolkit is a very nice package to call R functions from Excel. See: https://bert-toolkit.com/ I have used bert-toolkit to call a fitted neuralnet (avNNnet fitted with Caret) within a wrapper function in R from Excel VBA. This runs perfect. This…
user2165379
  • 445
  • 4
  • 20
3
votes
1 answer

How to check for overdispersion in a GAM with negative binomial distribution?

I fit a Generalized Additive Model in the Negative Binomial family using gam from the mgcv package. I have a data frame containing my dependent variable y, an independent variable x, a factor fac and a random variable ran. I fit the following…