Skip to content

Instantly share code, notes, and snippets.

@benmarwick
Created December 30, 2018 06:47
Show Gist options
  • Save benmarwick/8ce1fdf0b0fa7cd79ad99d2db815ae27 to your computer and use it in GitHub Desktop.
Save benmarwick/8ce1fdf0b0fa7cd79ad99d2db815ae27 to your computer and use it in GitHub Desktop.
# 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