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
52
votes
9 answers

installation path not writable R, unable to update packages

I am trying to install Bioconductor into R, using the code on their website. When I type in the code (see bellow) I get an error message saying that some packages can't be updated, the installation path is unwriteable. > ## try http:// if https://…
Eleanor Bellows
  • 541
  • 1
  • 4
  • 3
28
votes
5 answers

Error in model.frame.default: variable lengths differ

On running a gam model using the mgcv package, I encountered a strange error message which I am unable to understand: “Error in model.frame.default(formula = death ~ pm10 + Lag(resid1, 1) + : variable lengths differ (found for 'Lag(resid1,…
Meso
  • 1,375
  • 5
  • 17
  • 36
27
votes
4 answers

Is it possible to plot the smooth components of a gam fit with ggplot2?

I am fitting a model using gam from the mgcv package and store the result in model and so far I have been looking at the smooth components using plot(model). I have recently started using ggplot2 and like its output. So I am wondering, is it…
unique2
  • 2,162
  • 2
  • 18
  • 23
19
votes
1 answer

mgcv: How to set number and / or locations of knots for splines

I want to use function gam in mgcv packages: x <- seq(0,60, len =600) y <- seq(0,1, len=600) prova <- gam(y ~ s(x, bs='cr') can I set the number of knots in s()? and then can I know where are the knots that the spline used? Thanks!
memy
  • 229
  • 1
  • 2
  • 8
18
votes
1 answer

How to extract fitted splines from a GAM (`mgcv::gam`)

I am using GAM to model time trends in a logistic regression. Yet I would like to extract the the fitted spline from it to add it to another model, that cannot be fitted in GAM or GAMM. Thus I have 2 questions: How can I fit a smoother over time so…
Tom
  • 305
  • 2
  • 4
  • 15
17
votes
3 answers

Extracting data used to make a smooth plot in mgcv

This thread from a couple of years ago describes how to extract data used to plot the smooth components of a fitted gam model. It works, but only when there is one smooth variable. I've got more than one smooth variable, and unfortunately I can…
generic_user
  • 3,430
  • 3
  • 32
  • 56
13
votes
1 answer

Extract knots, basis, coefficients and predictions for P-splines in adaptive smooth

I'm using the mgcv package to fit some polynomial splines to some data via: x.gam <- gam(cts ~ s(time, bs = "ad"), data = x.dd, family = poisson(link = "log")) I'm trying to extract the functional form of the fit. x.gam is a gamObject,…
Lindon
  • 1,292
  • 1
  • 10
  • 21
11
votes
0 answers

GAM error: Fitting terminated with step failure - check results carefully

I’m writing a GAM using the mgcv package that predicts burrow abundance and distribution of two different species on an island using data obtained during a field trip and images taken from the Sentinel satellite. 101 plots were surveyed. 922 burrows…
Bong112
  • 161
  • 10
11
votes
1 answer

Caret package - cross-validating GAM with both smooth and linear predictors

I would like to cross validate a GAM model using caret. My GAM model has a binary outcome variable, an isotropic smooth of latitude and longitude coordinate pairs, and then linear predictors. Typical syntax when using mgcv is: gam1 <- gam( y ~ s(lat…
Paul Lantos
  • 113
  • 1
  • 6
10
votes
2 answers

Force GAM model fit to be monotonic and go through a fixed point (x0, y0) with R mgcv

I am trying to fit a GAM model to data under two constraints simultatenously: (1) the fit is monotonic (increasing), (2) the fit goes through a fixed point, say, (x0,y0). So far, I managed to have these two constraints work separately: For (1),…
Marta Karas
  • 4,967
  • 10
  • 47
  • 77
10
votes
1 answer

GAM model error

My data frame looks like: head(bush_status) distance status count 0 endemic 844 1 exotic 8 5 native 3 10 endemic 5 15 endemic 4 20 endemic 3 The count data is non-normally distributed. I'm…
Fbj9506
  • 231
  • 3
  • 11
9
votes
1 answer

How to use sample weights in GAM (mgcv) on survey data for Logit regression?

I'm interesting in performing a GAM regression on data from a national wide survey which presents sample weights. I read with interest this post. I selected my vars of interest generating a DF: nhanesAnalysis <- nhanesDemo %>% …
Borexino
  • 802
  • 8
  • 26
9
votes
1 answer

Why is bam from mgcv slow for some data?

I am fitting the same Generalized Additive Model on multiple data sets using the bam function from mgcv. While for most of my data sets the fit completes within a reasonable time between 10 and 20 minutes. For a few data sets the run take more than…
unique2
  • 2,162
  • 2
  • 18
  • 23
8
votes
1 answer

stat_smooth gam not the same as gam {mgcv}

I was using the stat_smooth function in ggplot2, decided I wanted the "goodness of fit", and used a mgcv GAM for that. It occurred to me that I should check to make sure that they were the same model (stat_smooth vs mgcv's gam), so I used the code…
CJ9
  • 91
  • 1
  • 6
8
votes
3 answers

Is it possible to include the product of two smooth terms in a mgcv gam model

I have had great success using gam to model seasonality for time series data. My latest model clearly shows a weekly pattern in addition to seasonal changes. While the weekly pattern itself is very stable over the year, its amplitude also varies…
unique2
  • 2,162
  • 2
  • 18
  • 23
1
2 3
30 31