lundi 9 mars 2020

bam error when adding random effect: data must be a data.frame

I have a dataframe with 365814 observations that I want to use for fitting a GAMM with mgcv. The following code works:

Speed_model_test<-bam(mean_dist~ habitat_type2 + s(Forest_density, bs="cr") + s(Ruggedness, bs="cr") + Hunting_in_season + Winter_enclosure_yes_no + sex,  data=red_deer_15_min2,link=gaussian(type="log"))

However, as soon as I add a random effect for the different individuals in the dataset, I get an error when fitting the model with the same dataframe:

Speed_model_test<-bam(mean_dist~ habitat_type2 + s(Forest_density, bs="cr") + s(Ruggedness, bs="cr") + Hunting_in_season + Winter_enclosure_yes_no + sex + s(individual.local.identifier, bs="re"), data=red_deer_15_min2,link=gaussian(type="log"))

Error in model.matrix.formula(form, data) : data must be a data.frame

What could cause this error and how can it be solved?

Thanks a lot in advance!




Aucun commentaire:

Enregistrer un commentaire