Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

predicted_draws() is missing sim()'s vars argument #15

Open
jonathan-g opened this issue Sep 13, 2022 · 2 comments
Open

predicted_draws() is missing sim()'s vars argument #15

jonathan-g opened this issue Sep 13, 2022 · 2 comments

Comments

@jonathan-g
Copy link

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?

@jonathan-g
Copy link
Author

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

@jonathan-g
Copy link
Author

I've submitted PR #17 to fix this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant