Hi all,
I would like to set starting values for a brms::brm
model manually for some coefficients only and according to a function (runif).
My current code looks something like this (you can ignore x
variables and unit
, I just want to manipulate the starting values of z
and of "as.factorFa1
and "as.factorFa2
):
library(tidyverse)
library(brms)
df <- data.frame(x1 = rnorm(100, mean = 1, sd = 2),
x2 = rnorm(100, mean = 2, sd = 2),
x3 = rnorm(100, mean = 3, sd = 2),
z = rnorm(100, mean = 4, sd = 2),
Fa = wakefield::r_sample_factor(n = 100, x = c(1, 2, 3)),
unit = wakefield::r_sample_factor(n = 100, x = 1:10),
Y = rnorm(100, mean = 15, sd = 5)
) %>% tibble::tibble()
brmsmodel <- brm(Y ~ as.factor(Fa) + # Fa has levels 1, 2, 3
x1 + x2 + x3 + z + (1 + x1 | unit),
data = df,
prior = c(prior(normal(0, 1), class = "b", coef = "z"),
prior_string("normal(0, 1)", class = "b", coef = paste("as.factorFa", 2:3, sep=""))),
chains = 1, iter = 25, warmup = 10, seed = 123,
init = "0")
This code works; however, I would like to set some starting values (inits
) manually to be drawn from a uniform distribution (X ~ U[0,1])
, similar to the priors.
I want something like this (pseudo code)
inits: 1) init = runif(0, 1), class = "b", coef = "z"
2) init = runif(0, 1), class = "b", coef = "as.factorFa2"
3) init = runif(0, 1), class = "b", coef = "as.factorFa2"
other inits: random
I only found inits = "0"
(to set all starting values to 0) or the default inits = "random"
. Can someone advise how to do this? Thanks in advance!