pbs-assess / sdmTMB

:earth_americas: An R package for spatial and spatiotemporal GLMMs with TMB
https://pbs-assess.github.io/sdmTMB/
187 stars 27 forks source link

Allow prediction on new data with missing time elements #130

Closed matteba closed 2 years ago

matteba commented 2 years ago

Hi, I'm trying to make a prediction for validation ( using 20% of the original dataset) from a fitted ( using 80% of the original dataset) GLM model with spatial-temporal components (year) with binomial distribution of the response variable.

Once I run the command

ValPA <- predict(mod, newdata = val.dataset.obs.std, type = "response")

I received this error message: Error in predict(): ! The time elements in newdata are not identical to those in the original dataset. For now, please predict on all time elements and filter out those you don't need after. Please let us know on the GitHub issues tracker if this is important to you.

I checked the range of the temporal components and it's the same. So I'm not sure wht's wrong here. Thanks for any help

seananderson commented 2 years ago

I assume the time range is the same but some of the time elements are missing from val.dataset.obs.std? You currently need all the time elements present. You can add some fake rows and remove them if you have to. It would be slicker if the predict function did that for you, which shouldn't be too hard. I'll adjust this issue title to that and count this as a vote to finally implement it!

matteba commented 2 years ago

Many thanks for the adivce. It worked indeed.

seananderson commented 2 years ago

This is now in the main branch: prediction on new data with the time argument specified can now have missing time slices.