Created
December 30, 2018 06:47
-
-
Save benmarwick/8ce1fdf0b0fa7cd79ad99d2db815ae27 to your computer and use it in GitHub Desktop.
t-test report code from http://my.ilstu.edu/~wjschne/444/IndependentSamples.html#(19)
This file contains hidden or 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
# from http://my.ilstu.edu/~wjschne/444/IndependentSamples.html#(19) | |
t.report <- function(tt){ | |
tvalue <- tt$statistic %>% formatC(digits = 2, format = "f") | |
pvalue <- tt$p.value %>% formatC(digits = 2, format = "f") | |
if (round(tt$parameter, 0) == tt$parameter) { | |
df <- tt$parameter | |
} else { | |
df <- formatC(digits = 2, format = "f") | |
} | |
if (tt$p.value < 0.0005) { | |
pvalue <- " < 0.001" | |
} else { | |
if (tt$p.value < 0.005) { | |
pvalue <- paste0(" = ",tt$p.value %>% formatC(digits = 3, format = "f")) | |
} else { | |
pvalue <- paste0(" = ",tt$p.value %>% formatC(digits = 2, format = "f")) | |
} | |
} | |
paste0("*t*(",df,") = ",tvalue, ", *p*", pvalue) | |
} | |
# This: | |
# As seen in Table 1 and Figure 1, the mean of Group 2 is significantly higher than the mean of Group 2, `r t.report(tt)`. | |
# Becomes: | |
# As seen in Table 1 and Figure 1, the mean of Group 2 is significantly higher than the mean of Group 2, t(143) = -5.88, p < 0.001. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment