#----------------------------------------------------------------------------
# Two-Sample Design
# Example 1a: Two-sided two-sample Welch-test
test.welch(mpg ~ vs, data = mtcars)
# Example 1b: One-sided two-sample Welch-test
test.welch(mpg ~ vs, data = mtcars, alternative = "greater")
# Example 1c: Two-sided two-sample Welch-test
# print Cohen's d with weighted pooled SD
test.welch(mpg ~ vs, data = mtcars, effsize = TRUE)
# Example 1d: Two-sided two-sample Welch-test
# plot results
test.welch(mpg ~ vs, data = mtcars, plot = TRUE)
# Load ggplot2 package
library(ggplot2)
if (FALSE) {
# Save plot, ggsave() from the ggplot2 package
ggsave("Two-sample_Welch-test.png", dpi = 600, width = 4, height = 6)}
# Example 1e: Two-sided two-sample Welch-test
# extract plot
p <- test.welch(mpg ~ vs, data = mtcars, output = FALSE)$plot
p
# Example 1f: Two-sided two-sample Welch-test
# Draw plot in line with the default setting of test.welch()
# Extract data
plotdat <- test.welch(mpg ~ vs, data = mtcars, output = FALSE)$data
# Draw plot
ggplot(plotdat, aes(factor(group), y)) +
geom_point(stat = "summary", fun = "mean", size = 4) +
stat_summary(fun.data = "mean_cl_normal", geom = "errorbar", width = 0.20) +
scale_x_discrete(name = NULL) +
labs(subtitle = "Two-Sided Confidence Interval") +
theme_bw() + theme(plot.subtitle = element_text(hjust = 0.5))
#----------------------------------------------------------------------------
# Multiple-Sample Design
# Example 2a: Welch's ANOVA
test.welch(mpg ~ gear, data = mtcars)
# Example 2b: Welch's ANOVA
# print eta-squared and omega-squared
test.welch(mpg ~ gear, data = mtcars, effsize = TRUE)
# Example 2c: Welch's ANOVA, plot results
test.welch(mpg ~ gear, data = mtcars, plot = TRUE)
# Load ggplot2 package
library(ggplot2)
if (FALSE) {
# Save plot, ggsave() from the ggplot2 package
ggsave("Multiple-sample_Welch-test.png", dpi = 600, width = 4.5, height = 6)}
# Example 2e: Welch's ANOVA
# extract plot
p <- test.welch(mpg ~ gear, data = mtcars, output = FALSE)$plot
p
# Example 2e: Welch's ANOVA
# Draw plot in line with the default setting of test.welch()
# Extract data
plotdat <- test.welch(mpg ~ gear, data = mtcars, output = FALSE)$data
# Draw plot
ggplot(plotdat, aes(group, y)) +
geom_point(stat = "summary", fun = "mean", size = 4) +
stat_summary(fun.data = "mean_cl_normal", geom = "errorbar", width = 0.20) +
scale_x_discrete(name = NULL) +
labs(subtitle = "Two-Sided Confidence Interval") +
theme_bw() + theme(plot.subtitle = element_text(hjust = 0.5))
Run the code above in your browser using DataLab