
Plot histogram of STRAPP test statistics to assess results
Source:R/plot_histogram_STRAPP_test_for_focal_time.R
plot_histogram_STRAPP_test_for_focal_time.RdPlot an histogram of the distribution of the test statistics
obtained from a STRAPP test carried out for a unique focal_time.
(See compute_STRAPP_test_for_focal_time() and
run_deepSTRAPP_for_focal_time()).
Returns a single histogram for overall tests.
If plot_posthoc_tests = TRUE, it will return a faceted plot with an histogram per post hoc tests.
If a PDF file path is provided in PDF_file_path, the plot will be saved directly in a PDF file.
Usage
plot_histogram_STRAPP_test_for_focal_time(
deepSTRAPP_outputs,
focal_time = NULL,
display_plot = TRUE,
plot_posthoc_tests = FALSE,
PDF_file_path = NULL
)Arguments
- deepSTRAPP_outputs
List of elements generated with
run_deepSTRAPP_for_focal_time(), that summarize the results of a STRAPP test for a specific time in the past (i.e. thefocal_time).deepSTRAPP_outputscan also be extracted from the output ofrun_deepSTRAPP_over_time()that run the whole deepSTRAPP workflow and store results inside$STRAPP_results_over_time.- focal_time
Numerical. (Optional) If
deepSTRAPP_outputscomprises results over multiple time-steps (i.e., output ofrun_deepSTRAPP_over_time(), this is the time of the STRAPP test targeted for plotting.- display_plot
Logical. Whether to display the histogram(s) generated in the R console. Default is
TRUE.- plot_posthoc_tests
Logical. For multinominal data only. Whether to plot the histogram for the overall Kruskal-Wallis test across all states (
plot_posthoc_tests = FALSE), or plot the histograms for all the pairwise post hoc Dunn's test across pairs of states (plot_posthoc_tests = TRUE). Default isFALSE.- PDF_file_path
Character string. If provided, the plot will be saved in a PDF file following the path provided here. The path must end with ".pdf".
Value
By default, the function returns a list of classes gg and ggplot.
This object is a ggplot that can be displayed on the console with print(output).
It corresponds to the histogram being displayed on the console when the function is run, if display_plot = TRUE, and can be further
modify for aesthetics using the ggplot2 grammar.
If using multinominal data and set plot_posthoc_tests = TRUE, the function will return a list of objects.
Each object is the ggplot associated with a pairwise post hoc test.
To plot each histogram i individually, use print(output_list[[i]]).
To plot all histograms at once in a multifaceted plot, as displayed on the console if display_plot = TRUE, use cowplot::plot_grid(plotlist = output_list).
Each plot also displays summary statistics for the STRAPP test associated with the data displayed.
The quantile of null statistic distribution at the significant threshold used to define test significance. This is the value found on the red dashed line. The test will be considered significant (i.e., the null hypothesis is rejected) if this value is higher than zero (the black dashed line).
The p-value of the STRAPP test which correspond the proportion of cases in which the statistics was lower than expected under the null hypothesis (i.e., the proportion of the histogram found below / on the left-side of the black dashed line).
If a PDF_file_path is provided, the function will also generate a PDF file of the plot. For post hoc tests, this will save the multifaceted plot.
Details
The main input deepSTRAPP_outputs is the typical output of run_deepSTRAPP_for_focal_time().
It provides information on results of a STRAPP test performed at a given focal_time.
Histograms are built based on the distribution of the test statistics.
Such distributions are recorded in the outputs of a deepSTRAPP run carried out with run_deepSTRAPP_for_focal_time()
when return_perm_data = TRUE so that the distributions of test stats computed across posterior samples are returned
among the outputs under $STRAPP_results$perm_data_df.
For multinominal data (categorical or biogeographic data with more than 2 states), it is possible to plot the histograms of post hoc pairwise tests.
Set plot_posthoc_tests = TRUE to generate histograms for all the pairwise post hoc Dunn's test across pairs of states.
To achieve this, the deepSTRAPP_outputs input object must contain a $STRAPP_results$posthoc_pairwise_tests$perm_data_array element
that summarizes test statistics computed across posterior samples for all pairwise post hoc tests.
This is obtained from run_deepSTRAPP_for_focal_time() when setting both posthoc_pairwise_tests = TRUE to carry out post hoc tests,
and return_perm_data = TRUE to record distributions of test statistics.
Alternatively, the main input deepSTRAPP_outputs can be the output of run_deepSTRAPP_over_time(),
providing results of STRAPP tests over multiple time-steps. In this case, you must provide a focal_time to select the
unique time-step used for plotting.
return_perm_datamust be set toTRUEso that the permutation data used to compute the tests are returned among the outputs under$STRAPP_results_over_time[[i]]$perm_data_df.posthoc_pairwise_testsmust be set toTRUEso that the permutation data used to performed the post hoc tests are also returned among the outputs under$STRAPP_results_over_time[[i]]$posthoc_pairwise_tests$perm_data_array.
For plotting all time-steps at once, see plot_histograms_STRAPP_tests_over_time().
See also
Associated functions in deepSTRAPP: run_deepSTRAPP_for_focal_time() plot_histograms_STRAPP_tests_over_time()