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

Allow 0-column newdata if positive number of rows #492

Merged
merged 1 commit into from
Dec 11, 2020

Conversation

jgabry
Copy link
Member

@jgabry jgabry commented Dec 10, 2020

fixes #491

This PR avoids performing one of the checks on newdata that resulted in an error if newdata had 0 columns. Allowing 0-column newdata is useful for doing posterior_predict() for intercept only models, as pointed out in #491 by @davidkane9. With this change, the following now works:

fit <- stan_glm(mpg ~ 1, data = mtcars)
posterior_predict(fit, newdata = tibble::tibble(.rows = 1)) # generate predictions for 1 obs
posterior_predict(fit, newdata = tibble::tibble(.rows = 2)) # generate predictions for 2 obs
...

@jgabry
Copy link
Member Author

jgabry commented Dec 11, 2020

This also works with posterior_epred() and posterior_linpred(). I will also add a test.

@jgabry jgabry requested a review from bgoodri December 11, 2020 02:06
@bgoodri bgoodri merged commit e7317be into master Dec 11, 2020
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

Successfully merging this pull request may close these issues.

Passing empty tibble to posterior_predict() when using intercept-only models
2 participants