library(nlme); library(emmeans); library(performance)
library(lme4)
13 Variance & Variance Components
Mixed models provide the advantage of being able to estimate the variance of random variables. Instead of looking at a variable as a collection of specific levels to estimate, random effects view variables as being a random drawn from a normal distribution with a standard deviation. The decision of how to designate a variable as random or fixed depends on
13.1 Unequal Variance
13.1.1 Case 1: Unequal Variance Due to a Factor
<- here::here(read.csv("data", "MET_trial_variance.csv")) var_ex1
$block <- as.character(var_ex1$block)
var_ex1hist(var_ex1$yield)
boxplot(yield ~ site, data = var_ex1)
<- lme(yield ~ site:variety + variety,
m1_a random = ~ 1 |site/block,
na.action = na.exclude,
data = var_ex1)
<- update(m1_a, weights = varIdent(form = ~1|site)) m1_b
<- update(m1_a, weights = varIdent(form = ~1|site)) m1_b
is equivalent to
<- lme(yield ~ site:variety + variety,
m1_b random = ~ 1 |site/block,
weights = varIdent(form = ~1|site),
na.action = na.exclude,
data = var_ex1)
13.2 Coefficient of Variation
<- fixef(m2_b)[1]
m2_ave names(m2_b) <- NULL
= sigma(m2_b)/m2_ave*100
m2_cv m2_cv
13.2.1 Looking at Variance Components
<- read.csv(here::here("data", "potato_tuber_size.csv")) var_comps