双总体t检验是检验两个样本平均数与其各自所代表的总体的差异是否显著。 如果有样本X和样本Y分别来自两个总体的样本,总体的方差相同且未知,计算两样本t统计量。由统计量知识知,t统计量的计算公式为: 在R中,t统计量函数为: t.stat <- function(x,y){ # calculate the length of sample x and sample y n1 <- length(x); n2 <- length(y); # calculate the mean of sample x and sample y xb <- mean(x); yb <- mean(y); # calculate the variance of sample x and sample y Sx2 <- var(x); Sy2 <- var(y); S <- ((n1-1)*Sx2+(n2-1)*Sy2)/(n1+n2-2); (xb-yb)/sqrt(S*(1/n1+1/n2)); } |
|