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

Error when predicting new fitted values from R gamlss object

I have a gamlss model that I'd like to use to make new y predictions (and confidence intervals) from in order to visualize how well the model fits the real data. I'd like to make predictions from a new data set of randomized predictor values…
BonnieM
  • 191
  • 1
  • 13
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…
7
votes
2 answers

How can I set a minimum value for basis dimension in mgcv?

Using a penalized spline of mgcv, I want to obtain effective degrees of freedom (EDF) of 10 /year in the example data (60 for the entire period). library(mgcv) library(dlnm) df <- chicagoNMMAPS df1<-subset(df, as.Date(date) >= '1995-01-01')…
Meso
  • 1,375
  • 5
  • 17
  • 36
7
votes
1 answer

error with train from caret package using method gam:

I have a gam model that I know works just fine in R, but when I try to "train" the same model using the caret package it returns an error saying that the input data columns are lists. Does anyone understand this? The code that I am running is as…
user3004015
  • 617
  • 1
  • 7
  • 14
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
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
3 answers

predict values from GAM for grouped dataframe in R

I have a dataset of mean annual temperature values at different latitudes in different years. I want to use this to predict the latitude at which a given temperature could be found in a given year; i.e., "in 1980, at what latitude would the mean…
AFH
  • 665
  • 1
  • 9
  • 28
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
1 answer

Adding Independent Variables to Prophet Package

There is an R package called prophet which is very good. It is a generalized additive model. The dependent variable is the the metric you are trying to solve and the independent variables are: the growth function, seasonality function, and a…
nak5120
  • 4,089
  • 4
  • 35
  • 94
6
votes
1 answer

Error in 1:object$nsdf : argument of length 0 when using plot.gam

I am seeing the error message when trying to plot a gam object in R: Error in 1:object$nsdf : argument of length 0 I am using the basic command: plot(myGamObject) This error is not specific to any data I am using as it also comes up at the end of…
julianhatwell
  • 1,074
  • 1
  • 8
  • 17
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
1
2
3
45 46