Fitting the model
- In
lme4
(and others) this is expressed as:
library(lme4)
fit <- glmer(
HR ~ (1 | pitcher) + (1 | batter),
data = sc_2023,
family = binomial
)
VarCorr(fit) # get sigma_p and sigma_b
## Groups Name Std.Dev.
## pitcher (Intercept) 0.188
## batter (Intercept) 0.523
- Results suggest more of the variation in home runs is due to batter effects then pitcher effects.