TheoreticalEcology / s-jSDM

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

Is there a way to assess the significance (p-value?) of pairwise relationships in species associations? #133

Closed CaiWang0503 closed 8 months ago

CaiWang0503 commented 8 months ago

Although the species associations are residuals in this case, but if I want to infer species interactions between species based on the strength of the pairwise relationship, how can I tell the relationship is strong and significant?

MaximilianPi commented 8 months ago

Hi @CaiWang0503,

you can approximate standard errors with bootstrapping:

library(sjSDM)
SS = diag(1.0, 5)
SS[1,2] = SS[2,1] = 0.9
sim = simulate_SDM(correlation = SS,species = 5L, sites = 500L)

m = sjSDM(sim$response, sim$env_weights, device = 0)
S = getCor(m)

res= 
lapply(1:30, function(i) {
  ind = sample.int(500, 500, replace = TRUE)
  m = sjSDM(sim$response[ind,], sim$env_weights[ind,], device = 0)
  S = getCor(m)
  return(S)
})
res_arr = abind::abind(res, along = 0)

mean = apply(res_arr, 2:3, mean) # mean effects
se = apply(res_arr, 2:3, sd) # standarderrors

Afterwards, you can calculate z-values and p-values:

# p-values
pnorm(abs(mean/se), lower.tail = FALSE)*2
CaiWang0503 commented 8 months ago

thank you, Max.