Hi all I am running a 3-level hierarchical linear model with brms to estimate between-runners and within-runners between races variability. The model is the following :
model1 <-
brm(
LNSPEED ~ 1 + linear_year + TIME + I(TIME^2) + I(TIME^3) +
TIME:linear_year + I(TIME^2):linear_year + I(TIME^3):linear_year +
(1+TIME|ID) + (1+TIME|ID:YEAR),
iter=2000,
control = list(adapt_delta = 0.95, max_treedepth=15),
seed=12345,
data=Dataset_1
)
where within-race LNSPEED
is modeled as a cubic finction of within-race TIME
, ID
is a grouping factor of the individual runners and YEAR
is a grouping factor of individual race (thus ID:YEAR
is a grouping factor indicating within-runner between races).
I am estimating various predicted marginal effects:
The expected grand mean:
all_RUNNERS_1_dist <-
model1 %>%
epred_draws(
newdata = expand_grid(linear_year=seq(0,1, by=0.25), TIME = seq(0, 8, by = 0.25)),
re_formula = NA
)
The expected average performance of runners:
all_RUNNERS_1_avg_perform_dist <-
model1 %>%
epred_draws(
newdata = expand_grid(linear_year=seq(0,1, by=0.25), TIME = seq(0, 8, by = 0.25), ID = unique(Dataset_1$ID)),
re_formula =~ (1+TIME | ID)
)
However I cannot get an estimate for the expected performance of individual races within runners:
all_RUNNERS_1_race2race_perform_dist <-
model1 %>%
epred_draws(
newdata = expand_grid(linear_year=seq(0,1, by=0.25), TIME = seq(0, 8, by = 0.25), **ID = unique(Dataset_1$ID), YEAR=unique(Dataset_1$YEAR)** ),
re_formula =~ (1+TIME | ID)+(1+TIME | ID:YEAR)
)
More specifically ID = unique(Dataset_1$ID), YEAR=unique(Dataset_1$YEAR)
produces an error since my data is unbalanced given that not all runners have competed in all races (the dataset includes seven races and runners have competed 1-6 races each).
I cannot get around on how the YEAR factor should be specified in the newdata argument to match the re_formula =~ (1+TIME | ID)+(1+TIME | ID:YEAR)
.
Thank you in advance.
edited by @jsocolar for syntax highlighting and code formatting.