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
6
votes
1 answer

Extract estimates of GAM

I am fairly new to R and presently reading a book “Generalized Additive Models”, an Introduction with R by Wood (2006) and going through some of the exercises, particularly the part on air pollution and death which is my area of interest. Using the…
Meso
  • 1,375
  • 5
  • 17
  • 36
5
votes
1 answer

Find spline knots by variable in python

When fitting a linear GAM model in python imposing n_splines=5, a piecewise-linear function is fitted: import statsmodels.api as sm from pygam import LinearGAM data = sm.datasets.get_rdataset('mtcars').data Y = data['mpg'] X =…
PeCaDe
  • 277
  • 1
  • 8
  • 33
5
votes
1 answer

Can't get arcsin back-transformation with emmeans to work

I am doing a GAM with my response variable as a percentage (0-100). I have used an arcsin transformation to improve model fit (asin(sqrt(myvariable/100))). I now want to evaluate contrasts between levels of my explanatory factor variable on the…
evelyn
  • 63
  • 5
5
votes
0 answers

Concurvity in parametric terms in GAM in R with mgcv

I have a GAM model (below) where SST_mean and NAO are numerical values, and cycle and region are categorical factors. I checked for concurvity using the concurvity function in mgcv. m2 <- gam(Strandings ~ s(SST_mean) + s(NAO, bs="re") + Cycle +…
mikejwilliamson
  • 405
  • 1
  • 7
  • 17
5
votes
1 answer

Selecting coefficents to plot as dot-and-whiskers

I would like to plot the results of a GAM as dot-and-whisker plots using the dwplot() command in the dotwhisker R package. The example in the package documentation is as follows: #Package preload library(dotwhisker) library(broom) library(dplyr) #…
5
votes
0 answers

mgcv: Specifying factor-smoother interactions for "global" grouped smooths

I've found the Hierarchical GAM pre-print (and GH repo) of Pedersen et al. extremely helpful in modeling inter-group variability in functional responses, but I've hit a stumbling block. I have some time series data (counts over time) with the…
adamdsmith
  • 920
  • 1
  • 9
  • 15
5
votes
0 answers

Why does the fitting time of a gam increases with the number of threads used?

Common sense indicates that any computation should be faster the more cores or threads we use. If the scaling is bad, the computation time will not improve with increasing number of threads. Thus, how come increasing threads considerably reduces the…
nukimov
  • 216
  • 1
  • 7
5
votes
2 answers

Extract p-value from gam.check in R

When I run gam.check(my_spline_gam), I get the following output. Method: GCV Optimizer: magic Smoothing parameter selection converged after 9 iterations. The RMS GCV score gradiant at convergence was 4.785628e-06 . The Hessian was positive…
a_geo
  • 157
  • 1
  • 1
  • 6
5
votes
1 answer

GAMLSS Error: Response Variable out of range

I cannot fathom why I am receiving this error. Both my variables are numeric and of the same length, and I adjust the data with NAs when they are not; however I am still receiving an error that my response variable is out of range year <-…
Jessica Ayers
  • 61
  • 1
  • 5
5
votes
1 answer

GAM with "gp" smoother: predict at new locations

I am using the following geoadditive model library(gamair) library(mgcv) data(mack) mack$log.net.area <- log(mack$net.area) gm2 <- gam(egg.count ~ s(lon,lat,bs="gp",k=100,m=c(2,10,1)) + s(I(b.depth^.5)) + …
user3036416
  • 1,205
  • 2
  • 15
  • 28
5
votes
0 answers

Is it possible to specify lower bound in response variable during smooth with gam?

I am trying to fit a smoothed surface of z against x and y using formula z ~ s(x, y) with gam function in mgcv package. My goal is to predict response z based on new values of x and y. In my real situation, z should be a positive number negative z…
mt1022
  • 16,834
  • 5
  • 48
  • 71
5
votes
2 answers

How to predict test data using a GAM with MRF smooth and neighborhood structure?

I am having a problem using the predict() function for a mgcv::gam (training) model on a new (testing) dataset. The problem arises due to a mrf smooth I have integrated to account for the spatial nature of my data. I use the following call to…
5
votes
1 answer

Prevent plot.gam from producing a figure

Say, I have a GAM that looks like this: # Load library library(mgcv) # Load data data(mtcars) # Model for mpg mpg.gam <- gam(mpg ~ s(hp) + s(wt), data = mtcars) Now, I'd like to plot the GAM using ggplot2. So, I use plot.gam to produce all the…
Dan
  • 11,370
  • 4
  • 43
  • 68
5
votes
1 answer

mgcv: how to specify interaction between smooth and factor?

In R, I would like to fit a gam model with categorical variables. I thought I could do it like with (cat is the categorical variable). lm(data = df, formula = y ~ x1*cat + x2 + x3); But I can't do things like : gam(data = df, formula = y ~…
Courvoisier
  • 904
  • 12
  • 26
5
votes
2 answers

R plot.gam Error "Error in 1:object$nsdf : argument of length 0"

I am trying to plot a gam object in R, which I made with the gam package. I receive the same error reported in Error in 1:object$nsdf : argument of length 0 when using plot.gam. However, the solution found there, updating to the latest versions (I…
BazookaDave
  • 1,192
  • 9
  • 16
1 2
3
45 46