Hot answers tagged

44 votes
Accepted

Adaptive GAM smooths in mgcv

Most of the extra smooths in the mgcv toolbox are really there for specialist applications — you can largely ignore them for general GAMs, especially univariate smooths (you don't need a random ...
Gavin Simpson's user avatar
24 votes
Accepted

ANOVA to compare models

The output from anova() is a series of likelihood ratio tests. The lines in the output are: The first line in the output corresponds to the simplest model with ...
Gavin Simpson's user avatar
21 votes

Smoothing methods for gam in mgcv package?

mgcv uses a thin plate spline basis as the default basis for it's smooth terms. To be honest it likely makes little difference in many applications which of these you choose, though in some situations ...
Gavin Simpson's user avatar
21 votes
Accepted

R/mgcv: Why do te() and ti() tensor products produce different surfaces?

These are superficially the same model but in practice when fitting there are some subtle differences. One important difference is that the model with ti() terms is ...
Gavin Simpson's user avatar
21 votes

Generalized additive models -- who does research on them besides Simon Wood?

There are many researchers on GAMs: it's just that basically the same model (GLM with linear predictor given by sum of smooth functions) is given lots of different names. You'll find models that you ...
Simon Wood's user avatar
20 votes
Accepted

Model selection for GAM in R

If you want to select from among a group of covariates, then a principled way of doing this is to put some additional shrinkage on each of the smoothers in the model so that they can be penalised out ...
Gavin Simpson's user avatar
19 votes
Accepted

Generalized additive models (GAMs), interactions, and covariates

Q1 What's the difference between models 3 and 4? Model 3 is a purely additive model $$y = \alpha + f_1(x) + f_2(w) + \varepsilon$$ so we have a constant $\alpha$ plus the smooth effect of $x$ plus ...
Gavin Simpson's user avatar
17 votes
Accepted

Two methods of adding random effects to a GAM give very different results. Why is this and which one should be used?

I suspect the difference is in terms of what fitted values you are getting. If you look at what I would call the model fit, the coefficient estimates, variance terms, the models are identical. Compare ...
Gavin Simpson's user avatar
16 votes
Accepted

Different ways of modelling interactions between continuous and categorical predictors in GAM

gam1 and gam2 are fine; they are different models, although they are trying to do the same thing, which is model group-specific ...
Gavin Simpson's user avatar
13 votes

How to choose the type of GAM-parameters

I'm assuming this is better explained in the 2nd edition of Simon's book (which should be out in a couple of days) as he and his students only worked out some of the theory for this years after Simon ...
Gavin Simpson's user avatar
13 votes
Accepted

Choosing k in mgcv's gam()

There is some confusion here and in the answer by @Ira S in that linked post. The default value of the argument k is ...
Gavin Simpson's user avatar
13 votes
Accepted

Correcting for multiple pairwise comparisons with GAM objects {mgcv} in R

The glht() function for generalized linear hypotheses from the multcomp package can be used to carry out various kinds of ...
Achim Zeileis's user avatar
12 votes
Accepted

Time series analysis via generalized additive models: model assumptions and stationarity

The idea here is that by estimating the trend as a smooth function, the residuals then are a stationary process and the ARMA model is being estimated in the residuals. In other words, the estimated ...
Gavin Simpson's user avatar
11 votes
Accepted

Predicting mean smooth in GAM with smooth-by-random-factor interaction

The solution suggested by Simon Wood to the simpler problem of predicting the population level effect from a model with random intercepts represented as a smooth is to use a ...
Gavin Simpson's user avatar
11 votes
Accepted

GAM factor smooth interaction--include main effect smooth?

You need to be careful with ordered factors here in mgcv as they aren't doing what I think you want to be fitting. If you pass an ordered factor to by, then ...
Gavin Simpson's user avatar
11 votes
Accepted

Random effects in Generalised Additive Model - mgcv package

The random effects in mgcv are proper random effects; there is a way to view random effects, penalized smooths, Gaussian processes, & Gaussian Markov Random Fields all as a Gaussian random field. ...
Gavin Simpson's user avatar
10 votes

Generalized Additive Model interpretation with ordered categorical family in R

In these models, the linear predictor is a latent variable, with estimated thresholds $t_i$ that mark the transitions between levels of the ordered categorical response. The plots you show in the ...
Gavin Simpson's user avatar
10 votes
Accepted

Why are generalized additive models (GAMs) so popular in ecology?

TL;DR: GAMs are useful models when specific functional relationships are not hypothesized. Ecology as a science (and like many other sciences, particularly population sciences) often has hypotheses ...
Alexis's user avatar
  • 29.2k
9 votes

GAM model selection

If you are using an extra penalty on each term, you can just fit the model and you are done (from the point of view of selection). The point of these penalties is allow for shrinkage of the perfectly ...
Gavin Simpson's user avatar
9 votes
Accepted

Gaussian Process smooths in mgcv: choosing between spherical and exponential covariance functions

The gp smooth type is only discussed in the second edition of Simon's book as it was added to the mgcv long after the first edition went to press. The main ...
Gavin Simpson's user avatar
9 votes

GAM with categorical variables - interpretation

In a factor by variable smooth, like other simple smooths, the bases for the smooths are subject to identifiability constraints. If you just naively computed the ...
Gavin Simpson's user avatar
9 votes
Accepted

Why is my design matrix rank deficient? (modelling seasonal data with a cyclic spline)

cyclicSpline already contains the constant vector in its span so if you additionally add an intercept it'll be rank deficient. ...
jld's user avatar
  • 19.9k
8 votes
Accepted

gam smoother vs parametric term (concurvity difference)

The concurvity moves from the stated smooth terms to the parametric terms, which concurvity groups in total under the para ...
Gavin Simpson's user avatar
8 votes
Accepted

Are GAM models linear in the parameters?

Yes, GAMs are linear in the parameters. If we ignore the estimation of smoothness parameters, once we have created the bases for all the covariates we want to fit a smooth effects of, a GAM is just ...
Gavin Simpson's user avatar
8 votes
Accepted

Plotting GAMs on Response Scale with Multiple Smooth and Linear Terms

If the model contains z then the effect of x estimated by the model is that given z is in ...
Gavin Simpson's user avatar
8 votes
Accepted

MGCV summary function extremely slow

The test for random effects is extremely costly computation-wise, especially so if there are lots of levels in the random effect factor. Use ...
Gavin Simpson's user avatar
7 votes

mgcv::gam overfitting

The problem is what you mean by 'smooth' here. If you really want a curve that is smooth w.r.t. time and passes through the spike in the data at time 1 then it will have to vary enormously on the y ...
Simon Wood's user avatar
7 votes
Accepted

Simulating Responses from fitted Generalized Additive Model

I'll illustrate with the classic 4 term data set oft used to illustrate GAMs, but will only simulate data from the strongly nonlinear term $f(x_2)$ as it is easy to visualise the process with a single ...
Gavin Simpson's user avatar
7 votes
Accepted

difference between summary.gam and gam.check p-values

The p values relate to two entirely different tests: in summary.gam the p values are of the null hypothesis of a zero effect of the indicated spline. There values ...
Gavin Simpson's user avatar
7 votes
Accepted

Inconsistent mgcv gam.check results

The issue is due to the basis dimension test used in gam.check() being based on permutations of model residuals. These permutations are computed using a pseudo ...
Gavin Simpson's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible