0
$\begingroup$

I have an ecological data set, whereby sediment mud content (%) (i.e. the continuous explanatory variable) is thought to be explaining the spatial distribution (i.e. presence/absence) of various estuarine benthic macroinvertebrate taxa (i.e. the binary response variable). Below is a subset of the data (actual data consists of >1400 replicates) for a single taxon, where the response is 'Bin' and the single predictor is 'Mud' and 'Estuary' is considered a random effect.

Estuary       Mud   Bin
FW            0.1   0
FW            0.3   0
FW            0.2   0
FW            2.1   0
POR           7.1   0
FOR           11.4  0
JRE           25.5  1
JRE           33.6  1
JRE           44.6  1
JRE           55.6  1
JRE           63.6  1
FW            76.6  1
FW            87.6  1
FW            90.6  1
FW            93.6  1

Here's the GAM model which used the mgcv package (and was conditioned on the 1400+ data points):

aa1.estuary<-gam(Bin~s(Mud,bs="ps", k=6) + s(Estuary, bs="re"),family=binomial, gamma=1,data=sample)

Here's the Cross validation step, which used CVgam in the gamclass package, but returned the error below when Estuary was included as a random effect:

aa1.val <- CVgam(formula=Bin~s(Mud, bs="ps", k=6) + s(Estuary, bs="re"), data = sample, nfold = 10, debug.level = 0, printit = TRUE, method = "GCV.Cp",cvparts = NULL, gamma = 1, seed =100)
Error in X[ind, ] : subscript out of bounds

To check, Estuary was omitted, generating the following output:

aa1.val <- CVgam(formula=Bin~s(Mud, bs="ps", k=6) , data = sample, nfold = 10, debug.level = 0, printit = TRUE, method = "GCV.Cp",cvparts = NULL, gamma = 1, seed =100)
     GAMscale    CV-mse-GAM  
     0.1491      0.1499

Hence I have two related questions: (1) whats causing the error when Estuary is included in the cross-validation step? and (2) do the above estimates of GAMscale=0.1491 and CV-mse-GAM =0.1499seem too close to one another to be realistic?

Thanks in advance,

$\endgroup$
  • $\begingroup$ Usually the smoothing is not added to categorical variables. In particular if you try to solve the same problem with the GAM package it requires a minimum number of unique values for each smoothed variable. $\endgroup$ – Donbeo Sep 3 '14 at 16:14
  • $\begingroup$ Any idea of syntax for a non-smoothed categorical random effect? $\endgroup$ – brober Sep 4 '14 at 20:52
  • 1
    $\begingroup$ just replace + s(Estuary) with + Estuary $\endgroup$ – Donbeo Sep 5 '14 at 9:41
  • $\begingroup$ so without the bs="re" term, Estuary is still considered a random effect? I tried this and deviance explained remained similar but AIC was lower with s(Estuary, bs="re") term compared to Estuary.. $\endgroup$ – brober Sep 7 '14 at 22:07

Your Answer

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

Browse other questions tagged or ask your own question.