Updating a BRMS model with new data--what is happening behind the scenes?

Hi,

I’m wondering what is happening behind the scenes when I use brms::update to fit a model to new data. Do posteriors from the original model influence the updated model?

I’ve been searching the web and brms/stan documentation, but I’m coming up short on answers.

Here’s a reproducible example

library(brms)
set.seed(1 )
data1 <- data.frame(x =  rnorm(1000)) # data for species 1
data1$y = data1$x + rnorm(1000, 0, .01)

data2 <- data.frame(x =  rnorm(10))   # data for species 2
data2$y = data2$x + rnorm(10, 0, 2)

plot(y~x, data1, col = "red")
points(y~x, data2, col = "blue")

prior <- prior(normal(0, 5), nlpar = "a") + 
  prior(normal(0, 5), nlpar = "b") 

m1 <- brm( bf( y  ~  x * a + b,
               a + b ~ 1,
               nl = TRUE), data = data1, prior = prior,  sample_prior = T)


m2 <- brm( bf( y  ~  x * a + b,
               a + b ~ 1,
               nl = TRUE), data = data2, prior = prior,  sample_prior = T)

m3 <- update(m1, newdata = data2)

# is there a difference between how m2 and m3 were fit or are they functionally the same procedure? 

with gratitude,
joe

2 Likes

Hi Joe,

No the posteriors from the original estimation do not affect the sampling of the model with new data. But you should also know that the priors used do not get updated in accordance with the new data. This means that if you are using any default priors (which are derived from the data), then priors derived using the original data will be applied to the new data.

This is why you might get slightly different estimates if you update an existing brm object, rather estimating a new model entirely

4 Likes