# How to obtain the variance of fixed effects?

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.

• You've calculated standard errors, these do not tell you about "which factors have greater weight in the proportion of incidence". Please can you be a bit more clear about what exactly is your research question(s) ? Oct 4, 2020 at 14:40
• Determing what predictor variables (habitat, season or site) have more weigh on the proportion in incidence variation of this virus, (i,e; percentage of variance explained) and within them which is thepercentage of variance explained of the different habitats, seasons and sites Oct 4, 2020 at 15:02
• Variances of the fixed effects (standard errors squared) do not tell you anything about percentage of variance explained by the variables. Oct 4, 2020 at 15:32
• So, how can I obtain the percentage of variance explained by the variables of this dataset? Thank you Oct 4, 2020 at 15:41

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)


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)


• I agree with your statement to use a GLMM with binomial family and used R^2 to explain what factor has higher effect in the incidence but, how do I know the R^2 of Crop and Autumn? Thank you in advance Ben Nov 3, 2020 at 17:21

Have you checked the model diagnostics for your linear mixed effects model? Incidence is a so-called "discrete proportion" and may be better modelled by a generalized linear mixed effects model (GLMM) with binomial family via the glmer() function in the lme4 package of R.

It seems like what you need is to report R-squared values for your linear mixed effects model (if its model diagnostics look acceptable) or pseudo R-squared values for your GLMM model.

For mixed effects models - be them linear or generalized linear - there are two types of R-squared values you can report:

1. Marginal R-Squared: Proportion of the total variance explained by the fixed effects;

2. Conditional R-Squared: Proportion of the total variance explained by the fixed and random effects.

These values can be computed, for instance, using the rsquared() function in the R package piecewiseSEM or the function r2_nakagawa() from the performance package.

See the article The coefficient of determination R2 and intra-class correlation coefficient from generalized linear mixed-effects models revisited and expanded by Nakagawa et al. available at https://royalsocietypublishing.org/doi/10.1098/rsif.2017.0213.