Fitted values transformation

Hi,
I was looking to find the derivative of a smooth curve. The model is formulated as follow:

m2 <- brm(bf(postive|trials(total) ~ s(time)),
          data = dat2, family = binomial(), cores = 4, seed = 17,
          iter = 4000, warmup = 1000, thin = 10, refresh = 0,
          control = list(adapt_delta = 0.99))

I tried this

len = 100
delta<-1e-10
x1_new <- seq(min(dat2$time), max(dat2$time), length.out = len)
newdata<-data.frame(x1_new, rep(1, 100))
names(newdata)<-c('time','total')
f1 = fitted(m2, newdata = newdata)

x2_new <- seq(min(dat2$time), max(dat2$time), length.out = len)+delta
newdata<-data.frame(x2_new, rep(1, 100))
names(newdata)<-c('time','total')
f2 = fitted(m2, newdata = newdata)

Derivative<-(f2$Estimate-f1$Estimate)/delta

Not sure how can I compute the confidence interval around it? Is it possible to define such quantities in the generated block of stan model?

Thanks

Got the answer for anyone interested https://dilshersinghdhillon.netlify.app/post/estimating-smooth-trends-and-identifying-periods-of-change-using-bayesian-inference/

2 Likes