510 questions
0
votes
0
answers
137
views
Trouble fitting `glmer()` and `gamm4()` models on uncomplicated data set - Is it a computer speed or complexity issue?
I am having issues with computing a GLMM in R using the lme4 package. The issue is that it is attempting to build the model but the loading stays in a suspended state (The stop sign button just ...
0
votes
0
answers
54
views
Using GAM for the first time on species detection data
I am running a GAM on species detection data for the first time. I would like to see if there is any interaction between time of year and diel period for both male and female of this species. This is ...
0
votes
1
answer
560
views
How to get the names of factor levels corresponding to fixed effect regression coefficients for a GAM in R?
I have a gam in R (mgcv package) with 7 parameters, and one of them is a fixed effect with 30 levels (30 names). I want to analyse the regression coefficients for each name (person), but R numbers ...
3
votes
1
answer
1k
views
Hazard Ratio Plot from mgcv::gam cox.ph model
I am navigating through different packages that let fit non-linear predictors in the context of COX PH models.
However, I was looking to produce plots to represent the non-linear relationship between ...
0
votes
1
answer
159
views
Error when running a fixed effect in a GAM with an offset in R with gratia::draw()
I have a data set that looks like this:
structure(list(n = c(236896L, 73258L, 75570L, 5684L, 10242L,
2037L, 74194L, 41764L, 288115L, 6728L, 18964L, 5395L, 23192L,
12575L, 39591L, 12566L, 44458L, ...
0
votes
1
answer
196
views
Mathematical equation of binomial probit gam (mgcv) with tensor product interactions?
I have the following binomial (probit) gam using mgcv, which includes y (0 or 1), two continuous predictors (xa, xb) plus the ‘ti’ interactions of a third covariate (xc) with these two predictors.
...
2
votes
1
answer
715
views
How to access and reuse the smooths in the `mgcv` package in `R`?
I am checking out the mgcv package in R and I would like to know
how to update a model based on new data. For example, suppose I have the
following data and I am interested in fitting a cubic ...
0
votes
1
answer
85
views
R: mgcv function bam: use multiple kernels from jupyter notebook
I use R in a jupyter notebook as described in this article. It work's perfectly fine. However, when I fit a GAM using the mgcv library and bam, e.g.:
dat <- gamSim(1,n=25000,dist="normal",...
0
votes
0
answers
278
views
Is there a way to make 1,2 and 3 step ahead predictions with a gam model in R using the mgcv package?
I've got a quick question regarding using the gam function and the predict.gam function in R using the mgcv package. I've got a model built with two predictors and one response. However when I try to ...
1
vote
1
answer
616
views
plot.gam and draw.gam produce different smooths for same GAMM object when using factor smooths
I've been experimenting with plotting different GAMMs using the plot.gam function from the mgcv package and draw.gam function from the gratia package. When plotting a GAMM with a beta distribution (...
3
votes
1
answer
422
views
Gtsummary output with mgcv gam
I have the following data set:
structure(list(Age = c(83L, 26L, 26L, 20L, 20L, 77L, 32L, 21L,
15L, 75L, 27L, 81L, 81L, 15L, 24L, 16L, 35L, 27L, 30L, 31L, 24L,
24L, 31L, 79L, 30L, 19L, 20L, 42L, 62L, ...
5
votes
2
answers
2k
views
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 ...
2
votes
2
answers
2k
views
GAM smooths interaction differences - calculate p value using mgcv and gratia 0.6
I am using the useful gratia package by Gavin Simpson to extract the difference in two smooths for two different levels of a factor variable. The smooths are generated by the wonderful mgcv package. ...
0
votes
1
answer
727
views
mgcv::gam, Error in names(dat) <- object$term : attribut 'names' [2] as to be same length as vector [1]
I want to run a hieratchical GAM in the mgcv package using the gam function. I used the same form of model in brms without problem and I will eventually re-run the same model in brms, but the deadline ...
2
votes
1
answer
2k
views
Three Way Interaction in mgcv
I am interested in implementing a three-way interaction in mgcv but while there has been some discussion both here and on Cross Validated, I have had trouble finding an answer to how exactly one ...
0
votes
0
answers
591
views
AIC() for mgcv model
I am creating a series of logistic regression models using mgcv and comparing them with AIC(). I have only four variables (socioeconomic class (Socio), sex, year of death (YOD), and age) for each ...
3
votes
0
answers
324
views
Multithreading/parallelization for MGCV summary function
I am fitting a gam using the MGCV package in R with the bam function (~60,000 samples) using 3 fixed effects and one random effect. The number of factors for the random effect is very high (several ...
1
vote
0
answers
514
views
Species-by-year random effects in a GLMM (point count data)
SUMMARY
I'm analyzing avian point count data using glmmTMB.
I'm trying to estimate year-specific mean abundance for each species.
Models with interactions of fixed terms are not working, I think ...
2
votes
0
answers
931
views
Why are the results of the gamm4 function of the gamm4 package different from the standard error displayed by $mer and $gam?
id:268levels
group:10levels
I used the gamm4 function of the package gamm4 to fit the following model.
gamm4_1 <- gamm4(y~z1+z2+z3+age+height+time+bmi,random=~(1|id)+(1|group),data=data,family=...
0
votes
0
answers
364
views
mgcv::k.check equivalent for GAM in brms
I am doing HGAM with the brm function (brms package). For now, I kept the default k = 10, but I want to know if I should set k higher. I know that the function k.check in the mgcv package does that ...
0
votes
1
answer
125
views
I don't know how to read the output when using ranef against the output of gamm in the mgcv package
id:268 levels
group:10 levels
Fitted a mixed-effects model using gamm in the mgcv package. Fitted a generalized additive model for age and bmi, but could not read the output of the random effect using ...
2
votes
1
answer
549
views
How to correct false convergence mgcv::gamm after updating R
I am getting a false convergence on a GAMM using mgcv::gamm when I try to fit models with corARMA functions for correlated error structures. The response data are amounts of precipitation, and are ...
1
vote
1
answer
344
views
Time (hours) formatting when plotting GAM smooth effects with mgcViz
I have a GAM model where time of day is one of the predictor values. Time is in numeric format, since as far as I understand, mgcv::gam doesn't accept POSIXct class. The model works fine, but I'd like ...
1
vote
1
answer
214
views
What is the default link function for the multinom family in mgcv?
I've looked for this information but haven't been able to find it. I assume it's a logit link but I'm not sure.
1
vote
0
answers
67
views
Conflicts with 'mgcv:gam' and another package?
I'm fitting some GAMMs using the 'mgcv' R package. However, when I attempt to include random smooths, I get an error about recursive vs. atomic vectors:
Error: $ operator is invalid for atomic vectors
...
2
votes
0
answers
202
views
Add specific penalty to the log-likelihood in MGCV::gam
In Tutz and Schmid (2016), example 9.4 (Breast Cancer) they compare several survival models. Among them, is a "fixed effects" model for heterogeneous hazards, where the FEs are constrained ...
3
votes
1
answer
594
views
Creating an editable partial effect plot in R with the gratia::draw() function that also has a rugplot
The question I have has mostly been answered by the following post: Cannot update/edit ggplot2 object exported from a package (`gratia`) in R. When I refer to the mydraw.gam function, it comes from ...
2
votes
3
answers
1k
views
R:mgcv add colorbar to 2D heatmap of GAM
I'm fitting a gam with mgcv and plot the result with the default plot.gam() function. My model includes a 2D-smoother and I want to plot the result as a heatmap. Is there any way to add a colorbar for ...
1
vote
1
answer
2k
views
mgcv GAM plot and predict with tensor smooth by factor
I am running GAMs to understand the spatio-temporal trends in size counts of a Californian mollusc. I have count data as a response to three-way interactions between space & time (lat,long,year) ...
2
votes
1
answer
727
views
Extract values used to make plot for parametric component of GAM in R
I have performed a GAM that includes both continuous smooth terms and a categorical variable. I have plotted the model (mod) using plot(mod,residuals=T,all.terms=T,pages=1). This produces plots of the ...
2
votes
0
answers
74
views
Pairing different gam smoothing regression (mgcv) to ggally [R]
I struggled with this code to pair different gam' smoothing regression (bs="cs" and bs="tp") using GGally:
sel1<-select(rekap,c('Total_Ni', 'Total_Mg', 'Total_Fe', 'CEC', 'pH','...
0
votes
1
answer
502
views
Trouble in GAM model in R software
I am trying to run the following code on R:
m <- gam(Flp_pop ~ s(Flp_CO, bs = "cr", k = 30), data = data, family = poisson, method = "REML")
My dataset is like this:
But when I ...
1
vote
0
answers
377
views
Progress bar when fitting a big additive model
When running a big additive model in R, is there a way to incorporate a progress bar (or similar) that tells me how much time is remaining? Some of my bam's run for many hours, and so it would be nice ...
0
votes
0
answers
108
views
Add additional regressor for phi and change link function for phi in GAM beta regression
I would like to use GAM to run penalized beta regression. Because of my setting, I also need to change the regression of precision, phi.
Here is my test code:
y <- c(0.0000943615,0.0074918919,0....
2
votes
0
answers
552
views
How is estimated degree of freedom in GAM determined?
I was working on my GAM model:
y <- c(0.0000943615,0.0074918919,0.0157332851,0.0783308615,
0.1546375803,0.5558444681,0.8583806898,0.9617216854,
0.9848004112,0.9964662546)
x <- log(...
0
votes
1
answer
466
views
Reproducibility of predictions from GAM (mgcv package) [closed]
I am using a generalized additive model built using the bam() function in the mgcv R package, to predict probabilities for a binary response.
I seem to get slightly different predictions for the same ...
2
votes
1
answer
2k
views
Binomial model with GAM (mgcv) using weights
I have been having an issue when trying to fit a binomial GAM to data. There are two ways these models can be coded, (i) providing a proportion as the response variable, and the number of trials as ...
2
votes
2
answers
2k
views
Log transformed data in GAM, how to plot response?
I used log-transformed data (dependent varibale=count) in my generalised additive model (using mgcv) and tried to plot the response by using "trans=plogis" as for logistic GAMs but the ...
0
votes
2
answers
294
views
How to paste string around predictor variables to create list of model combinations in R?
I have a vector of twelve predictor variables that I want all possible combinations for:
#variable vector
d_pred <- c("A", "B", "C", "D", "E", &...
3
votes
1
answer
1k
views
How to specify a hierarchical GAM (HGAM) model with two categorical & a continuous predictor using s(y1, by=y2:y3)) in mgcv?
Starting with dummy data for the question:
zone <- c(rep("Z1",1000),rep("Z2",1000),rep("Z3",1000),rep("Z4",1000))
scenario <- rep(c(rep("S1",250)...
6
votes
1
answer
784
views
Running random error model with mgcv gam takes too much memory
I am working on a model that includes several REs and a spline for one of the variables, so I am trying to use gam(). However, I reach memory exhaust limit error (even when I run it on a cluster with ...
1
vote
1
answer
354
views
Why do I have negative degrees of freedom in top model using MuMIn Dredge?
I have been using the dredge function in the MuMIn package to conduct model averaging on my global GAM model (using bam from the mgcv package), with a priori selected explanatory variables and two ...
0
votes
1
answer
1k
views
mgcv: gam.check() low p-value but not enough variable combinations to increase basis functions k
I have a similar issue described here but with the difference that I cannot increase the k-value without getting the error:
Error in smooth.construct.tp.smooth.spec(object, dk$data, dk$knots) :
A ...
4
votes
3
answers
5k
views
mgcv GAM: more than one variable in `by` argument (smooth varying by more than 1 factor)
I need to model a smooth term over more than one factor. The by argument allows me to model one smooth per factor level, but I cannot find how to do that over multiple factors.
I tried solutions akin ...
1
vote
0
answers
147
views
Error running betar distriubtion in GAM mgcv
I'm trying to run a gam using the mgcv package with a response variable which is proportional data. The data is overdispered so initially I used a quasibinomial distribution. However because I'm using ...
0
votes
0
answers
426
views
Convert probabilities from logistic regression to classes
I've fit a multinomial logistic regression using gam() and the mgcv package in R. I then used this model to make predictions on new data. The resulting predictions are probabilities because gam() ...
1
vote
1
answer
873
views
Troubles predicting fixed effects from a hierarchical GAM in mgcv
I have been fitting different hierarchical GAMs (hereafter: HGAM) using mgcv in R. I can extract and plot their predictions for their random effects without problems. Conversely, extracting and ...
0
votes
0
answers
783
views
GAMs (mgcv) binomial vs negative binomial vs zero inflated poisson
I am modeling coastal dolphin distribution with GAMs (package mgcv) and because most "events" modelled result in no sightings- the model has many zeros.
The zero-inflated poisson model ...
0
votes
0
answers
473
views
gam.check mgcv: low p values in basis check results
I have an issue similar to the one mentioned here. I'm getting low p-values in my gam check following running my model.
mGS_nb2 <- bam(gs ~ SE_score + s(ri) + TL + species + sex + season + year +
...
2
votes
1
answer
830
views
Error message using GAM in mgcv: Error in smooth.construct.tp.smooth.spec
I'm running a gamm using bam in mgcv. My response variable is between 0-1 and includes both numbers. For this I felt the betar distribution would be best. However I get an error when trying to run it.
...