Created
February 21, 2019 18:29
-
-
Save jvcasillas/72038db7c8f87d9d0ec0899b2c9cb90d to your computer and use it in GitHub Desktop.
Example of two one-sided t tests (to test equivalence)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load libraries | |
library("tidyverse") | |
library("TOSTER") | |
# Set seed for reproducibility | |
set.seed(10) | |
# Working memory means for 3 groups | |
wm_n <- rnorm(mean = 8.67, sd = 1.15, n = 12) | |
wm_nin <- rnorm(mean = 9.04, sd = 2.11, n = 26) | |
wm_m <- rnorm(mean = 9.16, sd = 1.93, n = 25) | |
# Create DF | |
my_df <- c( | |
rep("n", 12), | |
rep("nin", 26), | |
rep("m", 25)) %>% | |
as_data_frame(.) %>% | |
rename(., group = value) %>% | |
bind_cols(., | |
wm = c(rnorm(mean = 8.67, sd = 1.15, n = 12), # in | |
rnorm(mean = 9.04, sd = 2.11, n = 26), # nin | |
rnorm(mean = 9.16, sd = 1.93, n = 25) # m | |
), | |
dele = c(rnorm(mean = 49.17, sd = 4.43, n = 12), # in | |
rnorm(mean = 46.27, sd = 4.09, n = 26), # nin | |
rep(0, 25) # m | |
) | |
) | |
# Check means | |
my_df %>% | |
group_by(., group) %>% | |
summarize(., wm_mean = mean(wm), | |
wm_sd = sd(wm), | |
dele_mean = mean(dele), | |
dele_sd = sd(dele), | |
n = n()) | |
# Bartlet test of homogeneity of variance | |
bartlett.test(wm ~ group, data = my_df) | |
# Bartlett's K-squared = 4.778, df = 2, p-value = 0.09172 | |
# wm toast m vs nin | |
TOSTtwo(m1 = 9.16, sd1 = 1.93, n1 = 25, # m | |
m2 = 9.04, sd2 = 2.11, n2 = 25, # nin | |
low_eqbound_d = -0.4, | |
high_eqbound_d = 0.4, | |
alpha = 0.05) | |
# wm toast m vs in | |
TOSTtwo(m1 = 9.16, sd1 = 1.93, n1 = 25, # m | |
m2 = 8.67, sd2 = 1.15, n2 = 12, # n | |
low_eqbound_d = -0.3, | |
high_eqbound_d = 0.3, | |
alpha = 0.05) | |
# wm toast in vs nin | |
TOSTtwo(m1 = 8.67, sd1 = 1.15, n1 = 12, # n | |
m2 = 9.04, sd2 = 2.11, n2 = 25, # nin | |
low_eqbound_d = -0.3, | |
high_eqbound_d = 0.3, | |
alpha = 0.05) | |
# dele toast in vs nin | |
TOSTtwo(m1 = 49.17, sd1 = 4.43, n1 = 12, # n | |
m2 = 46.27, sd2 = 4.09, n2 = 26, # nin | |
low_eqbound_d = -0.3, | |
high_eqbound_d = 0.3, | |
alpha = 0.05) | |
# Furthermore, the TOST procedure suggested that the observed effects were | |
# statistically not different from zero for all pairwise comparisons for | |
# working memory | |
# (M vs. N: t(47.62) = -1.204, p = 0.117; | |
# M vs. NIN: t(33.11) = 0.0263, p = 0.510; | |
# N vs. NIN: t(34.26) = 0.260, p = 0.398) | |
# and for L2 proficiency | |
# (N vs. NIN: t(20) = 1.074, p = 0.852) | |
# TOST for lexical frequency | |
lex_df <- structure(list(target = c("corta", "firma", "grita", "lleva", | |
"llena", "manda", "graba", "gasta", "bebe", "come", "busca", | |
"llama", "besa", "mira", "vive", "compra", "vende", "lava", "fuma", | |
"pinta", "toca", "limpia", "cambia", "corto", "firmo", "grito", | |
"llevo", "lleno", "mando", "grabo", "gasto", "bebio", "comio", | |
"busco", "llamo", "beso", "miro", "vivio", "compro", "vendio", | |
"lavo", "fumo", "pinto", "toco", "limpio", "cambio"), freq = c(203, | |
174, 77, 765, 371, 110, 10, 41, 50, 87, 468, 631, 28, 547, 417, | |
197, 72, 45, 38, 87, 125, 92, 128, 62, 47, 182, 402, 61, 89, | |
9, 14, 53, 23, 90, 240, 62, 486, 105, 72, 23, 10, 12, 17, 105, | |
26, 109)), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame" | |
), row.names = c(NA, -46L), spec = structure(list(cols = list( | |
target = structure(list(), class = c("collector_character", | |
"collector")), freq = structure(list(), class = c("collector_double", | |
"collector"))), default = structure(list(), class = c("collector_guess", | |
"collector")), skip = 1), class = "col_spec")) | |
coda_words <- c("corta", "firma", "manda", "gasta", "busca", "compra", | |
"vende", "pinta", "limpia", "cambia", "corto", "firmo", | |
"mando", "gasto", "busco", "compro", "vendio", "pinto", | |
"limpio", "cambio") | |
lex_df <- lex_df %>% | |
mutate(., coda = if_else(target %in% coda_words, 1, 0)) | |
bartlett.test(freq ~ coda, data = lex_df) | |
lex_df %>% | |
group_by(., coda) %>% | |
summarize(., freq_mean = mean(freq), | |
freq_sd = sd(freq), | |
n = n()) | |
# dele toast in vs nin | |
TOSTtwo(m1 = 190, sd1 = 220, n1 = 26, # n | |
m2 = 106, sd2 = 102, n2 = 20, # nin | |
low_eqbound_d = -0.3, | |
high_eqbound_d = 0.3, | |
alpha = 0.05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nicely explained :-) I think the first TOStwo has a small mistake in regards to the Cohen's D,
should be
right?