Created
July 27, 2016 10:55
-
-
Save guidocor/8c7772b54519ee61aae90091232987e7 to your computer and use it in GitHub Desktop.
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
# helper function that makes a correlation | |
# Computes correlation between x and y and returns a list with the | |
# correlation object and the text as APA states to report it | |
# Also, the function prints the result, you can change this behavior with silent = FALSE | |
# Correlation reporting in APA Style: http://my.ilstu.edu/~jhkahn/apastats.html | |
# Brackets of CI in APA Style: http://blog.apastyle.org/apastyle/2010/06/formatting-statistics-using-brackets.html | |
correlation <- function(x,y, silent = TRUE, my.method="pearson") { | |
obj <- cor.test(x,y,method = my.method ) | |
apa <- paste0("r(", round(obj$parameter, 2) ,") = ", round(obj$estimate,2) , ", p < ", round(obj$p.value, 4) , | |
", 95% CI ","[",round(obj$conf.int[1], 2), ", ", round(obj$conf.int[2], 2), "]" ) | |
if(silent == FALSE) cat(apa) | |
return(list(cor = obj, text = apa)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment