### Style code with styler::style_pkg() Source: https://github.com/acclab/dabestr/blob/master/CONTRIBUTING.md Run this in the R console to format your code according to the tidyverse style guide before submitting a pull request. The commented line installs the styler package if it is not already installed. ```r # install.packages("styler") styler::style_pkg() ``` -------------------------------- ### Install dabestr package Source: https://github.com/acclab/dabestr/blob/master/README.Rmd Installs the dabestr package from CRAN or the development version from GitHub using devtools::install_github with the repository ACCLAB/dabestr and the dev branch. ```r # Install it from CRAN install.packages("dabestr") # Or the development version from GitHub: # install.packages("devtools") devtools::install_github(repo = "ACCLAB/dabestr", ref = "dev") ``` -------------------------------- ### Set up R environment for dabestr meta-analysis Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_minimeta.Rmd Loads the dabestr and dplyr packages, which are required for the mini-meta delta analysis. This setup is used in the tutorial's code chunks. ```r library(dabestr) library(dplyr) ``` -------------------------------- ### Load sample data and create effectsize objects Source: https://github.com/acclab/dabestr/blob/master/vignettes/plot_aesthetics.Rmd Loads sample datasets and creates several dabestr effectsize objects used in the plot examples. ```r library(dabestr) data(non_proportional_data) data(proportional_data) data(deltadelta_data) dabest_twogroup_obj.mean_diff <- load(non_proportional_data, x = Group, y = Measurement, idx = c("Control 1", "Test 1")) %>% mean_diff() dabest_multigroup_obj.mean_diff <- load(non_proportional_data, x = Group, y = Measurement, idx = list(c("Control 1", "Test 1", "Test 2"), c("Control 2", "Test 3")) ) %>% mean_diff() dabest_unpaired_props.mean_diff <- load(proportional_data, x = Group, y = Success, idx = list(c("Control 1", "Test 1")), proportional = TRUE ) %>% mean_diff() dabest_paired_props.mean_diff <- load(proportional_data, x = Group, y = Success, idx = list(c("Control 1", "Test 1", "Test 2", "Test 3"), c("Control 2", "Test 4")), proportional = TRUE, paired = "sequential", id_col = ID ) %>% mean_diff() ``` -------------------------------- ### Vignette setup chunk Source: https://github.com/acclab/dabestr/blob/master/vignettes/plot_aesthetics.Rmd Sets knitr chunk options for the vignette and loads the dplyr package. ```r knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(dplyr) ``` -------------------------------- ### Compute mean_diff effect size with dabestr Source: https://github.com/acclab/dabestr/blob/master/man/effect_size.Rd Shows the complete workflow for computing a mean difference effect size with dabestr: load the example dataset, create a dabest_obj with load(), apply mean_diff(), and print the resulting effectsize object. ```r data(non_proportional_data) ``` ```r dabest_obj <- load(non_proportional_data, x = Group, y = Measurement, idx = c("Control 1", "Test 1") ) dabest_obj.mean_diff <- mean_diff(dabest_obj) ``` ```r print(dabest_obj.mean_diff) ``` -------------------------------- ### Specify custom experiment labels and x-axis levels in delta-delta analysis Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_deltadelta.Rmd Use `experiment_label` and `x1_level` in `load()` to reorder and relabel the experiment and x-axis groups. This example sets the experiment labels to c("Drug", "Placebo") and the x1 levels to c("M", "W") for a delta-delta comparison. ```R unpaired_delta2_specified.mean_diff <- load(df, x = Genotype, y = Measurement, experiment = Treatment, colour = Genotype, delta2 = TRUE, experiment_label = c("Drug", "Placebo"), x1_level = c("M", "W") ) %>% mean_diff() dabest_plot(unpaired_delta2_specified.mean_diff) ``` -------------------------------- ### Comment for Other Effect Sizes (Cohens_d) Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_deltadelta.Rmd A commented-out example showing that cohens_d is not applicable for delta-delta plots. This is a placeholder and not executed. ```r # cohens_d(unpaired_delta2) ``` -------------------------------- ### Create Cumming estimation plot with float_contrast = FALSE Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_proportion_plots.Rmd Sets float_contrast = FALSE to produce a Cumming estimation plot instead of the default Gardner-Altman plot. This example is not evaluated in the source. ```R dabest_plot(two_groups_baseline.mean_diff, float_contrast = FALSE) ``` -------------------------------- ### Create non-floating contrast plot for baseline paired data Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_repeated_measures.Rmd Generates a plot with a non-floating contrast and custom y-axis limits for baseline paired data. This example is not evaluated. ```r dabest_plot(two_groups_paired_baseline.mean_diff, float_contrast = FALSE, raw_marker_size = 0.5, raw_marker_alpha = 0.3, contrast_ylim = c(-0.3, 1.3) ) ``` -------------------------------- ### Create non-floating contrast plot for sequential paired data Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_repeated_measures.Rmd Generates a plot with a non-floating contrast and custom y-axis limits. This example is not evaluated in the document. ```r dabest_plot(two_groups_paired_sequential.mean_diff, float_contrast = FALSE, raw_marker_size = 0.5, raw_marker_alpha = 0.3, contrast_ylim = c(-0.3, 1.3) ) ``` -------------------------------- ### Specify group order with non-nested idx vector Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_proportion_plots.Rmd Uses a singular vector for idx to compare all groups together in a single comparison. This example uses paired = 'baseline' and custom text sizes. ```R multi_group_baseline_specify.mean_diff <- load(df, x = Group, y = Success, idx = c( "Control 1", "Test 1", "Test 2", "Test 3", "Test 4", "Test 5", "Test 6" ), proportional = TRUE, paired = "baseline", id_col = ID ) %>% mean_diff() dabest_plot(multi_group_baseline_specify.mean_diff, swarm_y_text = 11, contrast_y_text = 11 ) ``` -------------------------------- ### Create demo dataset with control and test groups Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_basics.Rmd Creates a demo dataset with 9 groups (3 Control, 6 Test) and adds Gender and ID columns, then converts it to long format using tidyr::gather(). The seed is fixed for replicability. ```r set.seed(12345) # Fix the seed so the results are replicable. # pop_size = 10000 # Size of each population. N <- 20 # Create samples c1 <- rnorm(N, mean = 3, sd = 0.4) c2 <- rnorm(N, mean = 3.5, sd = 0.75) c3 <- rnorm(N, mean = 3.25, sd = 0.4) t1 <- rnorm(N, mean = 3.5, sd = 0.5) t2 <- rnorm(N, mean = 2.5, sd = 0.6) t3 <- rnorm(N, mean = 3, sd = 0.75) t4 <- rnorm(N, mean = 3.5, sd = 0.75) t5 <- rnorm(N, mean = 3.25, sd = 0.4) t6 <- rnorm(N, mean = 3.25, sd = 0.4) # Add a `gender` column for coloring the data. gender <- c(rep("Male", N / 2), rep("Female", N / 2)) # Add an `id` column for paired data plotting. id <- 1:N # Combine samples and gender into a DataFrame. df <- tibble::tibble( `Control 1` = c1, `Control 2` = c2, `Control 3` = c3, `Test 1` = t1, `Test 2` = t2, `Test 3` = t3, `Test 4` = t4, `Test 5` = t5, `Test 6` = t6, Gender = gender, ID = id ) df <- df %>% tidyr::gather(key = Group, value = Measurement, -ID, -Gender) ``` -------------------------------- ### Create demo dataset for proportion plots Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_proportion_plots.Rmd Creates a reproducible demo dataset with binary (0/1) proportion data for three control and seven test groups, plus gender and ID columns for coloring and paired plotting. The data is then reshaped into long format using tidyr::gather. ```r set.seed(12345) # Fix the seed so the results are reproducible. N <- 40 # The number of samples taken from each population # Create samples size <- 1 c1 <- rbinom(N, size, prob = 0.2) c2 <- rbinom(N, size, prob = 0.2) c3 <- rbinom(N, size, prob = 0.8) t1 <- rbinom(N, size, prob = 0.35) t2 <- rbinom(N, size, prob = 0.2) t3 <- rbinom(N, size, prob = 0.3) t4 <- rbinom(N, size, prob = 0.4) t5 <- rbinom(N, size, prob = 0.5) t6 <- rbinom(N, size, prob = 0.6) t7 <- c(rep(1, N)) # Add a `gender` column for coloring the data. gender <- c(rep("Male", N / 2), rep("Female", N / 2)) # Add an `id` column for paired data plotting. id <- 1:N # Combine samples and gender into a DataFrame. df <- tibble::tibble( `Control 1` = c1, `Control 2` = c2, `Control 3` = c3, `Test 1` = t1, `Test 2` = t2, `Test 3` = t3, `Test 4` = t4, `Test 5` = t5, `Test 6` = t6, `Test 7` = t7, Gender = gender, ID = id ) df <- df %>% tidyr::gather(key = Group, value = Success, -ID, -Gender) ``` -------------------------------- ### Create demo dataset with R Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_deltadelta.Rmd Generates a synthetic dataset with placebo and drug measurements, genotype, ID, and replicate columns, then reshapes it into long format using tidyr::gather. ```r set.seed(12345) # Fix the seed so the results are reproducible. # pop_size = 10000 # Size of each population. N <- 20 # The number of samples taken from each population # Create samples placebo <- rnorm(N / 2, mean = 4, sd = 0.4) placebo <- c(placebo, rnorm(N / 2, mean = 2.8, sd = 0.4)) drug <- rnorm(N / 2, mean = 3, sd = 0.4) drug <- c(drug, rnorm(N / 2, mean = 2.5, sd = 0.4)) # Add a `Genotype` column as the second variable genotype <- c(rep("M", N / 2), rep("W", N / 2)) # Add an `id` column for paired data plotting. id <- 1:N # Add a `Rep` column as the first variable for the 2 replicates of experiments done Rep <- rep(c("Rep1", "Rep2"), N / 2) # Combine all columns into a DataFrame. df <- tibble::tibble( Placebo = placebo, Drug = drug, Genotype = genotype, ID = id, Rep = Rep ) df <- df %>% tidyr::gather(key = Treatment, value = Measurement, -ID, -Genotype, -Rep) ``` -------------------------------- ### Create and format group comparison table Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_deltadelta.Rmd Creates a data frame summarizing the four experimental groups (Drug/Placebo by Wild type/Mutant) and renders it as a formatted table using knitr::kable and kableExtra. ```r df <- data.frame( `s` = c("Drug", "Placebo"), `Wild type` = c("$X_D, W$", "$X_P, W$"), `Mutant` = c("$X_D, M$", "$X_P, M$") ) colnames(df) <- c(" ", "Wild type", "Mutant") knitr::kable(df, escape = FALSE) %>% kableExtra::column_spec(1, bold = TRUE) %>% kableExtra::column_spec(1:2, border_right = TRUE) ``` -------------------------------- ### Printing Boot Result from dabest_effectsize_obj Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_deltadelta.Rmd Access the boot_result column of the dabest_effectsize_obj to view all delta-delta calculation outputs. Use print() to display the results. ```r print(unpaired_delta2.mean_diff$boot_result) ``` -------------------------------- ### Load data and create dabest object Source: https://github.com/acclab/dabestr/blob/master/man/load.Rd Loads the non_proportional_data dataset, creates a dabest object with load() using Group and Measurement columns, and prints the object. ```R # Loading in of the dataset data(non_proportional_data) # Creating a dabest object dabest_obj <- load( data = non_proportional_data, x = Group, y = Measurement, idx = c("Control 1", "Test 1") ) # Printing dabest object print(dabest_obj) ``` -------------------------------- ### Load data with load() and idx Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_basics.Rmd Creates a dabest object by passing a dataframe to load() with x and y columns and the two groups to compare in idx. ```R two_groups_unpaired <- load(df, x = Group, y = Measurement, idx = c("Control 1", "Test 1") ) ``` -------------------------------- ### Create demo dataset with multiple groups Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_minimeta.Rmd Sets a random seed and creates a long-format tibble with three control and three test groups, plus Gender and ID columns for coloring and paired plotting. Uses tidyr::gather to convert to long format. ```r set.seed(12345) # Fix the seed so the results are reproducible. # pop_size = 10000 # Size of each population. N <- 20 # The number of samples taken from each population # Create samples c1 <- rnorm(N, mean = 3, sd = 0.4) c2 <- rnorm(N, mean = 3.5, sd = 0.75) c3 <- rnorm(N, mean = 3.25, sd = 0.4) t1 <- rnorm(N, mean = 3.5, sd = 0.5) t2 <- rnorm(N, mean = 2.5, sd = 0.6) t3 <- rnorm(N, mean = 3, sd = 0.75) # Add a `gender` column for coloring the data. gender <- c(rep("Male", N / 2), rep("Female", N / 2)) # Add an `id` column for paired data plotting. id <- 1:N # Combine samples and gender into a DataFrame. df <- tibble::tibble( `Control 1` = c1, `Control 2` = c2, `Control 3` = c3, `Test 1` = t1, `Test 2` = t2, `Test 3` = t3, Gender = gender, ID = id ) df <- df %>% tidyr::gather(key = Group, value = Measurement, -ID, -Gender) ``` -------------------------------- ### Load all sample datasets with data() Source: https://github.com/acclab/dabestr/blob/master/vignettes/sample_datasets.Rmd Loads the four sample datasets included with dabestr: non_proportional_data, proportional_data, minimeta_data, and deltadelta_data. Each corresponds to a different type of estimation plot. ```r data("non_proportional_data") data("proportional_data") data("minimeta_data") data("deltadelta_data") ``` -------------------------------- ### load(data, x, y, idx, paired, id_col, ci, resamples, colour, proportional, minimeta, delta2, experiment, experiment_label, x1_level) Source: https://github.com/acclab/dabestr/blob/master/man/load.Rd Processes and converts a tidy dataset into the dabestr format. The output of this function is then used as an input for various procedural functions within dabestr to create estimation plots. ```APIDOC ## load(data, x, y, idx, paired, id_col, ci, resamples, colour, proportional, minimeta, delta2, experiment, experiment_label, x1_level) ### Description Processes and converts a tidy dataset into the dabestr format. The output of this function is then used as an input for various procedural functions within dabestr to create estimation plots. ### Usage ```r load( data, x, y, idx = NULL, paired = NULL, id_col = NULL, ci = 95, resamples = 5000, colour = NULL, proportional = FALSE, minimeta = FALSE, delta2 = FALSE, experiment = NULL, experiment_label = NULL, x1_level = NULL ) ``` ### Parameters - **data** (dataframe) - Required - A tidy dataframe. - **x** (column) - Required - Column in `data` that contains the treatment groups. - **y** (column) - Required - Column in `data` that contains the measurement values. - **idx** (list) - Optional - List of control-test groupings for which the effect size will be computed for. - **paired** (character) - Optional - Paired ("sequential" or "baseline"). Used for plots for experiments with repeated-measures designs. If "sequential", comparison happens between each measurement to the one directly preceding it. (control vs group i). If "baseline", comparison happens between each group to a shared control. (group i vs group i+1) - **id_col** (column) - Optional - Column in `data` indicating the identity of the datapoint if the data is tagged. Compulsory parameter if paired is TRUE. - **ci** (numeric) - Optional - Default 95. Determines the range of the confidence interval for effect size and bootstrap calculations. Only accepts values between 0 to 100 (inclusive). - **resamples** (numeric) - Optional - The number of resamples to be used to generate the effect size bootstraps. - **colour** (column) - Optional - Column in `data` that determines the groupings for colour of the swarmplot as opposed to `x`. - **proportional** (boolean) - Optional - Boolean value determining if proportion plots are being produced. - **minimeta** (boolean) - Optional - Boolean value determining if mini-meta analysis is conducted. - **delta2** (boolean) - Optional - Boolean value determining if delta-delta analysis for 2 by 2 experimental designs is conducted. - **experiment** (column) - Optional - Experiment column name for delta-delta analysis. - **experiment_label** (string) - Optional - String specifying the experiment label that is used to distinguish the experiment and the factors (being used in the plotting labels). - **x1_level** (string) - Optional - String setting the first factor level in a 2 by 2 experimental design. ### Return Value Returns a `dabest_obj` list with 18 elements. The following are the elements contained within: - `raw_data` - The tidy dataset passed to `load()` that was cleaned and altered for plotting. - `proportional_data` - List of calculations related to the plotting of proportion plots. - `enquo_x` - Quosure of x as initially passed to `load()`. - `enquo_y` - Quosure of y as initially passed to `load()`. - `enquo_id_col` - Quosure of id_col as initially passed to `load()`. - `enquo_colour` - Quosure of colour as initially passed to `load()`. - `proportional` - Boolean value determining if proportion plots are being produced. - `minimeta` - Boolean value determining if mini-meta analysis is conducted. - `delta2` - Boolean value determining if delta-delta analysis for 2 by 2 experimental designs is conducted. - `idx` - List of control-test groupings for which the effect size will be computed for. - `resamples` - The number of resamples to be used to generate the effect size bootstraps. - `is_paired` - Boolean value determining if it is a paired plot. - `is_colour` - Boolean value determining if there is a specified colour column for the plot. - `paired` - Paired ("sequential" or "baseline") as initially passed to `load()`. - `ci` - Numeric value which determines the range of the confidence interval for effect size and bootstrap calculations. Only accepts values between 0 to 100 (inclusive). - `Ns` - List of labels for x-axis of the rawdata swarm plot. - `control_summary` - Numeric value for plotting of control summary lines for float_contrast= TRUE. - `test_summary` - Numeric value for plotting of test summary lines for float_contrast = TRUE. - `ylim` - Vector containing the y limits for the rawdata swarm plot. ### Example ```r # Loading in of the dataset data(non_proportional_data) # Creating a dabest object dabest_obj <- load( data = non_proportional_data, x = Group, y = Measurement, idx = c("Control 1", "Test 1") ) # Printing dabest object print(dabest_obj) ``` ``` -------------------------------- ### Load data with proportional = TRUE Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_proportion_plots.Rmd Loads a dataset for proportion analysis by setting the proportional parameter to TRUE. The load() function requires x, y, and idx arguments. ```r two_groups_unpaired <- load(df, x = Group, y = Success, idx = c("Control 1", "Test 1"), proportional = TRUE ) print(two_groups_unpaired) ``` -------------------------------- ### Load data with minimeta = TRUE Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_minimeta.Rmd Loads the data frame with the dabestr load() function, specifying idx as a list of vectors for three experiments and setting minimeta = TRUE to enable mini-meta analysis. ```r unpaired <- load(df, x = Group, y = Measurement, idx = list( c("Control 1", "Test 1"), c("Control 2", "Test 2"), c("Control 3", "Test 3") ), minimeta = TRUE ) ``` -------------------------------- ### Create demo dataset for repeated measures Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_repeated_measures.Rmd Generates a synthetic dataset with control and test groups, a gender column for coloring, and an ID column for paired data plotting. The data is then reshaped into long format using tidyr::gather. ```r set.seed(12345) # Fix the seed so the results are reproducible. N <- 20 # The number of samples taken from each population # Create samples c1 <- rnorm(N, mean = 3, sd = 0.4) c2 <- rnorm(N, mean = 3.5, sd = 0.75) c3 <- rnorm(N, mean = 3.25, sd = 0.4) t1 <- rnorm(N, mean = 3.5, sd = 0.5) t2 <- rnorm(N, mean = 2.5, sd = 0.6) t3 <- rnorm(N, mean = 3, sd = 0.75) t4 <- rnorm(N, mean = 3.5, sd = 0.75) t5 <- rnorm(N, mean = 3.25, sd = 0.4) t6 <- rnorm(N, mean = 3.25, sd = 0.4) # Add a `gender` column for coloring the data. gender <- c(rep("Male", N / 2), rep("Female", N / 2)) # Add an `id` column for paired data plotting. id <- 1:N # Combine samples and gender into a DataFrame. df <- tibble::tibble( `Control 1` = c1, `Control 2` = c2, `Control 3` = c3, `Test 1` = t1, `Test 2` = t2, `Test 3` = t3, `Test 4` = t4, `Test 5` = t5, `Test 6` = t6, Gender = gender, ID = id ) df <- df %>% tidyr::gather(key = Group, value = Measurement, -ID, -Gender) ``` -------------------------------- ### Load and plot paired data with unequal pair sizes Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_repeated_measures.Rmd Loads the dataset with `load()` using `paired = "sequential"` and `id_col = ID`, then computes the mean difference and plots with `dabest_plot()`. The `warning = FALSE` chunk option suppresses warnings. ```r # Each pair is internally balanced even though the two pairs differ in size. multi_unequal_pairs.mean_diff <- load(df_unequal_pairs, x = Group, y = Measurement, idx = list(c("Control 1", "Test 1"), c("Control 2", "Test 2")), paired = "sequential", id_col = ID ) %>% mean_diff() dabest_plot(multi_unequal_pairs.mean_diff, raw_marker_size = 0.5, raw_marker_alpha = 0.3 ) ``` -------------------------------- ### Load proportional_data dataset Source: https://github.com/acclab/dabestr/blob/master/man/proportional_data.Rd Loads the proportional_data dataset into the R environment. The comment notes that the data becomes visible as soon as it is loaded. ```r data(proportional_data) # Lazy loading. Data becomes visible as soon as it is loaded ``` -------------------------------- ### Load paired data and plot with custom markers Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_minimeta.Rmd Load paired data using paired = "baseline" and id_col = ID, then compute mean_diff and plot with raw_marker_size = 0.5 and raw_marker_alpha = 0.3. ```R paired.mean_diff <- load(df, x = Group, y = Measurement, idx = list( c("Control 1", "Test 1"), c("Control 2", "Test 2"), c("Control 3", "Test 3") ), paired = "baseline", id_col = ID, minimeta = TRUE ) %>% mean_diff() dabest_plot(paired.mean_diff, raw_marker_size = 0.5, raw_marker_alpha = 0.3) ``` -------------------------------- ### Load dabestr library Source: https://github.com/acclab/dabestr/blob/master/vignettes/sample_datasets.Rmd Loads the dabestr package. Required before using any of its functions or datasets. ```r library(dabestr) ``` -------------------------------- ### Print the dabest object Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_deltadelta.Rmd Prints the loaded dabest object to inspect its structure and contents. ```r print(unpaired_delta2) ``` -------------------------------- ### Display first rows of the dataset Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_minimeta.Rmd Uses knitr::kable to render the first rows of the long-format data frame as a table. ```r knitr::kable(head(df)) ``` -------------------------------- ### Create a Gardner-Altman estimation plot with dabest_plot Source: https://github.com/acclab/dabestr/blob/master/man/dabest_plot.Rd Loads the twogroup_data dataset, prepares a dabest_obj with load() using Group and Measurement columns and the specified idx, computes the mean difference effect size with mean_diff(), then produces a Gardner-Altman estimation plot by calling dabest_plot() with float_contrast = TRUE. ```r # Loading of the dataset data(twogroup_data) # Preparing the data to be plotted dabest_obj <- load(non_proportional_data, x = Group, y = Measurement, idx = c("Control 1", "Test 1") ) dabest_obj.mean_diff <- mean_diff(dabest_obj) # Plotting an estimation plot dabest_plot(dabest_obj.mean_diff, TRUE) ``` -------------------------------- ### Load paired data with baseline pairing Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_repeated_measures.Rmd Loads a two-group paired dataset using the 'baseline' pairing method. For two groups, this yields the same numerical results as 'sequential'. ```r two_groups_paired_baseline <- load(df, x = Group, y = Measurement, idx = c("Control 1", "Test 1"), paired = "baseline", id_col = ID ) print(two_groups_paired_baseline) ``` -------------------------------- ### Create and plot mean difference estimation Source: https://github.com/acclab/dabestr/blob/master/README.Rmd Loads the non_proportional_data dataset, creates a mean difference estimation object using load() with Group as x, Measurement as y, and idx c("Control 1", "Test 1"), then pipes to mean_diff() and plots with dabest_plot(). ```r data("non_proportional_data") dabest_obj.mean_diff <- load( data = non_proportional_data, x = Group, y = Measurement, idx = c("Control 1", "Test 1") ) %>% mean_diff() dabest_plot(dabest_obj.mean_diff, TRUE) ``` -------------------------------- ### dabest_plot() with plot_component argument Source: https://github.com/acclab/dabestr/blob/master/vignettes/plot_aesthetics.Rmd Shows how to add and customize plot components by passing them as arguments to dabest_plot(). ```r dabest_plot( dabest_effectsize_obj, float_contrast = TRUE, plot_component = "adjustment_value" ) ``` -------------------------------- ### Apache License boilerplate notice for dabestr authors Source: https://github.com/acclab/dabestr/blob/master/LICENSE.md Boilerplate notice to attach to your work when applying the Apache License, with fields enclosed by brackets replaced with your own identifying information. The text should be enclosed in the appropriate comment syntax for the file format. Recommended to include a file or class name and description of purpose on the same printed page as the copyright notice. ```text Copyright 2023 dabestr authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` -------------------------------- ### Access boot_results for each experiment Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_minimeta.Rmd Accesses the boot_results element of the dabest_effectsize_obj to view details of each experiment, including the weighted delta. ```r unpaired.mean_diff$boot_result ``` -------------------------------- ### Load paired data with sequential pairing Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_repeated_measures.Rmd Loads a two-group paired dataset using the 'sequential' pairing method. The id_col parameter is required for paired data. ```r two_groups_paired_sequential <- load(df, x = Group, y = Measurement, idx = c("Control 1", "Test 1"), paired = "sequential", id_col = ID ) print(two_groups_paired_sequential) ``` -------------------------------- ### Print the dabest object Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_minimeta.Rmd Prints the loaded dabest object to show that effect sizes will be calculated for each group and the weighted delta. ```r print(unpaired) ``` -------------------------------- ### Set knitr chunk options Source: https://github.com/acclab/dabestr/blob/master/README.Rmd Configures knitr chunk options for the README.Rmd file, setting collapse to TRUE, comment to "#>", and the figure path to "man/figures/README-". ```r knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-" ) ``` -------------------------------- ### Print mean difference results for sequential pairing Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_repeated_measures.Rmd Prints the mean difference results for the sequential paired dataset. ```r print(two_groups_paired_sequential.mean_diff) ``` -------------------------------- ### Create dataset with unequal paired sample sizes Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_repeated_measures.Rmd Generates a tibble with two paired groups (Control 1/Test 1 with n=20, Control 2/Test 2 with n=10) using random normal data. Each pair is internally balanced, but the pairs differ in size. ```r set.seed(12345) N1 <- 20 N2 <- 10 df_unequal_pairs <- tibble::tibble( Group = rep(c("Control 1", "Test 1", "Control 2", "Test 2"), c(N1, N1, N2, N2)), Measurement = c( rnorm(N1, mean = 3, sd = 0.4), # Control 1 rnorm(N1, mean = 3.5, sd = 0.5), # Test 1 rnorm(N2, mean = 2.5, sd = 0.4), # Control 2 rnorm(N2, mean = 3.0, sd = 0.5) # Test 2 ), ID = c(1:N1, 1:N1, 1:N2, 1:N2) ) ``` -------------------------------- ### Print mean difference results for baseline pairing Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_repeated_measures.Rmd Prints the mean difference results for the baseline paired dataset. ```r print(two_groups_paired_baseline.mean_diff) ``` -------------------------------- ### Create paired proportion plot with baseline pairing Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_proportion_plots.Rmd Loads data with proportional = TRUE and paired = 'baseline', computes the mean difference, and generates a Gardner-Altman estimation plot. The id_col parameter is required for paired analysis. ```R two_groups_baseline.mean_diff <- load(df, x = Group, y = Success, idx = c("Control 1", "Test 1"), proportional = TRUE, paired = "baseline", id_col = ID ) %>% mean_diff() dabest_plot(two_groups_baseline.mean_diff) ``` -------------------------------- ### Load deltadelta_data dataset Source: https://github.com/acclab/dabestr/blob/master/man/deltadelta_data.Rd Loads the deltadelta_data dataset using lazy loading. The data becomes visible as soon as it is loaded. ```r data(deltadelta_data) # Lazy loading. Data becomes visible as soon as it is loaded ``` -------------------------------- ### Load data with ci = 90 Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_basics.Rmd Changes the confidence interval width to 90% by setting the ci argument. ```R two_groups_unpaired_ci90 <- load(df, x = Group, y = Measurement, idx = c("Control 1", "Test 1"), ci = 90 ) ``` -------------------------------- ### Generate paired proportion plot with custom text sizes and bar width Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_proportion_plots.Rmd Creates a paired proportion plot with float_contrast = FALSE and customizes text sizes and raw bar width. The plot is then arranged in a grid with empty panels using cowplot::plot_grid(). ```R pp_plot <- dabest_plot(two_groups_baseline.mean_diff, float_contrast = FALSE, swarm_y_text = 11, contrast_y_text = 11, raw_bar_width = 0.2 ) cowplot::plot_grid( plotlist = list(NULL, pp_plot, NULL), nrow = 1, ncol = 3, rel_widths = c(2.5, 5, 2.5) ) ``` -------------------------------- ### Load data for unpaired delta-delta plot with experiment_label and x1_level Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_deltadelta.Rmd Loads the dataset with delta2 = TRUE and additional parameters experiment_label and x1_level to specify the experiment groups and the reference level for the x variable. ```r unpaired_delta2 <- load(df, x = Genotype, y = Measurement, experiment = Treatment, colour = Genotype, delta2 = TRUE, experiment_label = c("Placebo", "Drug"), x1_level = c("W", "M") ) ``` -------------------------------- ### Load data for unpaired delta-delta plot Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_deltadelta.Rmd Loads the dataset with delta2 = TRUE to create a delta-delta analysis. The x, y, experiment, and colour parameters are specified; idx is optional for delta-delta. ```r unpaired_delta2 <- load(df, x = Genotype, y = Measurement, experiment = Treatment, colour = Genotype, delta2 = TRUE ) ``` -------------------------------- ### dabest_plot() Source: https://github.com/acclab/dabestr/blob/master/vignettes/plot_aesthetics.Rmd Documentation for the dabest_plot() function, which is used to generate and customize dabestr estimation plots. ```APIDOC ## dabest_plot() ### Description Generates a `dabestr` estimation plot with customizable aesthetics. Users can adjust text size, content, and other plot components by passing arguments to this function. ### Usage ```r dabest_plot( dabest_effectsize_obj, float_contrast = TRUE, plot_component = "adjustment_value", swarm_x_text = 11, swarm_y_text = 15, contrast_x_text = 11, contrast_y_text = 15, swarm_label = NULL, contrast_label = NULL, delta2_label = NULL ) ``` ### Parameters - **dabest_effectsize_obj** (object) - Required - The effectsize object obtained from `dabest` functions such as `mean_diff()`. - **float_contrast** (logical) - Optional - Whether to float the contrast plot. Default is `TRUE`. - **plot_component** (string) - Optional - Specifies which plot component to adjust. Example: `"adjustment_value"`. - **swarm_x_text** (numeric) - Optional - Font size of the x-axis text in the swarm plot. Default is 11. - **swarm_y_text** (numeric) - Optional - Font size of the y-axis text in the swarm plot. Default is 15. - **contrast_x_text** (numeric) - Optional - Font size of the x-axis text in the contrast plot. Default is 11. - **contrast_y_text** (numeric) - Optional - Font size of the y-axis text in the contrast plot. Default is 15. - **swarm_label** (string) - Optional - Label for the y-axis in the swarm plot. Default is `"value"` or `"proportion of success"` for proportion plots. - **contrast_label** (string) - Optional - Label for the y-axis in the contrast plot. Default is `"effect size"` based on the effect sizes from `effect_size()`. - **delta2_label** (string) - Optional - Label for the y-axis in the swarm plot for delta2 plots. Default is `NULL`. ### Example ```r dabest_plot( dabest_effectsize_obj, float_contrast = TRUE, plot_component = "adjustment_value" ) ``` ### Example: Adjusting Text Size ```r dabest_plot( dabest_twogroup_obj.mean_diff, float_contrast = TRUE, swarm_x_text = 30, swarm_y_text = 1, contrast_x_text = 30, contrast_y_text = 5 ) ``` ### Example: Adjusting Text Content ```r dabest_plot( dabest_twogroup_obj.mean_diff, float_contrast = TRUE, swarm_label = "I love estimation statistics.", contrast_label = "I love it more than you do!" ) ``` ``` -------------------------------- ### Create repeated measures paired proportion plot with sequential pairing Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_proportion_plots.Rmd Loads data with multiple groups in a nested list for idx, uses paired = 'sequential', and generates a plot with custom text sizes. This demonstrates the sequential repeated measures design. ```R multi_group_sequential.mean_diff <- load(df, x = Group, y = Success, idx = list( c( "Control 1", "Test 1", "Test 2", "Test 3" ), c( "Test 4", "Test 5", "Test 6" ) ), proportional = TRUE, paired = "sequential", id_col = ID ) %>% mean_diff() dabest_plot(multi_group_sequential.mean_diff, swarm_y_text = 11, contrast_y_text = 11 ) ``` -------------------------------- ### Create repeated measures paired proportion plot with baseline pairing Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_proportion_plots.Rmd Loads data with multiple groups in a nested list for idx, uses paired = 'baseline', and generates a plot with custom text sizes. This demonstrates repeated measures support. ```R multi_group_baseline.mean_diff <- load(df, x = Group, y = Success, idx = list( c( "Control 1", "Test 1", "Test 2", "Test 3" ), c( "Test 4", "Test 5", "Test 6" ) ), proportional = TRUE, paired = "baseline", id_col = ID ) %>% mean_diff() dabest_plot(multi_group_baseline.mean_diff, swarm_y_text = 11, contrast_y_text = 11 ) ``` -------------------------------- ### Customize Cumming plot with text sizes and arrange with cowplot Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_proportion_plots.Rmd Creates a Cumming plot with custom text sizes for the swarm and contrast y-axes, then arranges it with cowplot::plot_grid() using NULL placeholders. ```r pp_plot <- dabest_plot(two_groups_unpaired.mean_diff, float_contrast = FALSE, swarm_y_text = 11, contrast_y_text = 11 ) cowplot::plot_grid( plotlist = list(NULL, pp_plot, NULL), nrow = 1, ncol = 3, rel_widths = c(2.5, 5, 2.5) ) ``` -------------------------------- ### Adjust sankey and flow parameters for paired proportion plots Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_proportion_plots.Rmd Loads data with multiple groups and paired = 'sequential', then generates three plots: the default with sankey and flow TRUE, one with sankey = FALSE, and one with flow = FALSE. These demonstrate how to customize the Sankey diagram appearance. ```R separate_control.mean_diff <- load(df, x = Group, y = Success, idx = list( c("Control 1", "Test 1"), c("Test 2", "Test 3"), c("Test 4", "Test 5", "Test 6") ), proportional = TRUE, paired = "sequential", id_col = ID ) %>% mean_diff() dabest_plot(separate_control.mean_diff, swarm_y_text = 11, contrast_y_text = 11) dabest_plot(separate_control.mean_diff, swarm_y_text = 11, contrast_y_text = 11, sankey = FALSE ) dabest_plot(separate_control.mean_diff, swarm_y_text = 11, contrast_y_text = 11, flow = FALSE ) ``` -------------------------------- ### Set knitr chunk options Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_deltadelta.Rmd Sets knitr chunk options for the vignette: collapse output and use `#>` as the comment prefix. ```r knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` -------------------------------- ### Load and plot multi-baseline repeated-measures data Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_repeated_measures.Rmd Loads a dataset with two independent control/test groups, each with repeated measures, using 'baseline' pairing, computes the mean difference, and plots the results. ```r multi_baseline_repeated_measures.mean_diff <- load(df, x = Group, y = Measurement, idx = list( c( "Control 1", "Test 1", "Test 2", "Test 3" ), c( "Control 2", "Test 4", "Test 5", "Test 6" ) ), paired = "baseline", id_col = ID ) %>% mean_diff() dabest_plot(multi_baseline_repeated_measures.mean_diff, raw_marker_size = 0.5, raw_marker_alpha = 0.3 ) ``` -------------------------------- ### Load and analyze sequential repeated-measures data Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_repeated_measures.Rmd Loads a multi-group repeated-measures dataset with 'sequential' pairing and computes the mean difference. The slopegraph is the same as baseline, but the contrast plot differs. ```r sequential_repeated_measures.mean_diff <- load(df, x = Group, y = Measurement, idx = c( "Control 1", "Test 1", "Test 2", "Test 3" ), paired = "sequential", id_col = ID ) %>% mean_diff() print(sequential_repeated_measures.mean_diff) ``` -------------------------------- ### Set swarm and contrast y-limits in dabest_plot Source: https://github.com/acclab/dabestr/blob/master/vignettes/plot_aesthetics.Rmd Sets y-axis limits for the swarm and contrast plots using swarm_ylim and contrast_ylim. The contrast_ylim vector is inverted (c(0.7, -1.2)) to reflect that smaller values are better, as indicated by the contrast_label. ```r dabest_plot(dabest_multigroup_obj.mean_diff, float_contrast = FALSE, contrast_label = "More negative is better!", swarm_ylim = c(1, 5), contrast_ylim = c(0.7, -1.2) ) ``` -------------------------------- ### Generate Gardner-Altman plots for both effect sizes Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_proportion_plots.Rmd Creates Gardner-Altman estimation plots for both the mean difference and Cohen's h effect sizes using dabest_plot(). The function requires only the dabest_effectsize_obj. ```r dabest_plot(two_groups_unpaired.mean_diff) dabest_plot(two_groups_unpaired.cohens_h) ``` -------------------------------- ### Print ci90 object Source: https://github.com/acclab/dabestr/blob/master/vignettes/tutorial_basics.Rmd Printing the ci90 object shows the updated confidence interval. ```R print(two_groups_unpaired_ci90) ```