dat1 <- data.frame(group1 = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2),
group2 = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3),
y = c(3, 1, 4, 2, 5, 3, 2, 3, 6, 6, 3, NA))
#--------------------------------------
# Two-Sample Design
# Two-sided two-sample Welch-test
test.welch(y ~ group1, data = dat1)
# One-sided two-sample Welch-test
test.welch(y ~ group1, data = dat1, alternative = "greater")
# Two-sided two-sample Welch-test
# print Cohen's d with weighted pooled SD
test.welch(y ~ group1, data = dat1, effsize = TRUE)
# Two-sided two-sample Welch-test
# print Cohen's d with unweighted pooled SD
test.welch(y ~ group1, data = dat1, effsize = TRUE, weighted = FALSE)
# Two-sided two-sample Welch-test
# print Cohen's d with weighted pooled SD and
# small sample correction factor
test.welch(y ~ group1, data = dat1, effsize = TRUE, correct = TRUE)
# Two-sided two-sample Welch-test
# print Cohen's d with SD of the reference group 1
test.welch(y ~ group1, data = dat1, effsize = TRUE,
ref = 1)
# Two-sided two-sample Welch-test
# print Cohen's d with weighted pooled SD and
# small sample correction factor
test.welch(y ~ group1, data = dat1, effsize = TRUE,
correct = TRUE)
# Two-sided two-sample Welch-test
# do not print hypotheses and descriptive statistics,
test.welch(y ~ group1, data = dat1, descript = FALSE, hypo = FALSE)
# Two-sided two-sample Welch-test
# print descriptive statistics with 3 digits and p-value with 5 digits
test.welch(y ~ group1, data = dat1, digits = 3, p.digits = 5)
if (FALSE) {
# Two-sided two-sample Welch-test
# plot results
test.welch(y ~ group1, data = dat1, plot = TRUE)
# Load ggplot2 package
library(ggplot2)
# Save plot, ggsave() from the ggplot2 package
ggsave("Two-sample_Welch-test.png", dpi = 600, width = 4, height = 6)
# Two-sided two-sample Welch-test
# extract plot
p <- test.welch(y ~ group1, data = dat1, output = FALSE)$plot
p
# Extract data
plotdat <- test.welch(y ~ group1, data = dat1, output = FALSE)$data
# Draw plot in line with the default setting of test.welch()
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 95% Confidence Interval") +
theme_bw() + theme(plot.subtitle = element_text(hjust = 0.5))
}
#--------------------------------------
# Multiple-Sample Design
# Welch's ANOVA
test.welch(y ~ group2, data = dat1)
# Welch's ANOVA
# print eta-squared and omega-squared
test.welch(y ~ group2, data = dat1, effsize = TRUE)
# Welch's ANOVA
# do not print hypotheses and descriptive statistics,
test.welch(y ~ group2, data = dat1, descript = FALSE, hypo = FALSE)
if (FALSE) {
# Welch's ANOVA
# plot results
test.welch(y ~ group2, data = dat1, plot = TRUE)
# Load ggplot2 package
library(ggplot2)
# Save plot, ggsave() from the ggplot2 package
ggsave("Multiple-sample_Welch-test.png", dpi = 600, width = 4.5, height = 6)
# Welch's ANOVA
# extract plot
p <- test.welch(y ~ group2, data = dat1, output = FALSE)$plot
p
# Extract data
plotdat <- test.welch(y ~ group2, data = dat1, output = FALSE)$data
# Draw plot in line with the default setting of test.welch()
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 95% Confidence Interval") +
theme_bw() + theme(plot.subtitle = element_text(hjust = 0.5))
}
Run the code above in your browser using DataLab