#' Paired-samples t test
#'
#' @description Performs paired-samples t tests. The function delegates the
#' primary computations to \code{\link[stats]{t.test}}.
#'
#' @param dv1,dv2 Column vectors containing the dependent variables
#'
#' @seealso \code{\link[stats]{t.test}}
#'
#' @examples
#' wrap.t.pair(dv1 = bdata$DV1, dv2 = bdata$DV2)
#'
#' @import effsize stringr stats
#' @export
wrap.t.pair <- function(dv1, dv2) {
options(scipen=999)
# Error checks
if(is.null(dv1)) {return(paste("Cannot find the column vector inputted to parameter dv1."))}
if(is.null(dv2)) {return(paste("Cannot find the column vector inputted to parameter dv2."))}
if(is.null(dv1)==F) {if(is.numeric(dv1)==F) {return("Argument dv1 must be numeric.")}}
if(is.null(dv2)==F) {if(is.numeric(dv2)==F) {return("Argument dv2 must be numeric.")}}
## t-test results
a <- t.test(dv1, dv2, alternative = "two.sided", mu = 0, paired=T, conf.level = 0.95)
# cohen's d
b <- (cohen.d(dv1,dv2,paired=T,na.rm=T)$estimate)
if(a$p.value < .001) {
wrap.writeClipboard(paste("# paired t(",a$parameter,") = ",wrap.rd0(a$statistic,2),", p < .001, 95% CIdifference = [",wrap.rd0(a$conf.int[1],2),", ",wrap.rd0(a$conf.int[2],2),"], d = ",wrap.rd0(b,2),sep=""))
return(cat("\n","# paired t(",a$parameter,") = ",wrap.rd0(a$statistic,2),", p < .001, 95% CIdifference = [",wrap.rd0(a$conf.int[1],2),", ",wrap.rd0(a$conf.int[2],2),"], d = ",wrap.rd0(b,2),sep=""))
}
else {
wrap.writeClipboard(paste("# paired t(",a$parameter,") = ",wrap.rd0(a$statistic,2),", p = ",wrap.rd(a$p.value,3),", 95% CIdifference = [",wrap.rd0(a$conf.int[1],2),", ",wrap.rd0(a$conf.int[2],2),"], d = ",wrap.rd0(b,2),sep=""))
return(cat("\n","# paired t(",a$parameter,") = ",wrap.rd0(a$statistic,2),", p = ",wrap.rd(a$p.value,3),", 95% CIdifference = [",wrap.rd0(a$conf.int[1],2),", ",wrap.rd0(a$conf.int[2],2),"], d = ",wrap.rd0(b,2),sep=""))
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.