Hi all,
I am trying to build a model to explain variance in y in a country-year panel data.
However, the variance in y is so small in the 9 years that I have in the dataset.
Therefore, random intercepts for the countries (iso3c) and years (year) explain virtually all the variance (R2 = 0.94).
In my regressions, is it ok, if I avoid random intercepts for countries to make sure the rest of the model (other independent variables) explain the variance rather than only random country intercepts?
I share my formula, code, and data below. I will appreciate any suggestions regarding how to move forward.
df_replicate.csv (53.0 KB)
# y is left censored
# iso3c is country codes
# year is years
library(tidverse)
library(brms)
df_replicate <- read_csv("df_replicate.csv")
brms_formula <- "y | cens(cens) ~ (1 | iso3c) + (1 | year)"
mod <- brm(bf(brms_formula),
data = df_replicate,
prior = c(
prior(normal(0,1), class = Intercept),
prior(exponential(1), class = sigma),
prior(exponential(1), class = sd)
),
cores = 4,
chains = 4,
seed = 231024,
warmup = 2000,
iter = 8000,
control = list(adapt_delta = 0.99,
max_treedepth = 15))
summary(mod)
bayes_R2(mod)
Here are the results:
summary(mod)
Family: gaussian
Links: mu = identity; sigma = identity
Formula: y | cens(cens) ~ (1 | iso3c) + (1 | year)
Data: df_replicate (Number of observations: 1602)
Draws: 4 chains, each with iter = 8000; warmup = 2000; thin = 1;
total post-warmup draws = 24000
Group-Level Effects:
~iso3c (Number of levels: 178)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept) 0.58 0.03 0.52 0.65 1.01 532 1582
~year (Number of levels: 9)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept) 0.07 0.02 0.04 0.12 1.00 3616 6245
Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept -0.03 0.05 -0.12 0.06 1.02 169 521
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 0.10 0.00 0.10 0.11 1.00 9786 14244
bayes_R2(mod)
Estimate Est.Error Q2.5 Q97.5
R2 0.9355031 0.008382389 0.9162093 0.9485666