tidybayes.rethinking
tidybayes.rethinking copied to clipboard
`predicted_draws()` is missing `sim()`'s `vars` argument
In the example on p. 143-144 of Rethinking, 2nd ed, we have
# d has columns A, M, and D
m5.3A <- quap(
alist(
D ~ dnorm(mu, sigma).
mu <- a + bM * M + bA * A,
a ~ dnorm(0, 0.2),
bM ~ dnorm(0, 0.5).
bA ~ dnorm(0, 0.5),
sigma ~ dexp(1),
M ~ dnorm(mu_M, sigma_M),
mu_M <- aM + bAM * A,
aM ~ dnorm(0, 0.2),
bAM ~ dnorm(0, 0.5),
sigma_M ~ dexp(1)
), data = d
)
A_seq <- seq(2, 2, length.out = 30)
# notice, no M in sim_dat
sim_dat <- data.frame(A = A_seq)
# Use the model first to infer M from A and then to
# infer D from M and A
s <- sim(m5.3A, data = sim_dat, vars = c("M", "D"))
I can't figure out a way to do this with add_linpred_draws(). When I try
s <- predicted_draws(m5.3A, sim_dat)
I get an error message about "M" not found.
More generally, is there a way to use predicted_draws to extract predictions of M from this model, given a data frame with values of A?
If I call
s <- predicted_draws(m5.3A, sim_dat, vars = c("M", "D"))
I get an error
Error: `draws` must have exactly two dimensions. It has 0
I've submitted PR #17 to fix this problem.