It would be useful to have fitted_values() try to warn about data combinations (perhaps factors only - ignore numeric by factor interactions) that didn't exist in the original data. predict.gam() just doesn't even return an NA for such newdata which the causes an error in fitted_values() when we try to bind the output from predict() on to the data passed to the fitted_values().
factor_combos should be able to provide all the combos that exist in the data used to fit the model. Perhaps this can be solved by
select out all the factor terms from data
run distinct() on the above
run fitted_combos on object
compare the two objects, find combos in data that aren't in the data used to fit the model
get the indices of those rows from data
predict() but on for data with missing combos removed
assign output from predict to the rows of data that did have a combo used to fit the model, other rows are set to NA, so we avoid the error in the bind_cols() step.
It would be useful to have
fitted_values()
try to warn about data combinations (perhaps factors only - ignore numeric by factor interactions) that didn't exist in the original data.predict.gam()
just doesn't even return anNA
for suchnewdata
which the causes an error infitted_values()
when we try to bind the output frompredict()
on to thedata
passed to thefitted_values()
.factor_combos
should be able to provide all the combos that exist in the data used to fit the model. Perhaps this can be solved bydata
distinct()
on the abovefitted_combos
onobject
data
that aren't in the data used to fit the modeldata
predict()
but on for data with missing combos removedpredict
to the rows ofdata
that did have a combo used to fit the model, other rows are set toNA
, so we avoid the error in thebind_cols()
step.