-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
posterior_traj example errors #497
Comments
Hi @jgabry -- sorry for the slow reply. Just going to look at this now. I can't reproduce the bug using my installed version of rstanarm, but I think I am running the |
I can't reproduce the bug using the CRAN version either. So, looking back at recent commits, I am thinking that it might be this The user shouldn't need to provide |
@pamelanluna -- any chance you are able to assist? What is the intended behaviour here: Line 402 in 73f7740
The In any case, there doesn't appear to have been an I guess one quick fix option, as unattractive as it is, would be to force the user to call |
Thanks for looking in to this. One reason we didn't notice this right away was because Travis CI wasn't working properly for rstanarm. With #496 I'm adding R cmd check via GitHub Actions which will help us detect things like this immediately.
No worries at all. I opened the issue on a Friday night so I wasn't expecting an immediate reply! |
And I think you're right that this has to do with the model.offset() stuff. Here's what R cmd check says:
|
The offset is defined in model formula (e.g.,
This was done on purpose since the offset is defined within the model formula. The offset shouldn't be redefined with posterior predictions but will need the relevant covariate from the data to calculate the offset. It's been awhile, so I don't remember if I included the offset variable in
As mentioned above, the main issue is from the exclusion of the response variable in the new data, so this approach wouldn't fix the case when there is an offset but no response variable. An equivalent quick fix would be the following:
Again, this would not fix the case of no response variable when there is an offset, but it would get the tests to pass for now. I probably won't have time to figure out the changes for that case until next week. |
Thanks @pamelanluna! This helps clear up my thinking a bit -- yeah, that makes sense that the offset is just joined on in a similar fashion to the other covariates. Thanks for clarifying. @jgabry -- is there an option in |
I don't think we have that for the # need to get the name of the response variable (is there an easier way?)
response_name <- as.character(formula(object)$Long1)[2]
# create a temporary data frame with a column of just 0s (or whatever) as a placeholder for response
newX_temp <- cbind(0, newX)
colnames(newX_temp) <- c(response_name, colnames(newX))
# doesn't error anymore if using newX_temp
newOffset <- model.offset(model.frame(terms(glmod), newX_temp)) |
Thanks @jgabry! -- yeah I think this would work. The only bit that might need changing is we'd need to extract the formula for submodel m. So Also if we wanted to follow a principal of only doing this when necessary, then you could nest it under an if condition like @pamelanluna suggested, something like:
P.s. this is untested at my end -- infact I'm typing this from a phone! |
Ok I think this should work. About to open a PR fixing this. |
@sambrilleman @pamelanluna Finally coming back to this because I'm hoping we can release an rstanarm update after we get the next release of rstan out. Unfortunately, my fix in PR #499 works to fix the case where there's no offset (and the examples in the doc don't fail anymore) but I can't figure out how to fix the case where there's an offset. More details in #499 (comment) |
Actually I think I figured it out. More details in #499 (comment) |
@sambrilleman I'm working on #496 and running r cmd check I noticed that this part of the
posterior_traj()
examplerstanarm/R/posterior_traj.R
Lines 248 to 249 in aab5e59
fails with this error:
Same error happens with the next part of the example:
rstanarm/R/posterior_traj.R
Lines 270 to 271 in aab5e59
I think this is because
logBili
also needs to be innewdata
. @sambrilleman I'm happy to fix this but I'm not sure what valueslogBili
should have for theseposterior_traj()
examples. Should it just be set to its mean from the data? Or multiple different values?The text was updated successfully, but these errors were encountered: