rbchan / unmarked

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

Warnings when predicting when factors are present in the siteCovs but not used in the model formula #168

Closed kenkellner closed 4 years ago

kenkellner commented 4 years ago

After the recent changes to predict to handle various complex formulas and mismatched factors, predict checks the original covariates for valid factor levels:

https://github.com/rbchan/unmarked/blob/f3708507fe552c7e040d1edbfa47771dc3126dcc/R/unmarkedFit.R#L1629

However if the siteCovs contain factors that aren't then used in the model for which prediction is being done, these xlevs are being checked against non-existent columns in the newdata:

https://github.com/rbchan/unmarked/blob/f3708507fe552c7e040d1edbfa47771dc3126dcc/R/unmarkedFit.R#L1632

This results in a warning but the predictions are still generated correctly.

I dealt with this (I think) in the predict methods for occuMulti and occuMS by removing elements from xlevs that were not in the newdata before building the model frame:

https://github.com/rbchan/unmarked/blob/f3708507fe552c7e040d1edbfa47771dc3126dcc/R/getDesign.R#L629