This is the data and initial model that runs fine
n <- 50 # number of reps/group
mu_n <- 0 # means for each group
mu_c1 <- 0.2
mu_c2 <- 0.3
mu_c3 <- 0.3
mu_c4 <- 0.4
d <- tibble(group = rep(c("normal", "covid1", "covid2", "covid3", "covid4"), each = n),
cases = rep(c (1, 2, 3, 4, 5), each = n)) %>%
#as.factor(cases) %>%
mutate(y = c(rnorm(n , mean = mu_n, sd = 1),rnorm(n , mean = mu_c1, sd = 1),rnorm(n , mean = mu_c2, sd = 1),rnorm(n , mean = mu_c3, sd = 1),rnorm(n , mean = mu_c4, sd = 1)))
as.factor(d$cases)
fit <-
brm(data = d,
family = gaussian,
y ~0+ group,
prior = c(prior(normal(0,2), class = b),
prior(student_t(3,1,1), class = sigma)),
seed =1)
When I update the model and try to run the model to measure the difference between only two groups ( normal and covid4, I got this error
sim_d_and_fit <-
function
(seed, n, probs=c(0.05, 0.95)) {
mu_n <- 0 # means for each group
mu_c1 <- 0.2
mu_c2 <- 0.3
mu_c3 <- 0.3
mu_c4 <- 0.4
set.seed(seed)
d <- tibble(group = rep(c("normal", "covid1", "covid2", "covid3", "covid4"), each = n),
cases = rep(c (1, 2, 3, 4, 5), each = n)) %>%
#as.factor(cases) %>%
mutate(y = c(rnorm(n , mean = mu_n, sd = 1),rnorm(n , mean = mu_c1, sd = 1),rnorm(n , mean = mu_c2, sd = 1),rnorm(n , mean = mu_c3, sd = 1),rnorm(n , mean = mu_c4, sd = 1),x))
as.factor(d$cases)
update(fit,
newdata = d,
seed = seed) %>%
fixef(probs = probs) %>%
data.frame("groupcovid4","groupnormal") %>%
rownames_to_column("parameter") %>%
filter(parameter ==c("groupcovid4","groupnormal"))
}
n_sim <-100
s1 <-
tibble(seed =1:n_sim) %>%
mutate(b1 = map(seed, sim_d_and_fit, n =60)) %>%
unnest(b1)
the error
Error in `$<-.data.frame`(`*tmp*`, "call_text", value = c("... %>% unnest(b1)", :
replacement has 4 rows, data has 2