Computes predicted values of the fundamental niches of species from the fitted trophicSDMfit model at environmental conditions specified by Xnew. Predictions are obtained by setting preys to present when mode = "prey" or setting predators to absent when mode = "predator".

predictFundamental(
  tSDM,
  Xnew = NULL,
  pred_samples = NULL,
  verbose = FALSE,
  fullPost = TRUE
)

Arguments

tSDM

A trophicSDMfit object obtained with trophicSDM()

Xnew

a matrix specifying the environmental covariates for the predictions to be made. If NULL (default), predictions are done on the training dataset (e.g. by setting Xnew = tSDM$data$X).

pred_samples

Number of samples to draw from species posterior predictive distribution when method = "stan_glm". If NULL, set by the default to the number of iterations/10.

verbose

Whether to print advances of the algorithm.

fullPost

Optional parameter for stan_glm only. Whether to give back the full posterior predictive distribution (default, fullPost = TRUE) or just the posterior mean, and 2.5% and 97.5% quantiles.

Value

A list containing for each species the predicted value at each sites. If method = "stan_glm", then each element of the list is a sites x pred_samples matrix containing the posterior predictive distribution of the species at each sites.

Author

Giovanni Poggiato and Jérémy Andréoletti

Examples

data(Y, X, G)
# define abiotic part of the model
env.formula = "~ X_1 + X_2"
# Run the model with bottom-up control using stan_glm as fitting method and no penalisation
# (set iter = 1000 to obtain reliable results)
m = trophicSDM(Y, X, G, env.formula, iter = 100,
               family = binomial(link = "logit"), penal = NULL, 
               mode = "prey", method = "stan_glm")
#> Warning: The largest R-hat is 1.17, indicating chains have not mixed.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#r-hat
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
#> Warning: The largest R-hat is 1.06, indicating chains have not mixed.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#r-hat
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
#> Warning: The largest R-hat is 1.06, indicating chains have not mixed.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#r-hat
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
#> Warning: The largest R-hat is 1.06, indicating chains have not mixed.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#r-hat
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
# Obtain 100 draws from the posterior predictive distribution of species fundamental niche
# (pred_samples = 50)
# Since we don't specify Xnew, the function sets Xnew = X by default
Ypred = predictFundamental(m, fullPost = TRUE, pred_samples = 50)
# We can ask the function to only give back posterior mean and 95% credible intervals with
# fullPost = FALSE
# \donttest{
Ypred = predictFundamental(m, fullPost = FALSE, pred_samples = 50)
# }
#' We can now evaluate species probabilities of presence for the enviromental
# conditions c(0.5, 0.5)
predictFundamental(m, Xnew = data.frame(X_1 = 0.5, X_2 = 0.5), pred_samples = 50)
#> $Y1
#>    iterations
#>          [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
#>   1 0.6124817 0.6179183 0.6524006 0.6224469 0.6300747 0.6229084 0.6288763
#>    iterations
#>          [,8]      [,9]     [,10]    [,11]     [,12]     [,13]     [,14]
#>   1 0.6128087 0.6071477 0.6455582 0.615625 0.6556323 0.6298193 0.6275542
#>    iterations
#>       [,15]    [,16]    [,17]     [,18]     [,19]     [,20]     [,21]     [,22]
#>   1 0.63883 0.593448 0.632087 0.6412128 0.6030003 0.6227605 0.6348412 0.6082565
#>    iterations
#>         [,23]    [,24]     [,25]     [,26]     [,27]     [,28]     [,29]
#>   1 0.6254151 0.626278 0.6409445 0.6267746 0.6262983 0.6247518 0.5907619
#>    iterations
#>         [,30]     [,31]     [,32]     [,33]    [,34]     [,35]     [,36]
#>   1 0.6623712 0.6246259 0.6146396 0.6192177 0.643651 0.6345749 0.6354986
#>    iterations
#>         [,37]    [,38]     [,39]     [,40]     [,41]     [,42]     [,43]
#>   1 0.6247692 0.639787 0.6171308 0.5932608 0.6301597 0.6016737 0.6439179
#>    iterations
#>        [,44]     [,45]     [,46]     [,47]     [,48]     [,49]     [,50]
#>   1 0.629034 0.6404716 0.6413021 0.6018373 0.6300766 0.6239914 0.6390797
#> 
#> $Y2
#>    iterations
#>          [,1]      [,2]      [,3]      [,4]      [,5]      [,6]     [,7]
#>   1 0.6904423 0.6747701 0.7056436 0.6658292 0.6813057 0.6952902 0.690764
#>    iterations
#>          [,8]      [,9]    [,10]    [,11]     [,12]     [,13]     [,14]
#>   1 0.6755677 0.6955576 0.705637 0.682489 0.6822279 0.6940564 0.6711719
#>    iterations
#>         [,15]     [,16]     [,17]     [,18]    [,19]     [,20]     [,21]
#>   1 0.7019567 0.6760611 0.6979544 0.6894251 0.690844 0.7002313 0.6867054
#>    iterations
#>         [,22]     [,23]     [,24]     [,25]    [,26]     [,27]     [,28]
#>   1 0.6959071 0.6861715 0.6717696 0.6823555 0.688655 0.6894328 0.6962387
#>    iterations
#>         [,29]     [,30]     [,31]     [,32]     [,33]     [,34]     [,35]
#>   1 0.6763192 0.7068563 0.7076162 0.6633549 0.6859518 0.6747526 0.6947909
#>    iterations
#>         [,36]     [,37]     [,38]     [,39]     [,40]    [,41]     [,42]
#>   1 0.7004592 0.6732316 0.6799936 0.6797322 0.6819624 0.713136 0.7082635
#>    iterations
#>         [,43]     [,44]     [,45]     [,46]     [,47]     [,48]     [,49]
#>   1 0.6748847 0.6774351 0.6867226 0.6806222 0.6897378 0.6879747 0.6950011
#>    iterations
#>         [,50]
#>   1 0.6857084
#> 
#> $Y3
#>    iterations
#>          [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
#>   1 0.7257859 0.7300933 0.7415667 0.7221033 0.7398961 0.7341912 0.7280833
#>    iterations
#>          [,8]      [,9]     [,10]     [,11]     [,12]    [,13]     [,14]
#>   1 0.7096121 0.7199811 0.7238427 0.7197432 0.7379624 0.745032 0.7324466
#>    iterations
#>         [,15]     [,16]     [,17]     [,18]     [,19]     [,20]     [,21]
#>   1 0.7219836 0.7358375 0.7121071 0.7135458 0.7045353 0.7173603 0.7155348
#>    iterations
#>         [,22]     [,23]     [,24]     [,25]     [,26]     [,27]     [,28]
#>   1 0.7410211 0.7488973 0.7263796 0.7138012 0.7551951 0.7382021 0.6939916
#>    iterations
#>         [,29]     [,30]     [,31]     [,32]     [,33]     [,34]     [,35]
#>   1 0.7217804 0.7215334 0.7359388 0.7011916 0.6977891 0.7237176 0.7457306
#>    iterations
#>         [,36]     [,37]     [,38]     [,39]     [,40]     [,41]     [,42]
#>   1 0.7207358 0.6869878 0.7285606 0.7230974 0.7012647 0.7335963 0.7332553
#>    iterations
#>         [,43]     [,44]     [,45]     [,46]     [,47]     [,48]     [,49]
#>   1 0.7363702 0.7017994 0.7057592 0.7544917 0.7553325 0.7170781 0.7379624
#>    iterations
#>         [,50]
#>   1 0.6995482
#> 
#> $Y4
#>    iterations
#>          [,1]      [,2]      [,3]     [,4]      [,5]      [,6]      [,7]
#>   1 0.4860862 0.4603256 0.4773636 0.453428 0.4770747 0.4694145 0.4589764
#>    iterations
#>         [,8]      [,9]     [,10]     [,11]     [,12]     [,13]    [,14]
#>   1 0.494836 0.4579999 0.4676701 0.4685051 0.5003335 0.4601018 0.505574
#>    iterations
#>         [,15]     [,16]     [,17]     [,18]    [,19]    [,20]     [,21]
#>   1 0.4904049 0.5009787 0.4791662 0.4414678 0.470827 0.469819 0.4982235
#>    iterations
#>         [,22]     [,23]     [,24]     [,25]     [,26]     [,27]    [,28]
#>   1 0.4738068 0.4616056 0.4688872 0.4854064 0.4546089 0.4828494 0.449985
#>    iterations
#>         [,29]     [,30]     [,31]    [,32]     [,33]     [,34]     [,35]
#>   1 0.4604674 0.4872609 0.4787465 0.485448 0.4797251 0.4859057 0.4840628
#>    iterations
#>         [,36]     [,37]     [,38]     [,39]     [,40]     [,41]     [,42]
#>   1 0.4576553 0.4918255 0.4531695 0.4546936 0.4828653 0.5253702 0.4864205
#>    iterations
#>         [,43]     [,44]     [,45]     [,46]     [,47]     [,48]    [,49]
#>   1 0.4993938 0.4487432 0.5079777 0.4716517 0.4608389 0.4754071 0.432501
#>    iterations
#>         [,50]
#>   1 0.4524876
#> 
#> $Y5
#>    iterations
#>          [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
#>   1 0.4538472 0.4975063 0.4670712 0.4680565 0.4722507 0.4660335 0.4710417
#>    iterations
#>          [,8]      [,9]     [,10]     [,11]     [,12]     [,13]     [,14]
#>   1 0.4775214 0.4879259 0.5014025 0.4822701 0.4862197 0.4336525 0.4588128
#>    iterations
#>         [,15]     [,16]     [,17]     [,18]     [,19]     [,20]     [,21]
#>   1 0.4643398 0.4553224 0.4626736 0.4268176 0.4917586 0.4437301 0.4613329
#>    iterations
#>         [,22]     [,23]     [,24]     [,25]     [,26]     [,27]     [,28]
#>   1 0.4442014 0.4562191 0.4870558 0.4804418 0.4434844 0.4354242 0.4809237
#>    iterations
#>        [,29]     [,30]     [,31]    [,32]     [,33]     [,34]     [,35]
#>   1 0.470444 0.5204508 0.4746642 0.484292 0.4716033 0.5042127 0.4044775
#>    iterations
#>         [,36]     [,37]     [,38]     [,39]     [,40]     [,41]     [,42]
#>   1 0.4685608 0.5149217 0.4631017 0.4736722 0.4747267 0.4778638 0.4839461
#>    iterations
#>         [,43]     [,44]     [,45]     [,46]     [,47]     [,48]    [,49]
#>   1 0.4391905 0.4809237 0.4260523 0.4856687 0.4498162 0.4591472 0.469775
#>    iterations
#>         [,50]
#>   1 0.4034324
#> 
#> $Y6
#>    iterations
#>          [,1]      [,2]      [,3]      [,4]      [,5]      [,6]     [,7]
#>   1 0.5327089 0.5740801 0.5048637 0.5514248 0.4892809 0.5108339 0.511844
#>    iterations
#>         [,8]      [,9]     [,10]     [,11]     [,12]    [,13]     [,14]
#>   1 0.497277 0.5452515 0.5364561 0.5341255 0.5385689 0.602389 0.5919728
#>    iterations
#>         [,15]     [,16]     [,17]     [,18]     [,19]     [,20]     [,21]
#>   1 0.5188026 0.5688529 0.4797685 0.4804775 0.5452949 0.5295935 0.5625677
#>    iterations
#>         [,22]     [,23]     [,24]     [,25]     [,26]     [,27]     [,28]
#>   1 0.5212735 0.5436387 0.5769887 0.4809899 0.5638132 0.4839434 0.5160762
#>    iterations
#>         [,29]     [,30]     [,31]     [,32]     [,33]     [,34]    [,35]
#>   1 0.5393719 0.5671159 0.5428952 0.5279149 0.5764241 0.5065539 0.502558
#>    iterations
#>        [,36]     [,37]     [,38]     [,39]     [,40]     [,41]     [,42]
#>   1 0.518754 0.5446422 0.5428973 0.5268423 0.5350227 0.5205084 0.5290753
#>    iterations
#>        [,43]     [,44]     [,45]     [,46]     [,47]     [,48]     [,49]
#>   1 0.441046 0.5381657 0.5260473 0.5782424 0.5457862 0.4976236 0.5240077
#>    iterations
#>         [,50]
#>   1 0.5330541
#> 

# If we fit the model using in a frequentist  way (e.g. glm)
m = trophicSDM(Y, X, G, env.formula, 
               family = binomial(link = "logit"), penal = NULL, 
               mode = "prey", method = "glm")
# We are obliged to set pred_samples = 1 
# (this is done by default if pred_samples is not provided)
# In the frequentist case, fullPost is useless.
Ypred = predictFundamental(m, pred_samples = 1)