I am fitting a gam using the MGCV package in R using the bam function:

gam_model = bam(y ~ s(time, k = -1) + 
                    s(ID, bs = 're'),
                  family = 'gaussian',
                  data = dat,
                  method = "fREML",
                  select = FALSE,
                  nthreads = 64,
                  discrete = TRUE,
                  control = ctrl)

The size of the dataset is 10,388 observations. The GAM fits quite quickly (483 seconds), however the summary.gam function takes significantly longer: ~18 minutes (measured using the tictoc package).

Might anyone know what could be causing this?

This is the R version information:

platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
major          3                           
minor          6.3                         
year           2020                        
month          02                          
day            29                          
svn rev        77875                       
language       R                           
version.string R version 3.6.3 (2020-02-29)
nickname       Holding the Windsock 

1 Answer 1


The test for random effects is extremely costly computation-wise, especially so if there are lots of levels in the random effect factor.


summary(gam_model, re.test = FALSE)

to exclude the test for the random effect term from the model summary.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.