Skip to content

Help with GAM (mgcv)

7 messages · Stressed1985, Simon Wood

#
Please help! Im trying to run a GAM:

model3=gam(data2$Symptoms~as.factor(data2$txerad)+s(data2$maritalStatus),family=binomial,data=data2)

But keep getting this error: 
Error in dl[[i]] : subscript out of bounds

Can someone please tell me what this error is?

Thanks
#
Thank you for your reply!

It says:
This is mgcv  1.5-5 . For overview type `help("mgcv-package")'.

Its version: R 2.9.2

And summary(data2) gives:

       id              age             bmi           siblings        gender   
 Min.   :   1.0   Min.   :32.19   Min.   :16.41   Min.   :0.000   Female:494  
 1st Qu.: 273.5   1st Qu.:48.11   1st Qu.:23.44   1st Qu.:1.000   Male  :521  
 Median : 567.0   Median :57.86   Median :25.81   Median :1.000               
 Mean   : 559.5   Mean   :58.72   Mean   :26.42   Mean   :1.401               
 3rd Qu.: 839.5   3rd Qu.:69.06   3rd Qu.:28.90   3rd Qu.:2.000               
 Max.   :1117.0   Max.   :90.02   Max.   :59.25   Max.   :2.000               
   cigarette                        alcohol    coffee     drugs    
 never  :533   None                     :380   No :209   None:930  
 Current:200   At least a glass per week:164   yes:806   yes : 85  
 Former :282   At least a glass per day :471                       
                                                                   
                                                                   
                                                                   
  maritalStatus      edu                job        famhxGast       famhxPep  
 Single  :128   Min.   :1.000   Employed  :510   Min.   :1.00   Min.   :1.0  
 Married :793   1st Qu.:1.000   retired   :362   1st Qu.:1.00   1st Qu.:1.0  
 Widowed : 61   Median :2.000   housewife :132   Median :1.00   Median :1.0  
 Divorced: 33   Mean   :1.901   unemployed: 11   Mean   :1.13   Mean   :1.2  
                3rd Qu.:3.000                    3rd Qu.:1.00   3rd Qu.:1.0  
                Max.   :4.000                    Max.   :2.00   Max.   :2.0  
    hp_stat    txerad       Symptoms    
 Absent :431   no :923   Min.   :0.000  
 Present:584   yes: 92   1st Qu.:0.000  
                         Median :0.000  
                         Mean   :0.466  
                         3rd Qu.:1.000  
                         Max.   :1.000
#
On Monday 06 December 2010 09:33, Stressed1985 wrote:
- it's a bit difficult on the basis of the information you've supplied... 
- What version of mgcv are you using and with what R version on what platform? 
- What does summary(data2) give? 

best,
Simon
#
Ok, i just tried this:

library(mgcv)
model3=gam(data2$Symptoms~as.factor(data2$txerad)+as.factor(data2$maritalStatus),family=binomial,data=data2) 

And im still getting this error!

Error in dl[[i]] : subscript out of bounds
#
Probably the problem is with trying to smooth maritalStatus, which is a factor 
variable. Smooths are generally functions of metric variables (i.e. variables 
that take numerical values, where the ordering is meaningful). You can have 
random effect smooths and markov random field smooths in more recent mgcv 
versions (which can take factor arguments), but I doubt that these would be 
all that useful here... I would simply include maritalStatus as a factor 
variable.
On Monday 06 December 2010 11:37, Stressed1985 wrote:

  
    
#
OK, try...
model3=gam(Symptoms~as.factor(txerad)+as.factor(maritalStatus),family=binomial,data=data2)
or 
model3=gam(data2$Symptoms~as.factor(data2$txerad)+as.factor(data2$maritalSt
atus),family=binomial)
... both types of construction work with the current mgcv:gam (and with glm). 
Your construction doesn't work with the current mgcv:gam (or the current 
glm).
On Monday 06 December 2010 12:01, Stressed1985 wrote: