Gets regression coefficients (eventually standardised) of a local model, i.e. a SDMfit object. p-values or credible intervals are returned when available.

# S3 method for SDMfit
coef(object, standardise = FALSE, level = 0.95, ...)

Arguments

object

A SDMfit object, typically obtained with trophicSDM() and available in the field $model of a trophicSDMfit object

standardise

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.

level

The confidence level of credible intervals, only available for stan_glm method. Default to 0.95.

...

additional arguments

Value

A table containing the inferred coefficients (with credible intervals or p-values when available).

References

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.

Author

Giovanni Poggiato

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
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: 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.08, 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.11, 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
# unstandardised regression coefficients
coef(m$model$Y5)
#>                   mean       2.5%      97.5%
#> (Intercept) -0.6743124 -1.0562452 -0.2737307
#> X_1          1.5182934  1.0874567  2.1320034
#> X_2         -2.2938187 -2.8007750 -1.7227278
#> Y1           1.9517173  1.5950009  2.2873426
#> Y2          -0.1098928 -0.3848388  0.2257214
#> Y3          -0.9786615 -1.3116767 -0.6278177
#standardised regression coefficients with 90% credible intervals
coef(m$model$Y5, standardised = TRUE, level = 0.9)
#>                   mean         5%        95%
#> (Intercept) -0.6743124 -1.0129102 -0.3116744
#> X_1          1.5182934  1.1547903  2.0125129
#> X_2         -2.2938187 -2.7686953 -1.7931208
#> Y1           1.9517173  1.7109364  2.2393996
#> Y2          -0.1098928 -0.3302223  0.1515621
#> Y3          -0.9786615 -1.2808845 -0.6795918
# Run the same model using glm as fitting method
# (set iter = 1000 to obtain reliable results)
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$model$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

# Notice that unstandardised coefficients are always accessible
# in the fitted model:
m$model$Y5$coef
#>               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