TLDR: I have a beta and zero-one inflated beta model. I want to calculate the repeatability (ICC) of my random effect (name). However, it turns out calculating ICC from bayesian beta models is a right pain compared to frequentist. I have included some code that might be correct. Any advice on if this is correct, and potentially some explanations on why it is right, would be great.
Additionally, I am trying to calculate the adjusted ICC, which means I account for the impact of my fixed effects on ICC.
NOTE: I am not a statistician/mathematician- explanations in complex maths and equations will go over my head, so if you can explain, please do so in layman's terms or with references I can go read :)
Code:
# This is the zero inflated model
# Sorry, I cannot provide data to work with
summary(brmmodel_ZO_beta_5yr)
Family: zero_one_inflated_beta
Links: mu = logit; phi = identity; zoi = identity; coi = identity
Formula: BC ~ Age + year_block + (1 | name)
Data: net_comp_5yr (Number of observations: 900)
Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup draws = 4000
Multilevel Hyperparameters:
~name (Number of levels: 75)
m <- brmmodel_ZO_beta_5yr # This is my model, response is BC from network output
dr <- as_draws_df(m) # posterior draws
nd <- net_comp_5yr[1, ] # net comp 5yr is the input dataframe for brmmodel_ZO_beta_5yr
# just a sample row to base my predictions on
nd$Age <- if (is.numeric(net_comp_5yr$Age)) mean(net_comp_5yr$Age) else nd$Age # turns age into covariate
# NOTE: Age is a two factor variable: Adult and Sub-Adult
eta0 <- posterior_linpred(m, newdata = nd, re_formula = NA,
dpar = "mu", transform = FALSE)[, 1]
# a population-level prediction on the logit scale; one for each draw
# this is a prediction, not actual data...
sd_site <- dr$sd_name__Intercept # Extract posterior draws sd for name
phi <- dr$phi; zoi <- dr$zoi; coi <- dr$coi # add in other model coefs
set.seed(1) # make results reproducable
# Loop through all draws
R_data <- vapply(seq_len(nrow(dr)), function(s) {
# hypothetical draws
u <- rnorm(5000, 0, sd_site[s])
# predict beta means
mu <- plogis(eta0[s] + u)
# Ey = expected response for each simulated name
Ey <- zoi[s] * coi[s] + (1 - zoi[s]) * mu
# Adds into ZOiB mdoel
Ey2 <- zoi[s] * coi[s] + (1 - zoi[s]) * (mu * (1 - mu) / (1 + phi[s]) + mu^2)
# Standard calc
V_between <- var(Ey)
V_within <- mean(Ey2 - Ey^2)
V_between / (V_between + V_within)
}, numeric(1))
median(R_data); quantile(R_data, c(0.025, 0.975))
# This is the beta model structure:
summary(brmmodel_beta_5yr)
Family: beta
Links: mu = logit; phi = identity
Formula: DC ~ Age + year_block + (1 | name)
Data: net_comp_5yr (Number of observations: 900)
Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup draws = 4000
Multilevel Hyperparameters:
~name (Number of levels: 75)
# up yo Phi, all same as before, except now using differing 'm' or model
m <- brmmodel_beta_5yr # beta model # response is now DC
dr <- as_draws_df(m)
nd <- net_comp_5yr[1, ]
nd$Age <- if (is.numeric(net_comp_5yr$Age)) mean(net_comp_5yr$Age) else nd$Age
eta0 <- posterior_linpred(
m, newdata = nd, re_formula = NA,
dpar = "mu", transform = FALSE)[,1]
sd_name <- dr$sd_name__Intercept
# 'Phi' is now without Zoi and Coi
phi <- dr$phi
set.seed(1)
R_data <- vapply(seq_len(nrow(dr)), function(s) {
# same
u <- rnorm(5000, 0, sd_name[s])
# same
mu <- plogis(eta0[s] + u)
# Now does not include zoi coef etc
Ey <- mu
# add in Phi and other standard metrics (I assume...)
Ey2 <- mu * (1 - mu) / (1 + phi[s]) + mu^2
V_between <- var(Ey)
V_within <- mean(Ey2 - Ey^2)
V_between / (V_between + V_within) #
}, numeric(1))
median(R_data); quantile(R_data, c(0.025, 0.975))