gg_varpart: Plot variance components as estimated by calc.varpart

Description Usage Arguments Details Value See Also Examples

View source: R/variance_plots.R

Description

Plots estimates of the proportion of variance in each response accounted for by explanatory variables, latent variables and any row effects, as estimated by the boral function calc.varpart.

Usage

1
gg_varpart(model, as.percent = FALSE, label.means = FALSE)

Arguments

model

A boral model fitted with one or more latent variables.

as.percent

If TRUE, format variance axis tick marks and label as percentages. If FALSE (default), format as proportions.

label.means

If TRUE, append the mean value for each variance component to the legend label. Default is FALSE.

Details

Proceed with caution! Read the caveats and warnings detailed in the help page for calc.varpart when interpreting the plot drawn by this function. Also keep in mind that the results can be influenced by data artefacts, e.g. when modelling species occurrence data with a binomial model, the estimate of variance explained by predictor variables will tend to be higher for species with few presences than for more common species.

Value

A ggplot object.

See Also

calc.varpart gg_varpart_data

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(boral)
library(ggboral)

data(spider, package = "mvabund")
y <- spider$abun
X <- scale(spider$x)

# Warning - these settings are only to make the example run quickly.
# Don't use them for a real analysis!
example.control <- list(n.burnin = 10, n.iteration = 100, n.thin = 1)

# Note that we specify save.model = TRUE when calling boral
#
spiderfit_nb <- boral(y, X,
                      family = "negative.binomial",
                      lv.control = list(num.lv = 2),
                      row.eff = "fixed",
                      mcmc.control = example.control,
                      save.model = TRUE)

gg_varpart(spiderfit_nb,
           as.percent = TRUE,
           label.means = TRUE) + theme_bw()

mbedward/ggboral documentation built on June 27, 2020, 10:15 a.m.