gg_varpart_data: Prepare data to plot variance components for a boral model

Description Usage Arguments Details Value See Also Examples

View source: R/variance_plots.R

Description

This function calls the boral function calc.varpart to estimate the proportion of variance accounted for by explanatory variables, latent variables and any row effects. It returns the results as a data frame suitable for plotting with ggplot. It is used by gg_varpart but you can also use it directly if you are constructing plots 'manually'.

Usage

1

Arguments

model

A boral model fitted with one or more latent variables.

Details

This function requires that you fitted the model with explanatory variables and specified save.model = TRUE when calling boral so that MCMC samples were stored.

Value

A data frame to use with ggplot that has the following columns:

varpart

Variance component: one of X (explanatory variables), lv (latent variables), row (row effects).

value

Estimated proportion of variance.

label

Name of the response (e.g. species).

See Also

calc.varpart gg_varpart

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#' 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)

dat.varpart <- gg_varpart_data(spiderfit_nb)
head(dat.varpart)

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