Closed ASeatonSpatial closed 2 years ago
For bym_eff_latent
, one should get the 2n length vector, as it's explicitly asking for the entire latent vector. For just the plain effect vector, it should give a vector of length n (the second half is hidden). With bym_eff_eval
, one can choose to access arbitrary parts of the latent field, by indexing into either the first or second part, or both. The predict call that generates length 2 does seem to be a bug.
The plain bym_eff
is meant to act like it does in the estimation, giving a vector of length n, which is the effect "visible" in INLA.
Good to know bym_eff
would just return a vector of length n.
So the desired behaviour would be nrow(pred) = 56
in this example?
# try passing data to predict call
pred = predict(fit,
data = lip_data,
formula = ~ exp(Intercept + bym_eff))
nrow(lip_data)
#> [1] 56
nrow(pred)
#> [1] 2
And nrow(pred) = 10
in this one?
# try a data frame
pred_df = data.frame(county.id = 1:10)
pred = predict(fit,
data = pred_df,
formula = ~ exp(Intercept + bym_eff))
nrow(pred_df)
#> [1] 10
nrow(pred)
#> [1] 2
But nrow(pred) = 2
in both.
The problem is that inla_f=TRUE
doesn't get set/propagated to ibm_amatrix.bru_mapper_collect
when using generate
, so it expects list input instead of just the first vector. A workaround is to use _eval with a list in the predict call:
pred = predict(fit,
data = lip_data,
formula = ~ exp(Intercept + bym_eff_eval(list(county.id))))
nrow(pred)
#> [1] 56
pred_df = data.frame(county.id = 1:10)
pred = predict(fit,
data = pred_df,
formula = ~ exp(Intercept + bym_eff_eval(list(county.id))))
nrow(pred)
#> [1] 10
I need to think about whether the inla_f logic is such that it should be activated in generate calls; it should probably be renamed if that's the case, or a separate mechanism added to keep the logic predictable.
Use bym_eff_eval(list(v=...))
to access the hidden component separately.
Bug resolved. But I see in the bym and bym2 documentation that the naming of the latent components doesn't match the current internal mapper names, (u,v), as the inla documentation uses (v+u,u). The inlabru mapper names should be changed to match the inla documentation, e.g. (vu,u)?
I noticed a potential bug when predicting from a "bym" model. See a reprex below which requires the
SpatialEpi
package that has some areal unit data.If predicting without supplying new data, the predictions seem sensible. However, if passing a data object to the
predict()
function, it doesn't seem to return a prediction dataframe with sensible dimensions. I wonder if something is maybe breaking with the indexing since a bym model is a bit different, the effect is of length 2n, where n is number of nodes in the graph. If predicting without a data object it's possible to just subset this as required as I do below.Created on 2022-01-12 by the reprex package (v2.0.1)
The desired behaviour I guess would be for
predict(fit, data = pred_obj, ~ some_function(bym_eff))
to return an object with 2 timesnrow(pred_obj)
rows. This would applysome_function()
to both theu + v
andv
parts of thebym_eff
parameters.