510 questions
-1
votes
0
answers
52
views
Accounting for temporal autocorrelation with irregular time lags with GAM model in R [closed]
I am running a GAM model with bam in the mgcv package in R.
The dataset in the model is calculated from mean hourly speeds for individual fish from position data (x,y, datetime).
AR_hourly <- ...
1
vote
0
answers
54
views
Gratia derivatives of a factor smooth
I fit a hierarchical generalized additive model with a sum to zero smooth interactions (bs="sz"). I would like to take the first derivative and plot the simultaneous confidence interval in ...
3
votes
1
answer
131
views
How can I set "cr" as the default basis type in mgcv::gam instead of "tp"?
I'm using the mgcv package in R to build generalized additive models (GAMs), and I often use cubic regression splines (cr) instead of the default thin plate regression splines (tp) (mainly because cr ...
2
votes
1
answer
67
views
Y-axis of mgcv::gam cox.ph model: rate or ratio?
I am plotting a nonlinear generalized additive model (gam) using R's mgcv package:
library(mgcv)
V <- rep(1, nrow(dt)
fit <- gam(cbind(V, group_number) ~ s(time_elapsed, exposure_group, bs='fs'...
1
vote
0
answers
95
views
Nonsensical fits from mgcv using `gam()` or `bam()`
I am getting nonsensical fits from both mgcv::gam() and mgcv::bam() whenever I use ML, REML, or fREML, despite clear trends in the test data. I believe the issues started after I installed openBLAS ...
2
votes
1
answer
137
views
How to correctly specify lower and upper bounds in mgcv mono.con function
In the documentation for mgcv::pcls(), an example of constructing a monotonically increasing gam model is provided with the following code:
set.seed(1234) # added for reproducibility in this post only
...
4
votes
2
answers
137
views
Posterior predictive check for GAM (mgcv in R)
I am fitting GAMs in R using the mgcv R package. I then want to perform posterior predictive checks to compare observed and simulated outcomes. A toy example using the performance R package:
library(...
0
votes
0
answers
146
views
Calculation of robust standard errors with gam model
I would like to run a generalised additive model (GAM) regression with some clustered survey data, where I fit a spline for one of the variables. I would like to estimate robust standard errors, ...
0
votes
0
answers
66
views
What's causing this error in mgcv::bam()? Error in `pqr2()`: ! BLAS/LAPACK routine 'DGEMM ' gave error code -3
I'm running a mixed model in mgcv::bam() and my most complex model is throwing the below error both on my PC (RStudio) & my work's high powered computing system running Linux. I think it's ...
1
vote
1
answer
32
views
gratia::draw(): "'length.out' must be a non-negative number"
I'm trying to plot a factor-smooth term bs='fs' from my model, but I keep getting this error from gratia::draw(mod):
Error in seq.default(from = lower, to = upper, length.out = n) :
'length.out' must ...
0
votes
0
answers
87
views
Verbose output for GAM Gaussian family via mgcv
I'm building a GAM via mgcv, which takes days to build. Is there any way to know how much of the model has been built just to get an indication of what is left?
Can I print all details during the run ...
0
votes
1
answer
146
views
How to exclude random effects (smooths) when visualizing GAMMs with the vis.gam function of the mgcv package?
As far as I know, mgscv's vis.gam does not feature an argument like exclude = c("s(id)", ...) to exclude a random effect s(id, bs = "re") of a GAMM from the prediction. Is there ...
1
vote
1
answer
94
views
mgcv::gam does not correctly decompose the linear component from the smooth
I am interested in testing the linear trend separately from the nonlinear component in a GAMM.
I have followed an example from the mgcv documentation and answers to relevant questions on stackexchange ...
0
votes
1
answer
63
views
Extremly high deviance explained but no significant predictors in mgcv()
I have a small (n=28) dataset of three seabird occurrence count data and have run a hurdel GAM model (using mgcv::gam()) with first using a binary model with presence/absecene, and then a negative ...
1
vote
1
answer
73
views
Very odd plots from posterior simulation of factor by GAM model
I am running the model below (modGI_test):
modGI_test <- gam(Met1 ~ Antibiotics + s(Timepoint, k=7) +
s(Timepoint, by=Antibiotics, k=7, m=1) +
s(Timepoint, ID_new,...
1
vote
1
answer
189
views
GAM model with multidimensional categorical response variable (with mgcv) [closed]
I try to fit a GAM model with a multidimensional categorical response variable combining three binomial dimensions (e.g., A-B by a-b by α-β) lacking certain combinations and depending on a smooth of ...
0
votes
1
answer
217
views
gam fails with the error - "inner loop 3; can't correct step size"
I am using the mgcv package to train a gam model (family = betar(), method = 'REML' using 10 threads). I use the tp basis.
I split my dataset in multiple train-test splits - my main interest is ...
2
votes
0
answers
54
views
How to pass an explicit weights vector to a gam function in R
I'm working with the gam function from the mgcv package in R, and I have a custom function that uses a weights vector to fit the model. My issue is that when I pass a weights vector to the function as ...
1
vote
0
answers
122
views
Warning message: In bgam.fit(G, mf, chunk.size, gp, scale, gamma, method = method, : algorithm did not converge
I am fitting this model:
m <- bam(f,
data = d,
family = binomial(link = 'logit'),
select = TRUE,
method = 'REML')
where f is y ~ s(t) + s(x1) + s(x2) + s(x3) + ...
1
vote
2
answers
110
views
Ecology in R: Error in mgcv package "Error in eval(family$initialize) : values out of range"
I'm trying to fit a model in R which shows how depth and sediment type influence seagrass density (response) and collected a dataframe with about 5000 rows. For ease of data collection, we have ...
5
votes
1
answer
158
views
How to control (BLAS?) parallelization when using mgcv::gam
I am running some fairly large gam models and don't want to parallelize the computations, or at least want to be able to control the degree of parallelization. (Besides not wanting to fry my machine ...
2
votes
1
answer
74
views
Generate predictions for GAM (mgcv) using penalised cubic spline forced through a certain point
I am using MGCV to generate predictions for a GAM using a cubic spline forced through a certain point. I have generated the gam exactly as outlined in this post: https://stat.ethz.ch/pipermail/r-help/...
0
votes
1
answer
379
views
Prediction values don't match fitted function from GAM model
I have a presence/absence data for a species occurrence and I did a binomial GAM using sea surface temperature (sst) as a predictor variable.
My df object is a data.frame with the presence/absence ...
1
vote
0
answers
76
views
Run mgcv package in python via rpy2
I am trying to create a python package to run mgcv in R, to replace the functionality of pyGAM. I want to start with the r command gam(), and need to use rpy2 to transfer data from R. I don't know how ...
0
votes
0
answers
117
views
Missing category in reference level in multinomial GAM with mgcv in R
Consider the multinomial GAM with mgcv in R
library(mgcv)
multinom = gam(list(sound ~ word + s(long, lat),
~ word + s(long, lat),
~ word + s(long, ...
0
votes
0
answers
100
views
gam function output (mgcv package)
How can I improve my bam model if 3/4 gam.check plots show poor diagnosis, except for the histogram of residuals (which shows a normal distribution).
My response variable is soundscape saturation (...
0
votes
1
answer
388
views
Step failure (and iteration limit) in multinomial GAM with mgcv in R
I have a data set with 40 sites (long, lat) by 2 ages by 2 genders by 6 words and 6 dependent sound categories (coded 0 to 5) as simulated here:
sound <- sample(0:5, size=960, replace=T)
...
1
vote
0
answers
64
views
mgcv predict.gam in R version 4 gives error, in R version 3, no error
In R version 3.6.3, my predict.gam function gives a result. When I use R 4.x, I get errors for some types of predict, but not others:
library(gam)
library(dplyr)
gm1 <- predCol ~ s(VCF_nontree) + ...
1
vote
1
answer
190
views
How to Plot Difference Smooth with confidence Intervals using gamm4 in R
I am currently working on fitting splines with gamm4 and I have hierarchical data. In my dataset, Trial_no is nested within VP, and SoundType (levels: STA and DEV) is a level-1 predictor. My model ...
1
vote
1
answer
328
views
How can I enable openMP in Mac OS for mgcv R package?
I'm trying to run GAMMs in mgcv and hoping to utilise multi-threaded computation but openMP is not enabled on my Apple M2 Pro running Sonoma 14.1.1. I don't know a lot about the back-end of R, so ...
1
vote
1
answer
197
views
Plotting a QQplot from a logistic GAM fitted with mgcv and using weights
Here is a little script describing my problem.
I am fitting a logistic model in R using the mgcv package.
The dataset represent the occurrence of an event under certain conditions.
For this model, I ...
1
vote
2
answers
228
views
Using both foreach and bam from the mgcv package
I have several large GAM models to fit (lots of data, various distributions for residuals and random effect smooths). Currently, I use foreach with a cluster of processors based on the parallel ...
0
votes
0
answers
177
views
How to visualize GAM fit with a multiple imputed dataset?
I’m working with a dataset that has missing values, and I am using multiple imputation with the mice package in R. I then fit a Generalized Additive Model (GAM) using the mgcv package on the imputed ...
1
vote
1
answer
76
views
Cannot force legend to bottom in gratia::compare_smooths
I am using the wonderful gratia package to visualize multiple gam models from the mgcv package using the compare_smooths function. While I am able to create the gams properly and draw them, I cannot ...
2
votes
1
answer
298
views
How do I plot GAM model with log transformed response
I created a GAM model using mgcv. My response variable is log transformed. I would like to plot this model using gratia. However, I want to make sure the y-axis is exponentiated after I plot it using ...
1
vote
1
answer
147
views
Extract the effective degrees of freedom (EDF) from a Generalized Additive Model (GAM) applied to an imputed dataset
How do you extract the pooled estimated degrees of freedom (edf) from a pooled generalized additive model ?
library(mice) # For multiple imputation
library(mgcv) # For GAM models
library(broom) # ...
2
votes
2
answers
279
views
How to add points to the diagram of GAM results displayed with the plot_smooths() function?
I cannot add points to the diagram of GAM results displayed with the plot_smooths() function of tidymv package.
I would like to add points to the diagram of GAM results displayed with the plot_smooths(...
0
votes
1
answer
26
views
gam modeling: error in variable specification
I have created this regression model that works well :
model1 = bam(depend ~ s(indep, by = gender.x,bs = "tp") +
s(Age, by = gender.x, bs = "tp") + ti(Age, indep, by = gender....
3
votes
2
answers
220
views
Why does summary of bam model not work when using m=1 (generalised additive models)?
I'm trying to use bam() and method="fREML" to speed up my analyses.
require(mgcv)
require(gratia)
require(brms)
require(DHARMa)
require(marginaleffects)
mode11 <- bam(Met1 ~ s(Timepoint, ...
0
votes
0
answers
74
views
mgcv::gam mimicry of default geom_smooth gam when n is small
Am performing mgcv::gam over each unique XY pairing (2 in this instance) and both of these pairings have just 11 obs. Ideally, the prediction of A=0 should be somewhere between B = 2,000 and 1,000. ...
1
vote
1
answer
7k
views
"Error in Ops.data.frame(guide_loc, panel_loc) : ‘==’ only defined for equally-sized data frames" when using draw() from gratia to draw GAM in r
I am trying to draw GAMs in R using the below code. This code always used to work, and I could draw the partial effect of my smoothed term, but randomly it no longer works, consistently triggering ...
3
votes
2
answers
142
views
Updating a fitted R mgcv::bam model reports an "invalid type (closure)..." error
I am attempting to "bam.update" my fitted mgcv::bam model that uses the "weights" argument and getting the following error:
Error in model.frame.default(gp$fake.formula, data, ...
1
vote
2
answers
99
views
Is it possible to predict terms from a GAM with partial newdata?
Is it possible to get predictions from a GAM object for specific terms from 'partial' newdata, which only provides values for the terms to predict? Running predict.gam with type = 'terms' for specific ...
1
vote
1
answer
226
views
mgcv::gam predictions with observation-level / residual variance?
Is there a way to include residual variance in the predictions from predict.gam()?
For reference: I've used brms for similar purposes before, and it has two distinct functions, fitted() and predict(). ...
2
votes
1
answer
275
views
How to properly make predictions only on fixed effect factors using mixed GAM models in R?
I am trying to fit a GAM model using library(mgcv) for a data set containing five factors. Some factors are nested. There is an independent variable named x and a response variable named y. The goal ...
0
votes
1
answer
131
views
Shape Constrained Additive Model (Scam package) in Parsnip from Tidymodels
The Scam package allows to create Shape Constrained Additive Models and uses some routines from the mgcv package.
The Parsnip package from the Tidymodels framework allows to create the following types ...
1
vote
1
answer
103
views
How to predict and add values to original dataset
I have a large dataset that I need to predict some values for. I have this small
reproducible example below. I would like to predict for a few years ahead using
either gam or glm, however, I can't ...
0
votes
0
answers
256
views
Manually creating a rootogram to evaluate a GAM with a Tweedie distribution?
I have count data of a species which I am modelling using GAMs with negative binomial and Tweedie families.
I want to compare the models visually using rootograms.
This works fine for the negative ...
0
votes
0
answers
238
views
How can I ensure convergence of my BAM model with mgcv in R?
I am trying to fit a binomial GAM using the mgcv library in R. Because I have a high number of data points (~20,000), I am using the bam function. The structure of the model is as follows:
Model <- ...
1
vote
1
answer
62
views
Using update() function in conjunction with gamm4() in mgcv package
The update() function of R does not work with objects returned from the gamm4() function of the mgcv package.
Question: *Does anyone know of an equivalent way of updating gamm4 objects?
*
I have found ...