Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Models 8.4 and 8.5 #3

Closed
ASKurz opened this issue Mar 28, 2018 · 4 comments
Closed

Models 8.4 and 8.5 #3

ASKurz opened this issue Mar 28, 2018 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@ASKurz
Copy link
Owner

ASKurz commented Mar 28, 2018

I've been unable to figure out the brms equivalent to McElreath’s:

#8.4
m8.4 <- map2stan(
    alist(
        y ~ dnorm( mu , sigma ) ,
        mu <- a1 + a2 ,
        sigma ~ dcauchy( 0 , 1 )
),
data=list(y=y) , start=list(a1=0,a2=0,sigma=1) , chains=2 , iter=4000 , warmup=1000 ) 

#8.5
m8.5 <- map2stan(
    alist(
        y ~ dnorm( mu , sigma ) ,
        mu <- a1 + a2 ,
        a1 ~ dnorm( 0 , 10 ) ,
        a2 ~ dnorm( 0 , 10 ) ,
        sigma ~ dcauchy( 0 , 1 )
),
data=list(y=y) , start=list(a1=0,a2=0,sigma=1) , chains=2 , iter=4000 , warmup=1000 ) 

It's the double intercept. It has me stumped.

@ASKurz ASKurz added the help wanted Extra attention is needed label Mar 29, 2018
@paul-buerkner
Copy link

Define two variables, name tham, say, intercept1 and intercept2 and set them to 1 for all observations. Then specify y ~ 0 + intercept1 + intercept2.

@ASKurz
Copy link
Owner Author

ASKurz commented Apr 5, 2018

Ah; thanks for the idea, Paul! Along those lines, this works for model 8.5:

y <- rnorm(100, mean = 0, sd = 1)

b8.5 <-
  brm(data = list(y = y,
                  intercept1 = 1,
                  intercept2 = 1), 
      family = gaussian,
      y ~ 0 + intercept1 + intercept2,
      prior = c(set_prior("normal(0, 10)", class = "b"),
                set_prior("cauchy(0, 1)", class = "sigma")),
      inits = list(list(intercept1 = 0, intercept2 = 0, sigma = 1),
                   list(intercept1 = 0, intercept2 = 0, sigma = 1)),
      chains = 2, iter = 4000, warmup = 1000)

Is there a way to approach the challenge without altering the data?

@paul-buerkner
Copy link

Nope. To be honest, having two intercepts in the same model is pretty arcane and so there is not built-in solution for this. Please note that the "Intercept" inits won't work the way you specified them.

@ASKurz
Copy link
Owner Author

ASKurz commented Apr 5, 2018

Ha. I caught the inits issue right around the time you responded.

Thanks, again, for the help.

@ASKurz ASKurz closed this as completed Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants