# Random effect in GAM (mgcv)

3 messages
Open this post in threaded view
|

## Random effect in GAM (mgcv)

 Dear R users, I am using the *mgcv package* to model the ratio of hectares of damaged culture by wild boar in french departments according to some environmental covariates. I used a _Beta distribution_ for the response. For each department, we estimated the damaged in 3 different culture types (« Culture »). Our statistical individual are therefore the department crossed by the culture type. Also, the department are clustered into landscape types (« Cluster »). Since I want to get the effect of the Culture type and the Landscape, I keep those variables as fixed effects in the model. Also, since we have 5 repetitions of the response and of some covariates measurement in time per department and culture type, I put a random effect on the Department per Culture type and the Year as fixed effect as well. The model takes the form : *gam_tot <- gam (resp ~ Culture + Clust**er**:Culture + s(**Year**,k=4, by=Culture) + s(**X1**, by=Culture) + s(**X2**, by=Culture) + s(Depts, bs="re", by=Culture) * *, family=betar(link="logit"),method="REML",data=data,select=FALSE)* Then, I estimated the part of the model explained deviance provided by each covariate. For that, I run the model without the given covariate (keeping smooth parameters constant between models), and compute the difference in deviance between the Full model (with the given covariate) and the penalized model (without the given covariate): (Full model Deviance – Penalized model Deviance) / Full Model Deviance  From that, I get a _huge proportion of Deviance explained by the random effect_ (Department) of about 30 %, while the others covariates explained less than 1 %. *At this point, I have few questions :* *- Do you think my model formula is correct regarding my data and questions ?* *- Is my estimate of explained deviance correct ?* *In that case, how can I explain such a huge discrepancy between **the part of deviance explained by **random and fixed effects ? * Thanks for your help, Amélie         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.