1
$\begingroup$

I have been fitting a bayesian GLM using brms. The code works well but when I loop this over several data and make it a bit more complex, R encounters a fatal error and crashes. This seems to be happening to other people when using brms. I am now looking into other methods to code this in R (eg, stan_glm, bayesglm), but they don't seem to accept bounded uniform priors like brms does, which is what I need. Does anyone have suggestions? Thanks

code

N <- c(10, 12, 15, 20, 18)  
success <- c(2, 4, 6, 8, 10)  
x1 <- c(0, 0, 0, 0, 5)  
x2 <- c(0.5, 0.5, 0.5, 0.5, 0.5)  

data <- data.frame(N, success, x1, x2)

prior1 <- c(set_prior("uniform(-4,0)",  class = "b", coef = "x1"),
            set_prior("uniform(-4,0)",  class = "b", coef = "x2"))

fit_bglm <- brm(success | trials(N) ~ -1 + x1 + x2,
                       data = data,
                       family=binomial(link = "log"),
                       prior=prior1, chains = 8, iter = 8000,
                       seed=154511)
$\endgroup$
1
  • $\begingroup$ 1) link = log is not typically a good link function for the binomial distribution. 2) (a simplification tip) Why do you create a new variable x2 equal to 1/2 of what the intercept would be instead of just using the intercept? You can set a prior on the intercept directly via class = "Intercept". 3) It would be better to give us an example which breaks, rather than an example which works; it's hard to debug code that appears to be working. $\endgroup$
    – jbowman
    Commented May 25, 2023 at 19:23

0

Your Answer

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

Browse other questions tagged or ask your own question.