### Github Action setup Source: https://github.com/kassambara/rstatix/blob/master/cran-comments.md Example of setting up a Github Action for checking the package. ```R usethis::use_github_action("check-standard") ``` -------------------------------- ### Install rstatix Source: https://github.com/kassambara/rstatix/blob/master/docs/index.html Install the latest developmental version from GitHub or from CRAN. ```R if(!require(devtools)) install.packages("devtools") devtools::install_github("kassambara/rstatix") ``` ```R install.packages("rstatix") ``` -------------------------------- ### Example Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/prop_test.html Example of comparing an observed proportion to an expected proportion. ```r # Comparing an observed proportion to an expected proportion ``` -------------------------------- ### Adding a New Statistical Test - Test file example Source: https://github.com/kassambara/rstatix/blob/master/CLAUDE.md Example R code for writing unit tests for a new statistical test function. ```R test_that("new_test works with two groups", { result <- mtcars %>% new_test(mpg ~ am) expect_s3_class(result, "rstatix_test") expect_true("p" %in% colnames(result)) }) ``` -------------------------------- ### Example Usage Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/eta_squared.html An example demonstrating how to compute ANOVA and then calculate eta-squared and partial eta-squared. ```R # Data preparation df <- ToothGrowth df$dose <- as.factor(df$dose) # Compute ANOVA res.aov <- aov(len ~ supp*dose, data = df) summary(res.aov) #> Df Sum Sq Mean Sq F value Pr(>F) #> supp 1 205.4 205.4 15.572 0.000231 *** #> dose 2 2426.4 1213.2 92.000 < 2e-16 *** #> supp:dose 2 108.3 54.2 4.107 0.021860 * #> Residuals 54 712.1 13.2 #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # Effect size eta_squared(res.aov) #> supp dose supp:dose #> 0.05948365 0.70286419 0.03137672 partial_eta_squared(res.aov) #> supp dose supp:dose #> 0.2238254 0.7731092 0.1320279 ``` -------------------------------- ### Building and Documentation Source: https://github.com/kassambara/rstatix/blob/master/CLAUDE.md Commands for generating documentation, building the package tarball, and installing the package locally using devtools. ```r # Generate documentation from roxygen2 comments devtools::document() # Build package tarball devtools::build() # Or: R CMD build . # Install package locally devtools::install() ``` -------------------------------- ### Example 1: Basic Usage Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/kruskal_effsize.html An example demonstrating the basic usage of kruskal_effsize with the ToothGrowth dataset. ```R # Load data #:::::::::::::::::::::::::::::::::::::::: data("ToothGrowth") df <- ToothGrowth # Kruskal-wallis rank sum test #::::::::::::::::::::::::::::::::::::::::: df %>% kruskal_effsize(len ~ dose) #> # A tibble: 1 × 5 #> .y. n effsize method magnitude #> * #> 1 len 60 0.678 eta2[H] large ``` -------------------------------- ### Correlation tests Source: https://github.com/kassambara/rstatix/blob/master/README.md Examples of correlation tests, including pairwise and against all variables. ```r # Data preparation mydata <- mtcars %>% select(mpg, disp, hp, drat, wt, qsec) head(mydata, 3) #> mpg disp hp drat wt qsec #> Mazda RX4 21.0 160 110 3.90 2.620 16.46 #> Mazda RX4 Wag 21.0 160 110 3.90 2.875 17.02 #> Datsun 710 22.8 108 93 3.85 2.320 18.61 # Correlation test between two variables mydata %>% cor_test(wt, mpg, method = "pearson") #> # A tibble: 1 × 8 #> var1 var2 cor statistic p conf.low conf.high method #> #> 1 wt mpg -0.87 -9.56 1.29e-10 -0.934 -0.744 Pearson # Correlation of one variable against all mydata %>% cor_test(mpg, method = "pearson") #> # A tibble: 5 × 8 #> var1 var2 cor statistic p conf.low conf.high method #> #> 1 mpg disp -0.85 -8.75 9.38e-10 -0.923 -0.708 Pearson #> 2 mpg hp -0.78 -6.74 1.79e- 7 -0.885 -0.586 Pearson #> 3 mpg drat 0.68 5.10 1.78e- 5 0.436 0.832 Pearson #> 4 mpg wt -0.87 -9.56 1.29e-10 -0.934 -0.744 Pearson #> 5 mpg qsec 0.42 2.53 1.71e- 2 0.0820 0.670 Pearson ``` -------------------------------- ### Example 1: Select column using standard evaluation Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/df_arrange.html This example demonstrates how to select columns for arrangement using standard evaluation with the 'vars' argument. ```R df <- head(ToothGrowth) df %>% df_arrange(vars = c("dose", "len")) ``` -------------------------------- ### Roxygen2 Structure - Example one-sample test Source: https://github.com/kassambara/rstatix/blob/master/CLAUDE.md Example of a one-sample t-test using roxygen2 documentation format. ```R # One-sample test df %>% t_test(len ~ 1, mu = 0) ``` -------------------------------- ### Formula Interface Example 1 Source: https://github.com/kassambara/rstatix/blob/master/CLAUDE.md Example of using the t_test function with a formula interface for a two-sample test. ```r # outcome ~ group df %>% t_test(len ~ supp) ``` -------------------------------- ### Simple Test Example Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/dunn_test.html An example demonstrating a simple Dunn's test on the ToothGrowth dataset. ```R ToothGrowth %>% dunn_test(len ~ dose) #> # A tibble: 3 × 9 #> .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif #> * #> 1 len 0.5 1 20 20 3.55 3.78e- 4 7.56e- 4 *** #> 2 len 0.5 2 20 20 6.36 1.98e-10 5.95e-10 **** #> 3 len 1 2 20 20 2.81 4.99e- 3 4.99e- 3 ** ``` -------------------------------- ### Remove bracket Source: https://github.com/kassambara/rstatix/blob/master/README.md Example of removing brackets in p-value annotations. ```r ggboxplot(df, x = "dose", y = "len", ylim = c(0, 40)) + stat_pvalue_manual( stat.test, label = "p.adj.signif", y.position = c(29, 35), remove.bracket = TRUE ) ``` -------------------------------- ### Formula Interface Example 2 Source: https://github.com/kassambara/rstatix/blob/master/CLAUDE.md Example of using the t_test function with a formula interface for a one-sample test comparing to a mu value. ```r # One-sample test (compare to mu) df %>% t_test(len ~ 1, mu = 0) ``` -------------------------------- ### Example Usage Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/emmeans_test.html An example demonstrating how to use the emmeans_test function for pairwise comparisons on the ToothGrowth dataset. ```r # Data preparation df <- ToothGrowth df$dose <- as.factor(df$dose) # Pairwise comparisons res <- df %>% group_by(supp) %>% emmeans_test(len ~ dose, p.adjust.method = "bonferroni") res #> # A tibble: 6 × 10 #> supp term .y. group1 group2 df statistic p p.adj p.adj.signif #> * #> 1 OJ dose len 0.5 1 54 -5.83 3.18e- 7 9.53e- 7 **** #> 2 OJ dose len 0.5 2 54 -7.90 1.43e-10 4.29e-10 **** #> 3 OJ dose len 1 2 54 -2.07 4.34e- 2 1.30e- 1 ns #> 4 VC dose len 0.5 1 54 -5.41 1.46e- 6 4.39e- 6 **** #> 5 VC dose len 0.5 2 54 -11.2 1.13e-15 3.39e-15 **** #> 6 VC dose len 1 2 54 -5.77 3.98e- 7 1.19e- 6 **** # Display estimated marginal means attr(res, "emmeans") #> # A tibble: 6 × 8 #> supp dose emmean se df conf.low conf.high method #> #> 1 OJ 0.5 13.2 1.15 54 10.9 15.5 Emmeans test ``` -------------------------------- ### Example usage of freq_table. Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/freq_table.html Example of how to use the freq_table function with the ToothGrowth dataset. ```R data("ToothGrowth") ToothGrowth %>% freq_table(supp, dose) #> # A tibble: 6 × 4 #> supp dose n prop #> #> 1 OJ 0.5 10 33.3 #> 2 OJ 1 10 33.3 #> 3 OJ 2 10 33.3 #> 4 VC 0.5 10 33.3 #> 5 VC 1 10 33.3 #> 6 VC 2 10 33.3 ``` -------------------------------- ### No mode Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_mode.html Example demonstrating a case where there is no distinct mode. ```R x <- c(1, 2, 3, 4, 5) get_mode(x) ``` -------------------------------- ### Basic grouped t-test example Source: https://github.com/kassambara/rstatix/blob/master/CLAUDE.md Demonstrates a grouped t-test on a data frame. ```R df %>% group_by(dose) %>% t_test(len ~ supp) ``` -------------------------------- ### Adding a New Statistical Test - R script example Source: https://github.com/kassambara/rstatix/blob/master/CLAUDE.md Example R code for creating a new statistical test function within the rstatix package. ```R '@include utilities.R utilities_two_sample_test.R NULL '@export new_test <- function(data, formula, ...) { args <- as.list(environment()) params <- args %>% remove_null_items() %>% add_item(method = "base.r.function") # Determine test type number.of.groups <- guess_number_of_groups(data, group) test.func <- if(number.of.groups > 2) pairwise_two_sample_test else two_sample_test do.call(test.func, params) %>% set_attrs(args = args) %>% add_class(c("rstatix_test", "new_test")) } ``` -------------------------------- ### Example 2: Select column using non-standard evaluation Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/df_arrange.html This example shows how to select columns for arrangement using non-standard evaluation, including sorting a column in descending order. ```R df <- head(ToothGrowth) df %>% df_arrange(dose, desc(len)) ``` -------------------------------- ### Compute only mean and sd Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_summary_stats.html Example of computing only the mean and standard deviation for a variable. ```R ToothGrowth %>% get_summary_stats(len, type = "mean_sd") #> # A tibble: 1 × 4 #> variable n mean sd #> #> 1 len 60 18.8 7.65 ``` -------------------------------- ### Example: Comparing two proportions Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/fisher_test.html An example demonstrating how to use the fisher_test function to compare proportions of smokers between two groups. ```R # Comparing two proportions #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # Data: frequencies of smokers between two groups xtab <- as.table(rbind(c(490, 10), c(400, 100))) dimnames(xtab) <- list( group = c("grp1", "grp2"), smoker = c("yes", "no") ) xtab #> smoker #> group yes no #> grp1 490 10 #> grp2 400 100 # compare the proportion of smokers fisher_test(xtab, detailed = TRUE) #> # A tibble: 1 × 8 #> n estimate p conf.low conf.high method alter…¹ p.sig…² #> * #> 1 1000 12.2 8.77e-22 6.27 26.6 Fisher's Exact test two.si… **** ``` -------------------------------- ### Five number summary statistics Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_summary_stats.html Example of computing the five-number summary statistics for a variable. ```R ToothGrowth %>% get_summary_stats(len, type = "five_number") #> # A tibble: 1 × 7 #> variable n min max q1 median q3 #> #> 1 len 60 4.2 33.9 13.1 19.2 25.3 ``` -------------------------------- ### Example usage of friedman_effsize Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/friedman_effsize.html An example demonstrating how to use the friedman_effsize function with the ToothGrowth dataset. ```R # Load data #:::::::::::::::::::::::::::::::::::::::: data("ToothGrowth") df <- ToothGrowth %>% filter(supp == "VC") %>% mutate(id = rep(1:10, 3)) head(df) #> len supp dose id #> 1 4.2 VC 0.5 1 #> 2 11.5 VC 0.5 2 #> 3 7.3 VC 0.5 3 #> 4 5.8 VC 0.5 4 #> 5 6.4 VC 0.5 5 #> 6 10.0 VC 0.5 6 # Friedman test effect size #::::::::::::::::::::::::::::::::::::::::: df %>% friedman_effsize(len ~ dose | id) #> # A tibble: 1 × 5 #> .y. n effsize method magnitude #> * #> 1 len 10 1 Kendall W large ``` -------------------------------- ### Bimodal Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_mode.html Example demonstrating a bimodal case where there are two modes. ```R x <- c(1:5, 6, 6, 7, 8, 9, 9, 10) get_mode(x) ``` -------------------------------- ### Full summary statistics Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_summary_stats.html Example of computing full summary statistics for a single variable in a dataset. ```R data("ToothGrowth") ToothGrowth %>% get_summary_stats(len) #> # A tibble: 1 × 13 #> variable n min max median q1 q3 iqr mad mean sd se #> #> 1 len 60 4.2 33.9 19.2 13.1 25.3 12.2 9.04 18.8 7.65 0.988 #> # … with 1 more variable: ci ``` -------------------------------- ### Get pairwise comparison labels Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_test_label.html Example of getting a label for pairwise comparisons from a T test. ```R get_pwc_label(ttest, type = "text") ``` -------------------------------- ### Get test label for Wilcoxon test Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_test_label.html Example of getting a formatted string for a Wilcoxon test result. ```R get_test_label(wilcox, detailed = TRUE, type = "text") ``` -------------------------------- ### Loading packages Source: https://github.com/kassambara/rstatix/blob/master/docs/index.html Load the rstatix and ggpubr packages. ```R library(rstatix) library(ggpubr) # For easy data-visualization ``` -------------------------------- ### Get test label for T test Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_test_label.html Example of getting formatted strings for a T test result, showing multiple outputs. ```R ttest <- df %>% t_test(len ~ dose) get_test_label(ttest, detailed = TRUE, type = "text") ``` -------------------------------- ### Comparisons against all (basemean) Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_comparisons.html Illustrates how to compare each group level against all other groups (basemean). ```R ToothGrowth %>% get_comparisons("dose", ref.group = "all") #> $V1 #> [1] "all" "0.5" #> #> $V2 #> [1] "all" "1" #> #> $V3 #> [1] "all" "2" ``` -------------------------------- ### Non standard evaluation Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/df_get_var_names.html Example demonstrating non-standard evaluation for selecting variables. ```R ToothGrowth %>% df_get_var_names(dose, len) #> [1] "dose" "len" ``` -------------------------------- ### Standard evaluation Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/df_get_var_names.html Example demonstrating standard evaluation for selecting variables using the 'vars' argument. ```R ToothGrowth %>% df_get_var_names(vars = c("len", "dose")) #> [1] "len" "dose" ``` -------------------------------- ### Documentation Website Source: https://github.com/kassambara/rstatix/blob/master/CLAUDE.md Commands for building and previewing the pkgdown documentation website locally. ```r # Build pkgdown site (output in docs/) pkgdown::build_site() # Preview locally pkgdown::preview_site() # Build single reference page pkgdown::build_reference() ``` -------------------------------- ### Examples Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/multinom_test.html Examples of using the multinom_test function. ```r # Data tulip <- c(red = 81, yellow = 50, white = 27) # Question 1: are the color equally common ? #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # this is a test of homogeneity res <- multinom_test(tulip) res #> # A tibble: 1 × 2 #> p p.signif #> * #> 1 0.000000711 **** attr(res, "descriptives") #> # A tibble: 3 × 3 #> group observed expected #> #> 1 red 81 52.7 #> 2 yellow 50 52.7 #> 3 white 27 52.7 # Pairwise comparisons between groups pairwise_binom_test(tulip, p.adjust.method = "bonferroni") #> # A tibble: 3 × 9 #> group1 group2 n estimate conf.low conf.high p p.adj p.adj…¹ #> * #> 1 red yellow 131 0.618 0.529 0.702 0.00851 2.55e-2 * #> 2 red white 108 0.75 0.657 0.828 0.000000191 5.72e-7 **** #> 3 yellow white 77 0.649 0.532 0.755 0.0117 3.5 e-2 * #> # … with abbreviated variable name ¹​p.adj.signif # Question 2: comparing observed to expected proportions #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # this is a goodness-of-fit test expected.p <- c(red = 0.5, yellow = 0.33, white = 0.17) res <- multinom_test(tulip, expected.p) res #> # A tibble: 1 × 2 #> p p.signif #> * #> 1 0.942 ns attr(res, "descriptives") #> # A tibble: 3 × 3 #> group observed expected #> #> 1 red 81 79 #> 2 yellow 50 52.1 #> 3 white 27 26.9 # Pairwise comparisons against a given probabilities pairwise_binom_test_against_p(tulip, expected.p) #> # A tibble: 3 × 10 #> group observed expected n estimate conf.low conf.high p p.adj p.adj…¹ #> * #> 1 red 81 79 158 0.513 0.432 0.593 0.811 1 ns #> 2 yellow 50 52.1 158 0.316 0.245 0.395 0.800 1 ns #> 3 white 27 26.9 158 0.171 0.116 0.239 1 1 ns #> # … with abbreviated variable name ¹​p.adj.signif ``` -------------------------------- ### All possible pairwise comparisons Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_comparisons.html Demonstrates how to get all possible pairwise comparisons between groups using the get_comparisons function. ```R ToothGrowth %>% get_comparisons("dose") #> $V1 #> [1] "0.5" "1" #> #> $V2 #> [1] "0.5" "2" #> #> $V3 #> [1] "1" "2" ``` -------------------------------- ### Prepare demo data for t-test Source: https://github.com/kassambara/rstatix/blob/master/docs/index.html Prepare the ToothGrowth dataset for a t-test by converting dose to a factor. ```R df <- ToothGrowth df$dose <- as.factor(df$dose) head(df) ``` -------------------------------- ### Comparisons against reference groups Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_comparisons.html Shows how to perform comparisons against a specified reference group. ```R ToothGrowth %>% get_comparisons("dose", ref.group = "0.5") #> $V1 #> [1] "0.5" "1" #> #> $V2 #> [1] "0.5" "2" ``` -------------------------------- ### Example 2: Grouped Data Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/kruskal_effsize.html An example showing how to use kruskal_effsize with grouped data. ```R # Grouped data df %>% group_by(supp) %>% kruskal_effsize(len ~ dose) #> # A tibble: 2 × 6 #> supp .y. n effsize method magnitude #> * #> 1 OJ len 30 0.611 eta2[H] large #> 2 VC len 30 0.855 eta2[H] large ``` -------------------------------- ### Formula Examples Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/anova_test.html Examples of supported formula structures for different ANOVA types. ```R # Between-Ss ANOVA (independent measures ANOVA): y ~ b1*b2 # Within-Ss ANOVA (repeated measures ANOVA): y ~ w1*w2 + Error(id/(w1*w2)) # Mixed ANOVA: y ~ b1*b2*w1 + Error(id/w1) ``` -------------------------------- ### Sample n rows by group Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/sample_n_by.html This example demonstrates how to sample n rows by group using the sample_n_by function. ```R ToothGrowth %>% sample_n_by(dose, supp, size = 2) #> # A tibble: 12 × 3 #> len supp dose #> #> 1 14.5 OJ 0.5 #> 2 8.2 OJ 0.5 #> 3 5.2 VC 0.5 #> 4 7 VC 0.5 #> 5 27.3 OJ 1 #> 6 25.8 OJ 1 #> 7 22.5 VC 1 #> 8 13.6 VC 1 #> 9 24.8 OJ 2 #> 10 30.9 OJ 2 #> 11 23.3 VC 2 #> 12 18.5 VC 2 ``` -------------------------------- ### Compute correlation matrix Source: https://github.com/kassambara/rstatix/blob/master/docs/index.html Compute correlation matrix. ```R # Compute correlation matrix cor.mat <- mydata %>% cor_mat() cor.mat ``` -------------------------------- ### ANOVA Table Source: https://github.com/kassambara/rstatix/blob/master/docs/index.html Compute and display ANOVA table for linear models. ```R #.my.model <- lm(yield ~ block + N*P*K, npk) anova_test(.my.model) ``` -------------------------------- ### Use model as arguments Source: https://github.com/kassambara/rstatix/blob/master/README.md Performing ANOVA test using a linear model object as input. ```r # Use model as arguments #::::::::::::::::::::::::::::::::::::::::: .my.model <- lm(yield ~ block + N*P*K, npk) anova_test(.my.model) #> ANOVA Table (type II tests) #> #> Effect DFn DFd F p p<.05 ges #> 1 block 4 12 4.959 0.014 * 0.623 #> 2 N 1 12 12.259 0.004 * 0.505 #> 3 P 1 12 0.544 0.475 0.043 #> 4 K 1 12 6.166 0.029 * 0.339 #> 5 N:P 1 12 1.378 0.263 0.103 #> 6 N:K 1 12 2.146 0.169 0.152 #> 7 P:K 1 12 0.031 0.863 0.003 #> 8 N:P:K 0 12 NA NA NA ``` -------------------------------- ### Show the significance levels Source: https://github.com/kassambara/rstatix/blob/master/docs/index.html Show the significance levels of the correlation matrix. ```R # Show the significance levels cor.mat %>% cor_get_pval() ``` -------------------------------- ### Summary statistics of some selected variables Source: https://github.com/kassambara/rstatix/blob/master/docs/index.html Calculate common summary statistics for selected variables in the iris dataset. ```R # Summary statistics of some selected variables #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: iris %>% get_summary_stats(Sepal.Length, Sepal.Width, type = "common") ``` -------------------------------- ### T-test Source: https://github.com/kassambara/rstatix/blob/master/README.md Performing a t-test and visualizing the results with p-value annotations and a horizontal mean line. ```r # T-test stat.test <- df %>% t_test(len ~ dose, ref.group = "all") stat.test #> # A tibble: 3 × 10 #> .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif #> * #> 1 len all 0.5 60 20 5.82 56.4 2.90e-7 8.70e-7 **** #> 2 len all 1 60 20 -0.660 57.5 5.12e-1 5.12e-1 ns #> 3 len all 2 60 20 -5.61 66.5 4.25e-7 8.70e-7 **** # Box plot with horizontal mean line ggboxplot(df, x = "dose", y = "len") + stat_pvalue_manual( stat.test, label = "p.adj.signif", y.position = 35, remove.bracket = TRUE ) + geom_hline(yintercept = mean(df$len), linetype = 2) ``` -------------------------------- ### Example Usage Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/cor_mark_significant.html An example demonstrating how to use cor_mark_significant on the mtcars dataset after calculating a correlation matrix. ```R mtcars %>% select(mpg, disp, hp, drat, wt, qsec) %>% cor_mat() %>% cor_mark_significant() #> rowname mpg disp hp drat wt qsec #> 1 mpg #> 2 disp -0.85**** #> 3 hp -0.78**** 0.79**** #> 4 drat 0.68**** -0.71**** -0.45** #> 5 wt -0.87**** 0.89**** 0.66**** -0.71**** #> 6 qsec 0.42* -0.43* -0.71**** 0.091 -0.17 ``` -------------------------------- ### Example usage of box_m Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/box_m.html An example demonstrating how to use the box_m function with the iris dataset. ```R data(iris) box_m(iris[, -5], iris[, 5]) #> # A tibble: 1 × 4 #> statistic p.value parameter method #> #> 1 141. 3.35e-20 20 Box's M-test for Homogeneity of Covariance Matri… ``` -------------------------------- ### Grouped Data Example Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/dunn_test.html An example demonstrating Dunn's test on grouped data from the ToothGrowth dataset. ```R ToothGrowth %>% group_by(supp) %>% dunn_test(len ~ dose) #> # A tibble: 6 × 10 #> supp .y. group1 group2 n1 n2 statistic p p.adj p.adj…¹ #> * #> 1 OJ len 0.5 1 10 10 2.83 0.00459 0.00918 ** #> 2 OJ len 0.5 2 10 10 4.22 0.0000245 0.0000734 **** #> 3 OJ len 1 2 10 10 1.39 0.166 0.166 ns #> 4 VC len 0.5 1 10 10 2.62 0.00887 0.0177 * #> 5 VC len 0.5 2 10 10 5.01 0.000000557 0.00000167 **** #> 6 VC len 1 2 10 10 2.39 0.0169 0.0177 * #> # … with abbreviated variable name ¹​p.adj.signif ``` -------------------------------- ### Grouped summary statistics Source: https://github.com/kassambara/rstatix/blob/master/docs/index.html Calculate mean and standard deviation for Sepal.Length, grouped by Species. ```R # Grouped data #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: iris %>% group_by(Species) %>% get_summary_stats(Sepal.Length, type = "mean_sd") ``` -------------------------------- ### Load data Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/factorial_design.html This snippet demonstrates how to load the ToothGrowth dataset and view its initial rows. ```R data("ToothGrowth") df <- ToothGrowth head(df) ``` -------------------------------- ### Compute full summary statistics but show only selected statistics Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_summary_stats.html Example of computing full summary statistics but filtering the output to show only mean, sd, median, and iqr. ```R ToothGrowth %>% get_summary_stats(len, show = c("mean", "sd", "median", "iqr")) #> # A tibble: 1 × 6 #> variable n mean sd median iqr #> #> 1 len 60 18.8 7.65 19.2 12.2 ``` -------------------------------- ### Select Columns in a Data Frame Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/df_select.html This example demonstrates how to select columns from a data frame using the df_select function. It shows both standard evaluation using the 'vars' argument and non-standard evaluation by directly passing column names. ```R df <- head(ToothGrowth) df #> len supp dose #> 1 4.2 VC 0.5 #> 2 11.5 VC 0.5 #> 3 7.3 VC 0.5 #> 4 5.8 VC 0.5 #> 5 6.4 VC 0.5 #> 6 10.0 VC 0.5 # Select column using standard evaluation df %>% df_select(vars = c("dose", "len")) #> dose len #> 1 0.5 4.2 #> 2 0.5 11.5 #> 3 0.5 7.3 #> 4 0.5 5.8 #> 5 0.5 6.4 #> 6 0.5 10.0 # Select column using non-standard evaluation df %>% df_select(dose, len) #> dose len #> 1 0.5 4.2 #> 2 0.5 11.5 #> 3 0.5 7.3 #> 4 0.5 5.8 #> 5 0.5 6.4 #> 6 0.5 10.0 ``` -------------------------------- ### Display both SSn and SSd using detailed = TRUE Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/anova_summary.html Show generalized eta squared using effect.size = "ges". ```r # Display both SSn and SSd using detailed = TRUE # Show generalized eta squared using effect.size = "ges" anova_summary(res.anova, detailed = TRUE, effect.size = "ges") #> Effect SSn SSd DFn DFd F p p<.05 ges #> 1 dose 2426.434 712.106 2 54 92.000 4.05e-18 * 0.773 #> 2 supp 205.350 712.106 1 54 15.572 2.31e-04 * 0.224 #> 3 dose:supp 108.319 712.106 2 54 4.107 2.20e-02 * 0.132 ``` -------------------------------- ### Summary statistics for the whole data frame Source: https://github.com/kassambara/rstatix/blob/master/docs/index.html Calculate common summary statistics for all variables in the iris dataset. ```R # Whole data frame #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: iris %>% get_summary_stats(type = "common") ``` -------------------------------- ### Vector Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/make_clean_names.html Example of using make_clean_names on a character vector. ```R make_clean_names(c("a and b", "a-and-b")) #> [1] "a.and.b" "a.and.b" make_clean_names(1:10) #> [1] "X1" "X2" "X3" "X4" "X5" "X6" "X7" "X8" "X9" "X10" ``` -------------------------------- ### Data frame Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/make_clean_names.html Example of using make_clean_names on a data frame. ```R df <- data.frame( `a and b` = 1:4, `c and d` = 5:8, check.names = FALSE ) df #> a and b c and d #> 1 1 5 #> 2 2 6 #> 3 3 7 #> 4 4 8 make_clean_names(df) #> a.and.b c.and.d #> 1 1 5 #> 2 2 6 #> 3 3 7 #> 4 4 8 ``` -------------------------------- ### convert_as_factor, set_ref_level, reorder_levels Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/factors.html Demonstrates the usage of convert_as_factor to convert variables to factors, set_ref_level to change the reference level, and reorder_levels to change the order of factor levels. ```R df <- tibble( group = c("a", "a", "b", "b", "c", "c"), time = c("t1", "t2", "t1", "t2", "t1", "t2"), value = c(5, 6, 1, 3, 4, 5) ) df ``` ```R result <- df %>% convert_as_factor(group, time) result ``` ```R levels(result$group) ``` ```R result <- result %>% set_ref_level("group", ref = "c") levels(result$group) ``` ```R result <- result %>% reorder_levels("group", order = c("b", "c", "a")) levels(result$group) ``` -------------------------------- ### Robust summary statistics Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/get_summary_stats.html Example of computing robust summary statistics for a variable. ```R ToothGrowth %>% get_summary_stats(len, type = "robust") #> # A tibble: 1 × 4 #> variable n median iqr #> #> 1 len 60 19.2 12.2 ``` -------------------------------- ### R base function t.test() usage Source: https://github.com/kassambara/rstatix/blob/master/docs/reference/doo.html Shows how to use the base R 't.test' function with 'doo' when it's not pipe-friendly. ```R comparisons <- ToothGrowth %>% group_by(dose) %>% doo(~t.test(len ~ supp, data =.)) ```