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
8
votes
2 answers

How to get only the plots from gam.check

When applying gam.check in the mgcv package, R produces some residual plots and basis dimension output. Is there a way to only produce the plots and not the printed output? library(mgcv) set.seed(0) dat <- gamSim(1,n=200) b <-…
phg
  • 536
  • 1
  • 7
  • 19
7
votes
1 answer

Why does it not cause a warning that gamm4 uses internal function from mgcv?

I am puzzled by a fact that I noticed when reading the source code of the gamm4 package. In two places, it imports internal functions from mgcv. One place is in the gamm4.setup function (link to code here) G <- mgcv:::gam.setup(formula,pterms, …
Øystein S
  • 536
  • 2
  • 11
7
votes
2 answers

GAMs in R: Fewer unique covariate combinations than df

I tried fitting gams to some dataframes I have. All minus one work. It fails with the error: Error in smooth.construct.tp.smooth.spec(object, dk$data, dk$knots) : A term has fewer unique covariate combinations than specified maximum degrees of…
Lenn
  • 1,283
  • 7
  • 20
7
votes
2 answers

GAM with mrf smooth - errors (mismatch between nb/polys area names and data area names

I am trying to fit Polish local government election results in 2015 following the superb blog by @GavinSimpson. https://www.fromthebottomoftheheap.net/2017/10/19/first-steps-with-mrf-smooths/ I joined my xls data with the shp data using a 6 digit…
Jacek Kotowski
  • 620
  • 16
  • 49
7
votes
1 answer

How to specify the non-linear interaction of two factor variables in generalised additive models [R]

I have a time-series data set that contains an outcome variable which is continuous and two factor predictors (one with 6 levels and one with 2 levels). I would like to model the non-linear interaction of the two factor variables on the continuous…
Stefano
  • 1,405
  • 11
  • 21
7
votes
1 answer

mgcv gam() error: model has more coefficients than data

I am using GAM (generalized additive models) for my dataset. This dataset has 32 observations, with 6 predictor variables and a response variable (namely power). I am using gam() function of the mgcv package to fit the models. Whenever, I try to…
Haroon Lone
  • 2,837
  • 5
  • 29
  • 65
7
votes
1 answer

R Package conflict between gam and mgcv?

Detaching packages in R isnt good practice (see ?detach), but for some reasons I have to switch between the packages gam and mgcv. Once mgcv was attached and detached (and all the dependencies in the namespace unloaded!), functions of gam produce…
6
votes
0 answers

Temporal autocorrelation in spatial bam (gam)

I am modelling fish depth in a river based on acoustic tag detections (meaning the data are not exactly a perfectly spaced continuous time series). I predict that depth will differ based on spatial location in the river because different areas have…
6
votes
1 answer

No access to "ldTweedie" function from mgcv when called from within another package

I am using mgcv package within my own package and so far everything worked nicely. However, I tried to introduce Tweedie family objects ("Tweedie()", "tw()") to my package, but I am getting an error when trying to use the latter. The function is as…
6
votes
0 answers

How to set boundary condition in a complex soap film GAM smoother?

I am modelling the distribution of bottlenose dolphins in the lagoon of a South Pacific Island. I would like to use a soap-film smoother to model the probability of dolphin presence over a 2D surface (longitude x latitude) accounting for land…
S.Derville
  • 208
  • 1
  • 2
  • 6
6
votes
0 answers

Adding splines to a multinomial logit model using mgcv

I am trying to train a multinomial logit model and while I am at it I might as well make it a GAM and add splines to the mix. I have tried using mgcv, but I have only managed to generate errors so far. Below are some examples using the iris…
Zoltan
  • 760
  • 4
  • 15
6
votes
1 answer

Autocorrelation in Generalized Additive Models (GAM)

I have a time series dataset for water temperature, air temperature, and flow rate in a river. I have created a GAM model to predict water temperature based on air temp and flow. However, I have not accounted for the autocorrelation in the datasets.…
Daniel
  • 63
  • 1
  • 4
6
votes
2 answers

How to add a random intercept and random slope term to a GAMM model in R

I am trying to specify both a random intercept and random slope term in a GAMM model with one fixed effect. I have successfully fitted a model with a random intercept using the below code within the mgcv library, but can now not determine what the…
jjulip
  • 1,093
  • 4
  • 16
  • 24
6
votes
0 answers

How do I interact a tensor product with two different `by=var` variables?

An example: library(mgcv) N=1000 x1 = seq(1:N) x2 = log(x1) x3 = sqrt(x1) fac1 = ceiling(rnorm(N)*3) fac2 = ceiling(runif(N)*3) y = fac1*x2 + x1*x2 + x2 + x3*x2 + x2*(x1/x3)^(.8+fac2/10) + rnorm(N)*x2 mod = gam(y~ …
generic_user
  • 3,430
  • 3
  • 32
  • 56
6
votes
1 answer

Determining derivatives from GAM smooth object

I have a quite simple time series data set consisting of annual averages of a singe variable ("AVERAGE"). I wish to investigate the rate of change (1st derivative) and acceleration (2nd derivative) and associated standard errors of the "trend"…
Phil W
  • 115
  • 1
  • 7
1
2
3
30 31