R – How to Obtain the Variance of Fixed Effects in R

r

In order to analyse which factors have greater weight in the proportion of incidence (number of infected inidivuals against total individuals), the interaction of all factors (habitat, site and seasons) must be tested by a linear mixed model (LMM)

The predictor variables are habitat and season, considering at the same time the random factor sampling site and the response factor was the incidence value.

The dataset that I am using is this: https://drive.google.com/file/d/1fVuJNdZ593L6LoIKNhUynRGGIsN-IdxV/view?usp=sharing

I performed the LMM by R. Habitat and season as fixed factor and site as random

     lme(Incidence ~ Habitat + Season, random = ~1|Site) 

In order to extract the variance I execute these codes in r

      ##to obtain ramdon effects
      vc <- lme4::VarCorr(GlM_habitats)
       print(vc,comp=c("Variance","Std.Dev."),digits=2)
      Site = pdLogChol(1) 
        Variance     StdDev    
      (Intercept) 0.0031535943 0.05615687
      Residual    0.0008026781 0.02833157

      # Variance of fixed effects: 

      get_variance_fixed(GlM_habitats)
       var.fixed 
      0.01533339 

       var_fixed <- diag(vc_fixed); var_fixed
           (Intercept)      HabitatEdge   HabitatOakwood HabitatWasteland     SeasonSpring               SeasonSummer 
          0.0014200762     0.0020746951     0.0022753646     0.0022753646     0.0001337797     0.0004310081 
      # Standard errors of fixed effects: 
       se_fixed <- sqrt(var_fixed); se_fixed
           (Intercept)      HabitatEdge   HabitatOakwood HabitatWasteland     SeasonSpring     SeasonSummer 
            0.03768390       0.04554882       0.04770078       0.04770078       0.01156632       0.02076074 

However, I obtain the same variance value for crop (from habitat predictable variable) and autumn (from season predictable variable) called Intercept.
I do not know to separate them or obtain their variance value.

Thank you in advance

Best Answer

I second @IsabellaGhement's suggestion that you strongly consider a binomial model for the incidence (you'll need to know the 'denominator' — the total number of individuals used to compute the incidence).

$R^2$ measures do exist for linear mixed models, although there are several different, all slightly different,definitions. A reasonable place to start would be the overview of the r2glmm R package.

library(r2glmm)
library(nlme)
library(ggplot2)

m1 <- lme(Incidence ~ Habitat + Season, random = ~1|Site, data=dd)
ggplot(dd, aes(Season,Incidence,colour=Habitat))+
    stat_sum(alpha=0.4,position=position_dodge(width=0.2)) +
    scale_size(breaks=1:3,range=c(3,6))+
    geom_line(aes(group=Site),colour="gray")+
    scale_y_sqrt()+
    geom_hline(yintercept=0,lty=2)

enter image description here

Now compute $R^2$ and display:

r2 <- r2beta(model=m1,partial=TRUE,method='sgv')
print(r2)

            Effect   Rsq upper.CL lower.CL
1            Model 0.867    0.929    0.792
2      HabitatEdge 0.705    0.836    0.539
4 HabitatWasteland 0.639    0.797    0.443
3   HabitatOakwood 0.603    0.775    0.394
6     SeasonSummer 0.084    0.348    0.000
5     SeasonSpring 0.003    0.184    0.000
plot(x=r2)

enter image description here

Related Question