TheoreticalEcology / s-jSDM

Scalable joint species distribution modeling
https://cran.r-project.org/web/packages/sjSDM/index.html
GNU General Public License v3.0
68 stars 14 forks source link

Different R2 produced for Model and Anova #113

Closed AndrewCSlater closed 1 year ago

AndrewCSlater commented 1 year ago

Hi there, when analysing the R2 of a model I get 2 different results depending on the method I use.

mod = sjSDM(Y = as.matrix(y), env = as.matrix(scale(eo)), spatial = linear(scale(XY), ~0+X1+X2:X1:X2+I(X1^2)+I(X2^2)), se = T, iter = 200, device = "gpu")

a = Rsquared(mod, method = "McFadden") mAn = anova(mod, device = "gpu") mean(mAn$species$R2_McFadden$Full)

a [1] 0.2768665 mean(mAn$species$R2_McFadden$Full) [1] 0.3457764

Are they providing information on different things, or could you recommend which one is best to use in reporting?

Many thanks for your help! Andrew

MaximilianPi commented 1 year ago

Hi @AndrewCSlater,

I found a small bug in the Rsquared function (when calculating the null model) that resulted in an underestimation of Rsquared. You can get the updated Rsquared function by installing the development version or simply using the anova workaround.

Note: Due to the Monte Carlo approximation, the Rsquared is not exact and varies slightly. So if you need an exact Rsquared (e.g. for parameter tuning), you should repeat the Rsquared calculation a few times and use the average.

Thanks for the report, I will add the last statement to the anova and Rsquared function.