Make an automated plot of the effect of a pair-level variable like phylogenetic distance
scatter_pairvar.Rd
Make an automated plot of the effect of a pair-level variable like phylogenetic distance
Usage
scatter_pairvar(
mod,
xvar,
xlabel,
color = "red",
orig.scale = TRUE,
ymin = 0,
ymax = 1,
ci_width = 0.95,
grid_size = 100,
thin = TRUE,
thin_to = 100
)
Arguments
- mod
An object of class "compnet" created by the buildcompnet() function.
- xvar
Character string for the name of the trait to be used. Must match the trait name in the input data used to build the model.
- xlabel
Optional character string to replace xvar when plotting.
- color
Color to use in plotting.
- orig.scale
Logical value indicating whether to back-transform trait data to the original scale (TRUE) or leave them with mean zero and unit variance (FALSE).
- ymin
Real number indicating the location of the bottom of the plot's y axis.
- ymax
Real number indicating the location of the top of the plot's y axis.
- ci_width
A real number (0,1) describing the desired widths of credible band. Defaults to 0.95.
- grid_size
A positive integer defining the number of discrete steps to use in approximating the shape of mean prediction curves and credible bands. Defaults to 100.
- thin
Logical value determining whether to use a random subsample of the full posterior sample.
- thin_to
Integer value determining how many random samples to draw from the full posterior sample if thin=TRUE.
Examples
data(ex_presabs)
data(ex_phylo)
# Quick demo run. Will prompt warnings.
# Run with default warmup and iter for good posterior sampling.
ex_compnet_phylo <- buildcompnet(presabs=ex_presabs, pairvars=ex_phylo, warmup=10, iter=20)
#>
#> SAMPLING FOR MODEL 'srm_binomial' NOW (CHAIN 1).
#> Chain 1:
#> Chain 1: Gradient evaluation took 8.6e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.86 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1:
#> Chain 1:
#> Chain 1: WARNING: No variance estimation is
#> Chain 1: performed for num_warmup < 20
#> Chain 1:
#> Chain 1: Iteration: 1 / 20 [ 5%] (Warmup)
#> Chain 1: Iteration: 2 / 20 [ 10%] (Warmup)
#> Chain 1: Iteration: 4 / 20 [ 20%] (Warmup)
#> Chain 1: Iteration: 6 / 20 [ 30%] (Warmup)
#> Chain 1: Iteration: 8 / 20 [ 40%] (Warmup)
#> Chain 1: Iteration: 10 / 20 [ 50%] (Warmup)
#> Chain 1: Iteration: 11 / 20 [ 55%] (Sampling)
#> Chain 1: Iteration: 12 / 20 [ 60%] (Sampling)
#> Chain 1: Iteration: 14 / 20 [ 70%] (Sampling)
#> Chain 1: Iteration: 16 / 20 [ 80%] (Sampling)
#> Chain 1: Iteration: 18 / 20 [ 90%] (Sampling)
#> Chain 1: Iteration: 20 / 20 [100%] (Sampling)
#> Chain 1:
#> Chain 1: Elapsed Time: 0.05 seconds (Warm-up)
#> Chain 1: 0.042 seconds (Sampling)
#> Chain 1: 0.092 seconds (Total)
#> Chain 1:
#> Warning: There were 1 chains where the estimated Bayesian Fraction of Missing Information was low. See
#> https://mc-stan.org/misc/warnings.html#bfmi-low
#> Warning: Examine the pairs() plot to diagnose sampling problems
#> Warning: The largest R-hat is 2.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
#> [1] "compnet uses Stan under the hood. You may see warnings from Stan alongside, this message. To deal with any warnings Stan might issue, Please see the links provided in Stan's output, as well as the compnet website:https://kyle-rosenblad.github.io/compnet/"
scatter_pairvar(ex_compnet_phylo, xvar="phylodist", ymax=0.25)
#> Warning: Removed 14 rows containing missing values or values outside the scale range
#> (`geom_point()`).