I am reading Statistical Rethinking (2nd edition) from Richard McElreath and in the 4th chapter there is example of B-Spline, which is solved by quap (quadratic approximation) and I would like to solve it by ulam (HMC).
data("cherry_blossoms")
d = cherry_blossoms
d2 = d[ complete.cases(d$temp), ]
num_knots = 15
knot_list = quantile(d2$year, probs = seq(0,1,length.out = num_knots))
library(splines)
B = bs(d2$year,knots = knot_list[-c(1,num_knots)],degree = 3, intercept = TRUE) #matrix 1124 x 17
m4.7 = quap(
alist(
T ~ dnorm(mu, sigma),
mu <- a + B %*% w,
a ~ dnorm(6,10),
w ~ dnorm(0,1),
sigma ~ dexp(1)
), data = list(T= d2$temp,B=B),start = list(w = rep(0,ncol(B)))
)
But it seems that I can't multiply matrix of predictors (B
) by parameter vector (w
) in ulam interface. Can someone advise me how to do this in ulam interface? (mu <- a + B %*% w
)