rbchan / unmarked

R package for hierarchical models in ecological research
https://rbchan.github.io/unmarked/
37 stars 25 forks source link

predict can fail when formula contains poly(), bs(), scale(), etc... #155

Closed rbchan closed 4 years ago

rbchan commented 4 years ago

Fix predict so that it uses information about transformations specified in formula. Might require expand.model.frame.

Thanks to Ariel Muldoon for reporting the issue:

https://mail.google.com/mail/u/0/?shva=1#inbox/FMfcgxwGCkmWNsjwPnhlDTCRVRHQLHQg

kenkellner commented 4 years ago

To expand on the scope of the problem, there are ~10 different predict functions that I suspect all have this issue and would all need to be updated separately. There's a lot of duplicated or very similar code among them though so there's probably an opportunity to simplify things.

aosmith16 commented 4 years ago

I'd be happy to do a pull request to put in my "fix" for this if you all think it'd be helpful. I can certainly understand that this may be a good juncture to work on the predict functions a little more, though, and I'd then be muddying the waters.

(I would have reported the issue here directly but I became uncertain about which unmarked repo was active so ended up on the forum :slightly_smiling_face:.)

rbchan commented 4 years ago

If you're up for adding this fix to all the predict methods, that would be fantastic. My sense is that it would be best if we could leave the getDesign methods alone, but perhaps that won't be possible. I guess the goal should be to mimic the behavior or predict.lm, predict.glm, etc... If we could do that, it should address some of the other predict-related issues on the list. How does that sound? Thanks again.

kenkellner commented 4 years ago

Agreed, it would be nice to consolidate the predict methods a bit more but that's a big job and it would be nice to just get this working.

I think the getDesign methods are generally only used by predict when your newdata is an unmarked frame, which typically only happens when you're predicting using the original dataset. I'm not sure if formula issues appear in that case or if it's only when it's really "new" data you're predicting for.

aosmith16 commented 4 years ago

I looked at the getDesign methods today and I agree it looks like those are used only when making predictions with the original dataset,(unmarked frame). From what I've seen so far the issue arises only when using new data. Given that, right now I'm focusing on the data.frame methods.