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

Variable Selection with mgcv

Is there a way of automating variable selection of a GAM in R, similar to step? I've read the documentation of step.gam and selection.gam, but I've yet to see a answer with code that works. Additionally, I've tried method= "REML" and select =…
IJH
  • 167
  • 1
  • 11
5
votes
2 answers

R: GAM with fit on subset of data

I fit a Generalized Additive Model using gam from the mgcv package. I have a data table containing my dependent variable Y, an independent variable X, other independent variables Oth and a two-level factor Fac. I would like to fit the following…
yannick
  • 397
  • 3
  • 19
4
votes
2 answers

Plotting smooth functions from my GAM in ggplot

I have created a GAM and set up the predictions but having trouble with how to plot any smooth functions from my model. Been trying to plot these in ggplot but having trouble with the arguments/aesthetics now I have added in a the month aswell,…
Joe
  • 795
  • 1
  • 11
4
votes
0 answers

R Is it possible to use Generalised Additive Models for Location Scale and Shape (GAMLSS) in a multilevel dataset and plot percentiles?

Im trying to plot continuous percentiles of a variable against another variable. Ive found the package gamlss which lets me do pretty much that. data(iris) (gamlss) (gamm4) r1<-gamlss(Sepal.Length~cs(Sepal.Width, 3), sigma.formula=~cs(Sepal.Width,…
Jajo123
  • 75
  • 4
4
votes
2 answers

How do you plot smooth components of different GAMs in same panel?

I have two GAMs which have the same predictor variables but different independent variables. I would like to combine the two GAMs to a set of plots where the smooth component (partial residuals) of each predictor variable are in the same panel…
tolonen
  • 67
  • 6
4
votes
1 answer

Combine two gamm outputs in same graph?

The axis and variables are the same, but the original data frame is different mod_a <- gamm(Response ~ s(variable1) + s(variable2) + s(variable3), data=df1) mod_b <- gamm(Response ~ s(variable1) + s(variable2) + s(variable3), data=df2) How do I…
4
votes
1 answer

Equivalent of span using geom_smooth() with "gam"

This is probably a very basic question but I haven't found an answer yet. Is there an equivalent to the span argument in the geom_smooth function when method = "gam"? I am not familiar with GAM's in general so I would appreciate any input on that. I…
b_surial
  • 512
  • 4
  • 14
4
votes
1 answer

Finding maximum on a 3D gam-smoothed surface

Given the following example: library(mgcv) set.seed(2) dat <- gamSim(2, n = 1000, dist = "normal", scale = 1) m <- gam(y ~ s(x, z, k = 40), data = dat$data, method = "REML") fit <- predict(m) vis.gam(m, se=T, type="response") Is there any way to…
Kenny Chen
  • 43
  • 4
4
votes
1 answer

mgcv GAM with betar

Does anyone know how to obtain the fitted phi parameter from the model output (mgcv GAM with a beta distribution)? Referring to the betar gam example provided: library(mgcv) ## Simulate some beta data... set.seed(3);n<-400 dat <- gamSim(1,n=n) mu <-…
lmyt
  • 71
  • 2
4
votes
1 answer

Namespace specifier on gam package does not work

I don't understand why the below two gam models produce different results. The only difference is in one of the models I added the namespace specifier gam:: before the functions gam and s. I want to do this because I am exploring the differences…
TimW
  • 65
  • 5
4
votes
1 answer

How to change the y-axis for a multivariate GAM model from smoothed to actual values?

I am using multivariate GAM models to learn more about fog trends in multiple regions. Fog is determined by visibility going below a certain threshold (< 400 meters). Our GAM model is used to determine the response of visibility to a range of…
Q.James
  • 41
  • 2
4
votes
1 answer

mgcv: How to use 'exclude' argument in predict.gam?

I have a model structured as follows, and I would like to extract the predicted values while ignoring the random effect. As specified in ?predict.gam and here, I am using the exclude argument, but I am getting an error. Where is my mistake? dt <-…
mluerig
  • 638
  • 10
  • 25
4
votes
1 answer

mgcv_1.8-24: "fREML" or "REML" method of bam() gives wrong explained deviance

Fitting the same model with bam using methods "fREML" and "REML" gave me close results, but the deviance explained is rather different as returned by summary.gam. With "fREML" the quantity is ~3.5% (not good) while with "REML" it is ~50% (not that…
Arnaud
  • 377
  • 1
  • 2
  • 11
4
votes
1 answer

Predict values from sinusoidal noise

Background Using R to predict the next values in a series. Problem The following code generates and plots a model for a curve with some uniform noise: slope = 0.55 offset = -0.5 amplitude = 0.22 frequency = 3 noise = 0.75 x <- seq( 0, 200 ) y <-…
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
4
votes
1 answer

GAM R variance explained by variable

My current problem is to calculate the variance explained by the different variables of a general additive model (GAM) with R. I followed the explanation given by Wood here : https://stat.ethz.ch/pipermail/r-help/2007-October/142743.html But I would…