0

I ask the community for help on the following problem. Suppose we estimate the following regression model with fixed effects Age (factor variable) and Year (factor variable) as random effects.

set.seed(123)
# Packages
library(brms)
#install.packages("rstan")
library(rstan)

# Data simulation
age <- 10:20
year <- 1990:2000
n1 <-  length(age)
n2 <-  length(year) 
n <- n1*n2
y <- rnorm(n = n,mean = 50,sd = 30 )

beta_0 <- 0.25
beta_age <- 0.25
beta_year <- - 0.85

y <-beta_0+beta_age*age+beta_year*year

# Final Dataframe
d <- data.frame(y=y,
     Age=as.factor(rep(age,n2)),
     Year=as.factor(rep(year,n1))
     )

fit <- brm(y ~ 0+Age+(1|Year), d, iter = 50, warmup = 10, chains = 1)

fixef(fit)

> fixef(fit)
Estimate Est.Error      Q2.5      Q97.5
Age10 -1.5333147 1.3878804 -3.839673  1.0539617
Age11 -0.1285437 0.9321314 -1.221775  1.9525542
Age12 -2.1895797 1.2388774 -4.829345 -1.0598727
Age13  3.7247485 2.4157734  1.408428  8.4137437
Age14 -3.0134557 2.1435395 -8.148383 -1.1134809
Age15 -0.6631218 1.2442192 -2.122722  1.8919087
Age16 -1.2382832 1.6596973 -4.145329  0.3973843
Age17  1.7116087 2.4962776 -1.389026  5.3579521
Age18 -1.1881552 1.3884096 -4.155563  0.2962675
Age19 -0.6924640 1.0659378 -1.558155  1.3804710
Age20 -0.4457888 0.6615983 -1.763389  0.8225215


ranef(fit)

$Year
, , Intercept

Estimate Est.Error       Q2.5    Q97.5
1990 -1.3702433 1.7680814 -3.2623355 0.885315
1991 -2.2592311 2.3086167 -4.6791703 1.036105
1992  1.7228745 2.5290462 -0.4616315 4.225590
1993 -0.8166271 1.2671842 -2.1690639 1.809690
1994  1.7928488 2.2368656 -0.6837609 4.464356
1995  0.7169620 1.8096562 -0.5032051 3.002480
1996 -0.1112231 0.7797995 -0.7787910 1.614591
1997  2.1406982 2.2829444 -0.2656490 4.370186
1998 -0.3399042 1.0476426 -1.3453246 2.147565
1999  1.7134314 1.9736618 -0.5384686 4.063977
2000 -0.5178907 1.0331019 -1.5312055 1.854528

Obtained the coefficients, let’s suppose to get a 5-year forecast on the Year coefficient and obtain Year_F, let’s say c(1.0342, 0.9514, 0.9234, 0.8345, 0.7863) and length (Year_F) < length (Year) How can I reconstruct the equation: y_F ~ 0 + Age + (1 | Year_F)

Thanks for your support

5
  • Sorry, I don't understand what you're asking for. Could you edit the question to be clearer or more specific? Commented Jul 30, 2022 at 12:21
  • Thanks, basically the question is: pretending to get new coefficients fot "Year", how would you reconstruct the regression model? I mean the equation. Commented Jul 30, 2022 at 16:20
  • What do you mean by "reconstruct the regression model"? Commented Jul 30, 2022 at 18:33
  • Let's assume we are in a linear regression model, with the estimated coefficients b0 and b1: \hat{y} = \hat{b0} + \hat{b1} * x. Suppose we want to replace \hat{b1} with \hat{c1} and find \hat{z} = \hat{b0} + \hat{c1} * x ... In the context of linear regression it is very simple. How can I do when I have random effects? Commented Jul 31, 2022 at 6:10
  • Ah, okay, I think I see what you're after now. And that's not really a programming question so much as a methods question, which means you probably ought to post it on Stack Exchange rather than Stack Overflow. Commented Jul 31, 2022 at 12:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.