R/coef.trophicSDMfit.R
coef.trophicSDMfit.Rd
Gets regression coefficients (eventually standardised) of a fitted trophicSDM. p-values or credible intervals are returned when available.
# S3 method for trophicSDMfit
coef(object, standardise = FALSE, level = 0.95, ...)
A trophicSDMfit object obtained with trophicSDM()
Whether to standardise regression coefficients. Default to FALSE. If TRUE, coefficients are standardised using the latent variable standardisation (see Grace et al. 2018) for more details.
The confidence level of credible intervals, only available for stan_glm method. Default to 0.95.
additional arguments
A list containing, for each species, the inferred coefficients (with credible intervals or p-values when available).
Grace, J. B., Johnson, D. J., Lefcheck, J. S., and Byrnes, J. E. K.. 2018. Quantifying relative importance: computing standardized effects in models with binary outcomes. Ecosphere 9(6):e02283.
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: 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.19, 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: Markov chains did not converge! Do not analyze results!
#> 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.05, 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
# unstandardised regression coefficients
coef(m)
#> $Y1
#> mean 2.5% 97.5%
#> (Intercept) 0.3529661 0.01579191 0.6467421
#> X_1 -1.3679897 -1.72539504 -0.8887395
#> X_2 1.6707387 1.34114202 2.1381284
#>
#> $Y2
#> mean 2.5% 97.5%
#> (Intercept) -0.2827361 -0.6163644 0.11451739
#> X_1 2.5775447 2.0368016 3.21621887
#> X_2 -0.4891153 -1.0239071 -0.02560512
#>
#> $Y3
#> mean 2.5% 97.5%
#> (Intercept) -0.6083904 -0.9641849 -0.3208077
#> X_1 1.7748459 1.3238689 2.3726269
#> X_2 1.2617083 0.8514722 1.7031377
#>
#> $Y4
#> mean 2.5% 97.5%
#> (Intercept) 0.79171461 0.3789801 1.11144521
#> X_1 -1.08093552 -1.5820757 -0.72279580
#> X_2 -0.04514398 -0.5167490 0.44050544
#> Y3 -0.30588533 -0.5804229 -0.06523017
#>
#> $Y5
#> mean 2.5% 97.5%
#> (Intercept) -0.6268791 -1.0736333 -0.1860750
#> X_1 1.4398702 0.9104161 1.9245040
#> X_2 -2.3083002 -2.8004448 -1.7582396
#> Y1 1.9289190 1.6326410 2.2629579
#> Y2 -0.1012753 -0.3532097 0.2888476
#> Y3 -0.9764066 -1.2675562 -0.7100177
#>
#> $Y6
#> mean 2.5% 97.5%
#> (Intercept) 1.2666776 0.8663053 1.73382277
#> X_1 -0.2584283 -0.6394258 0.18037092
#> X_2 0.6187240 0.1028627 1.11342894
#> Y3 -0.9810084 -1.2707563 -0.64656380
#> Y5 -0.3851025 -0.6980905 -0.07357911
#>
#standardised regression coefficients with 90% credible intervals
coef(m, standardised = TRUE, level = 0.9)
#> $Y1
#> mean 5% 95%
#> (Intercept) 0.3529661 0.1159906 0.6358667
#> X_1 -1.3679897 -1.6556678 -0.9972050
#> X_2 1.6707387 1.3567148 2.0871309
#>
#> $Y2
#> mean 5% 95%
#> (Intercept) -0.2827361 -0.5895620 0.08521338
#> X_1 2.5775447 2.1260499 3.08969766
#> X_2 -0.4891153 -0.9477263 -0.08787474
#>
#> $Y3
#> mean 5% 95%
#> (Intercept) -0.6083904 -0.9159226 -0.3498503
#> X_1 1.7748459 1.4182869 2.2590881
#> X_2 1.2617083 0.9024893 1.6684875
#>
#> $Y4
#> mean 5% 95%
#> (Intercept) 0.79171461 0.4643277 1.04795538
#> X_1 -1.08093552 -1.4494368 -0.75154127
#> X_2 -0.04514398 -0.4386190 0.35192091
#> Y3 -0.30588533 -0.5503995 -0.08786903
#>
#> $Y5
#> mean 5% 95%
#> (Intercept) -0.6268791 -1.0511523 -0.3014526
#> X_1 1.4398702 1.0362738 1.8888343
#> X_2 -2.3083002 -2.6882248 -1.8756191
#> Y1 1.9289190 1.6744643 2.1928542
#> Y2 -0.1012753 -0.3290987 0.1711184
#> Y3 -0.9764066 -1.2273647 -0.7191873
#>
#> $Y6
#> mean 5% 95%
#> (Intercept) 1.2666776 0.8886837 1.6984012
#> X_1 -0.2584283 -0.6097637 0.1369216
#> X_2 0.6187240 0.1599976 1.0321477
#> Y3 -0.9810084 -1.2233617 -0.6824965
#> Y5 -0.3851025 -0.6478072 -0.1343373
#>
# Run the same model using glm as fitting method
m = trophicSDM(Y, X, G, env.formula,
family = binomial(link = "logit"), penal = NULL,
mode = "prey", method = "glm")
# Now we have p-values instead of credible intervals
coef(m)
#> $Y1
#> estimate p_val
#> (Intercept) 0.3476586 5.372927e-02
#> X_1 -1.3313797 2.333667e-08
#> X_2 1.7163540 1.908865e-12
#>
#> $Y2
#> estimate p_val
#> (Intercept) -0.2642011 1.540839e-01
#> X_1 2.5883318 2.224192e-23
#> X_2 -0.5073633 4.338125e-02
#>
#> $Y3
#> estimate p_val
#> (Intercept) -0.6018391 1.487210e-03
#> X_1 1.7483980 7.089826e-12
#> X_2 1.3163439 3.311450e-07
#>
#> $Y4
#> estimate p_val
#> (Intercept) 0.78889471 2.155371e-05
#> X_1 -1.10206644 1.366519e-06
#> X_2 -0.08188654 7.192093e-01
#> Y3 -0.30131937 3.913908e-02
#>
#> $Y5
#> estimate p_val
#> (Intercept) -0.6189468 8.464968e-03
#> X_1 1.4694263 1.907815e-07
#> X_2 -2.2685583 8.659117e-16
#> Y1 1.9375122 4.590864e-27
#> Y2 -0.1034504 5.281146e-01
#> Y3 -0.9758157 2.959546e-09
#>
#> $Y6
#> estimate p_val
#> (Intercept) 1.3140626 3.056395e-09
#> X_1 -0.2164506 3.660621e-01
#> X_2 0.5733713 1.878167e-02
#> Y3 -0.9788779 7.812723e-09
#> Y5 -0.3864325 7.464448e-03
#>
# Notice that unstandardised coefficients are always accessible
# in the fitted model:
m$coef
#> NULL