Hi. I’m trying to fit a hierarchical growth model to Coronavirus case counts. I can fit a simple model to a single country with reasonable results, but as soon as I try to introduce country as a new level the results no longer make sense. I attach a file with data for a few countries: corona_counts.csv (10.5 KB) and the following should hopefully illustrate the problem.
library(tidyverse)
library(brms)
library(bayesplot)
case_counts <- read_csv("corona_counts.csv")
case_counts$Country.Region <- as.factor(case_counts$Country.Region)
### Fit single country
form_1 <- bf(cum_cases ~ A * exp( -exp( -(k * (day - delay) ) ) ),
A ~ 1 ,
k ~ 1 ,
delay ~ 1 ,
nl = TRUE)
priors1 <- c(
prior(lognormal(0.65, 0.5), nlpar = "A", lb=0),
prior(lognormal(0.65, 0.5), nlpar = "k", lb=0),
prior(lognormal(0.65, 0.5), nlpar = "delay", lb=0),
prior(student_t(5, 0, 1.5), class = "sigma"))
mod1 <- brm(form_1, data = case_counts %>% filter(Country.Region == "China"),
prior = priors1, seed = 1234,
family = lognormal(link = "identity", link_sigma = "identity"),
chains = 4, cores=4, sample_prior = "no")
summary(mod1)
plot(conditional_effects(mod1), points = TRUE)
This gives me a not great but not totally out of the ballpark fit:
However when I try to make a hierarchical model by country:
### Fit multiple countries with hierarchical model
form_mult <- bf(cum_cases ~ A * exp( -exp( -(k * (day - delay) ) ) ),
A ~ 1 + (1 | Country.Region),
k ~ 1 + (1 | Country.Region),
delay ~ 1 + (1 | Country.Region),
nl = TRUE)
modmult <- brm(form_mult, data = case_counts,
prior = priors1, seed = 1234,
family = lognormal(link = "identity", link_sigma = "identity"),
chains = 4, cores=4, sample_prior = "no")
summary(modmult)
conditions <- make_conditions(case_counts, "Country.Region")
plot(conditional_effects(modmult, conditions = conditions ), points = TRUE)
Things are rather ugly:
It appears to give me the same linear fit no matter the country.
Where am I going wrong here? Any tips appreciated!
- Operating System: Catalina
- brms Version: 2.12