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

How to interpret Random Effects Plot from mgcv

I have a few questions regarding using a random effect in a GAM. First, how do you interpret and communicate the output graph? I have fire modeled as a random effect in this GAM because it is largely a random occurrence at my different field sites…
3
votes
0 answers

Difference between offset as argument and in formula

Using the offset as argument and in a formula should give the same output. As one can see here https://stackoverflow.com/a/29233096/426176. However, using glm.nb I get different results: mod1 <- glm.nb(y ~ x1 + x2 + offset(log(pop))) mod2 <-…
psoares
  • 4,733
  • 7
  • 41
  • 55
3
votes
1 answer

partial_dependence() got an unexpected keyword argument 'feature' for a python generalized additive model. How do I fix it?

I’m attempting to make a generalized additive model for some ocean data. My code is the following: from pygam import LinearGAM from pygam import LogisticGAM import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as…
April
  • 31
  • 2
3
votes
1 answer

Beta regression & spatial autocorrelation

I am trying to work out the best possible way to add random effects to my beta regression. I have a data frame consisting of longitude, latitude, seal tag, sea surface temp in kelvin and the mean behavioural position of the seal. I have rescaled…
Anna Firth
  • 31
  • 1
3
votes
0 answers

Calculating between and within variance (mean squares) in mgcv::gam

I would like to calculate the between and within variability of a parametric term (or mean squares of parametric term and residuals) in a mgcv::gam, but can't figure out how to do that with mgcv. Below is an example. I've created a gam object. Then…
huang
  • 31
  • 4
3
votes
1 answer

How to predict gam model with random effect in R?

I am working on predicting gam model with random effect to produce 3D surface plot by plot_ly. Here is my code; x <- runif(100) y <- runif(100) z <- x^2 + y + rnorm(100) r <- rep(1,times=100) # random effect r[51:100] <- 2 # replace 1 into 2, making…
imtaiky
  • 191
  • 1
  • 12
3
votes
0 answers

GAM with binomial distribution and with spatial autocorrelation in R

I am using gam (from mgcv package in R) to model presence/absence data in 3355 cells of 1x1km (151 presences and 3204 absences). Even though I include a smooth with the spatial locations in the model to address the spatial dependence in my data, the…
3
votes
1 answer

Changing predicted values to response scale after predict() function, not via type = "response"

Working in R. I'm having trouble with calculating my predicted values to the response scale when I have to exclude a random effect from the prediction. By excluding the random effect from the prediction, I need to specify type = "terms", hereby…
Peter
  • 343
  • 5
  • 17
3
votes
1 answer

How to check for overdispersion in a GAM with negative binomial distribution?

I fit a Generalized Additive Model in the Negative Binomial family using gam from the mgcv package. I have a data frame containing my dependent variable y, an independent variable x, a factor fac and a random variable ran. I fit the following…
3
votes
0 answers

Include full mgcv::gam() summary() with stargazer()

I am trying to create a table of my mgcv::gam() summary with the stargazer package. See code below. library(stargazer) library(mgcv) set.seed(2) ## simulate some data... dat <- gamSim(1,n=400,dist="normal",scale=2) b <-…
ecology
  • 606
  • 3
  • 9
  • 29
3
votes
1 answer

How to test the statistical significance of a random effect in GAMM?

I am now using the package mgcv to build a GAMM in R, and my questions are: First, how can we know if the random effect is statistically significant or not? Second, how can we extract the random intercept values in the model? Third, what does…
Yang Yang
  • 858
  • 3
  • 26
  • 49
3
votes
1 answer

Saving space when saving a fitted gam object (mgcv::gam and scam::scam)

I am estimating a very simple model on a large dataset. The formula looks like scam::scam(formula = ratio ~ s(rate,bs="mpi")) These models are then used to generate predictions for new data. I do not care about anything else about the model. My…
Zoltan
  • 760
  • 4
  • 15
3
votes
2 answers

Tensor product based Gaussian process smoother in mgcv

I'm trying to run a GAM model where the interaction between X and Y is modelled using a Gaussian process. The code below works fine when using the default smooth (s()) in mgcv, but I would like to model my data with a tensor product (te()) as I…
KaanKaant
  • 434
  • 3
  • 16
3
votes
1 answer

Non-standard evaluation with mgcv::gam

I am making a function which takes unevaluated calls to regression functions as input, creates some data, and then evaluates the call. Here is an example: library(lme4) compute_fit <- function(m){ # Generate some data df <- data.frame(x =…
Øystein S
  • 536
  • 2
  • 11
3
votes
1 answer

Get the name of iteration in purrr::map function

I am making graphs from 4 statistical models subsetting "virus" variable. I don't know how to put the title of the graphs according to "virus" variable. I made this reproducible…