0

I am creating a Bayesian linear regression model to predict points scored by players in a game using R and JAGS. I have 5 predictors, and the basic linear regression model is of the form:

points = beta0 + (beta1 * x1) + (beta2 * x2) + (beta3 * x3) + (beta4 * x4) + (beta5 * x5)

As each player is unique, I have added a hierarchy using the following JAGS model string:

model {
for ( i in 1:Ntotal ) {
  y[i] ~ dnorm( dmu[i], tau )
  
  dmu[i] <- beta0[p[i]] + beta[p[i],1]*x[i,1] + beta[p[i],2]*x[i,2] + beta[p[i],3]*x[i,3] 
                        + beta[p[i],4]*x[i,4] + beta[p[i],5]*x[i,5]
}
for ( subject_p in 1:n_subjects ) {           
   beta0[subject_p] ~ dnorm( dmu0 , 1/Var0 )
   
   for ( z in 1:Ncols ) {
     beta[subject_p,z] ~ dnorm( mu[z], 1/Var[z] )
   }
}
tau ~ dgamma(0.01, 0.01)

"p" in p[i] is the id of a given player.

mu[z] and Var[z] are specified individually, along the lines of:

mu[1] <- 5
Var[1] <- 0.1

By monitoring "beta0" and "beta" I get posterior estimates for beta parameters for each player (beta[1,1], beta[1,2] ...). I also want to extract the value of each beta parameter for the group of players (e.g., beta[1], beta[2]...)

If it helps, suppose beta[1,2] (the coefficient of predictor 2 for player 1) was 2.3, and I interpret this as "for each unit increase in predictor 2, the predicted points for player 1 increases by 2.3 (on average)". I would like to extract the overall beta parameter values so I could say something like "overall, a one unit increase in predictor 2 increases a player's predicted points by x (on average)".

Is this possible? And how would I modify my model string to achieve it?

JimJam
  • 1
  • The `mu[z]` parameters are the values you want, but it looks like you're not estimating them, but providing them as data. These `mu` values are hyper parameters and you wold need to put priors on them (i.e., hyperpriors). So, in short, you would have to estimate them rather than provide them as data. You should also do that with the variances, too. – DaveArmstrong Oct 25 '22 at 16:44
  • Thanks @DaveArmstrong, I think betas are the parameters I want to monitor. The current model string produces beta coefficients for each variable/predictor, for each player, and I'm hoping I can produce an "overall" beta parameter, for each predictor/variable. I had thought about mu[j], but I also want to use informative priors, hence why I'm providing them as data e.g., mu[1] <- 5 Var[1] <- 0.1 – JimJam Oct 29 '22 at 04:47
  • In the true multilevel context, the `mu` is the global parameter. In that context, you're saying that, for example, `beta[p[I], 1]` is drawn from a normal distribution with mean `mu[1]` and variance `1/tau[1]`. Again, in the traditional multilevel context, `mu[1]` is a hyperparameter that is given hyperpriors. For example, you could say `mu[1] ~ dnorm(5, 10)` in which case you would be saying that the global coefficient is centred at 5 with a variance of 10. Then you also need to provide a prior distribution for the level-2 residual variance, e.g., `tau[1] ~ dgamma(1,.1)`. – DaveArmstrong Oct 31 '22 at 14:33
  • Thanks @DaveArmstrong, I'll give that a go and see what I come up with. Thanks for your help! – JimJam Nov 06 '22 at 11:18

0 Answers0