#' A function to perform a two-sample t-test based on summary, not replicate values.
#'
#' @param m1,m2,s1,s2,n1,n2,m0,equal.variance
#' @keywords data_processing
#' @export
#' @examples
#' t.test2()
t.test2 <- function(m1,m2,s1,s2,n1,n2,m0=0,equal.variance=FALSE){
if( equal.variance==FALSE )
{
se <- sqrt( (s1^2/n1) + (s2^2/n2) )
# welch-satterthwaite df
df <- ( (s1^2/n1 + s2^2/n2)^2 )/( (s1^2/n1)^2/(n1-1) + (s2^2/n2)^2/(n2-1) )
} else
{
# pooled standard deviation, scaled by the sample sizes
se <- sqrt( (1/n1 + 1/n2) * ((n1-1)*s1^2 + (n2-1)*s2^2)/(n1+n2-2) )
df <- n1+n2-2
}
t <- (m1-m2-m0)/se
dat <- c(m1-m2, se, t, 2*pt(-abs(t),df))
names(dat) <- c("Difference of means", "Std Error", "t", "p-value")
return(dat)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.