inlabru-org / inlabru

inlabru
https://inlabru-org.github.io/inlabru/
76 stars 21 forks source link

Relative contribution of covariates. R2, fraction of variance #68

Open htansci opened 4 years ago

htansci commented 4 years ago

Hello inlabru,

Is there an easy way to access a value of R2 from an lgcp() model fit with inlabru?

I am trying to assess the relative contribution of multiple covariates and was planning to do this by assessing changes in R2 after dropping covariates.

Also curious if there are more suitable approaches using this kind of model.

Cheers,

Harri

finnlindgren commented 4 years ago

R2 squared isn't defined for continuous domain LGCP models, so you'll need to define a different measure to use for this. You could perhaps consider assessing an R2-like measure based on discretised point counts? We have a brief discussion/example of assessing the contributions of spatial covariates and spatial random fields in the context of point process data in this paper: https://projecteuclid.org/euclid.aoas/1514430286 The approach used there can be computed with the help of calls to predict for models with and without the covariate one wants to assess the contribution of.

htansci commented 4 years ago

Ideally, the measure I would use would be somewhat analogous to the output of various SDM methods, perhaps something like a mean % contribution of each covariate to the linear predictor.

What I've come up with so far using predict() feels simple but I think it is something like what I want?

lp.pxl <- predict(fit.model, pxl, ~ spat + covar1 + covar2 + covar3, n.samples = 200) lp.pxl.spat <- predict(fit.model, pxl, ~ spat, n.samples = 200) lp.pxl.cov1 <- predict(fit.model, pxl, ~ covar1, n.samples = 200) lp.pxl.cov2 <- predict(fit.model, pxl, ~ covar2, n.samples = 200) lp.pxl.cov3 <- predict(fit.model, pxl, ~ covar3, n.samples = 200)

lp.pxl.spat$squared <-lp.pxl.cov3$mean^2 lp.pxl.cov1$squared <- lp.pxl.cov3$mean^2 lp.pxl.cov2$squared <- lp.pxl.cov3$mean^2 lp.pxl.cov3$squared <- lp.pxl.cov3$mean^2

lp.pxl$sumsquare <- lp.pxl.spat$squared + lp.pxl.cov1$squared + lp.pxl.cov2$squared + lp.pxl.cov3$squared

lp.pxl.spat$squared.frac.sumsq <- lp.pxl.spat$squared / lp.pxl$sumsquare lp.pxl.cov1$squared.frac.sumsq <- lp.pxl.cov1$squared / lp.pxl$sumsquare lp.pxl.cov2$squared.frac.sumsq <- lp.pxl.cov2$squared / lp.pxl$sumsquare lp.pxl.cov3$squared.frac.sumsq <- lp.pxl.cov3$squared / lp.pxl$sumsquare

mean(lp.pxl.spat$squared.frac.sumsq) mean(lp.pxl.cov1$squared.frac.sumsq) mean(lp.pxl.cov2$squared.frac.sumsq) mean(lp.pxl.cov3$squared.frac.sumsq)

Cheers,

Harri