Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predict for communityPGLMM #35

Open
vmikk opened this issue Apr 10, 2019 · 0 comments
Open

Predict for communityPGLMM #35

vmikk opened this issue Apr 10, 2019 · 0 comments

Comments

@vmikk
Copy link
Contributor

vmikk commented Apr 10, 2019

Dear PGLMM gurus,

Unfortunately, currently there is no predict(object, newdata = ...) method for communityPGLMM class, and it is only possible to extract the fitted values with fitted.communityPGLMM.

In particular, I'm very interested in how to predict for the zero-inflated binomial model fitted with INLA:

modd <- phyr::pglmm(
    cbind(PositiveSamples, TotalSamples - PositiveSamples) ~ X * F + (1|sp__) + (1|site) + (1|sp__@site),
    family = "zeroinflated.binomial",
    data = dat,
    tree = tree,
    bayes = TRUE
    )

where X is a continuous predictor and F is a factor with 2 levels.
In order to inspect the model behavior, I would like to plot the effect of X on the proportion of PositiveSamples for each level of F. This is very similar to the effect displays from effects package or marginal_effects from brms:

N <- 200
dummydata <- rbind(
  data.frame(
    PositiveSamples = sample(x = 0:5, size = N/2, replace = T),
    TotalSamples = 12,
    X = rnorm(n = N/2, mean = 10, sd = 1),
    F = "F1"
  ),
  data.frame(
    PositiveSamples = sample(x = 6:10, size = N/2, replace = T),
    TotalSamples = 12,
    X = rnorm(n = N/2, mean = 10, sd = 1),
    F = "F2"
  ))

mod <- glm(
  cbind(PositiveSamples, TotalSamples - PositiveSamples) ~ X * F,
  data = dummydata,
  family = binomial)

plot(effects::allEffects(mod))

There is also no built-in predict method in INLA which would allow predicting for new data, e.g., in the same way as for lm or glm with predict(mod, newdata = expand.grid(X = 1:3, F = c("F1", "F2")).
Therefore, it is not easy to construct such plots.

For prediction, I also tried to append additional data cases with missing (NA) response to the model input data, similar to the INLA tutorial, and call communityPGLMM.bayes directly:

communityPGLMM.bayes(
  formula = modd$formula,
  data = dat,            # main data + data for prediction
  family = "zeroinflated.binomial",
  sp = modd$sp,
  site = modd$site,
  random.effects = modd$random.effects,
  s2.init = modd$s2.init,
  B.init = modd$B.init,
  marginal.summ = modd$marginal.summ,
  verbose = TRUE,
  calc.DIC = FALSE,
  prior = "inla.default", prior_alpha = 1, prior_mu = 0.1
  )

but I've got an error "variable lengths differ (found for 'inla_effects[[1]]') ".
Running phyr::pglmm on the data with NAs or inlabru:::predict.inla(modd$inla.model) also doesn't work.

Maybe you know how to predict using the result of communityPGLMM class?

I would be grateful for any advice you could provide.
With best regards,
Vladimir Mikryukov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant