#install.packages("BSDA")
library(BSDA)
## 载入需要的程辑包:lattice
##
## 载入程辑包:'BSDA'
## The following object is masked from 'package:datasets':
##
## Orange
x <- rnorm(12)
tsum.test(mean(x), sd(x), n.x=12)
## Warning in tsum.test(mean(x), sd(x), n.x = 12): argument 'var.equal' ignored for
## one-sample test.
##
## One-sample t-Test
##
## data: Summarized x
## t = -0.779, df = 11, p-value = 0.4524
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## -0.8924867 0.4258752
## sample estimates:
## mean of x
## -0.2333058
t.test(x)
##
## One Sample t-test
##
## data: x
## t = -0.779, df = 11, p-value = 0.4524
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## -0.8924867 0.4258752
## sample estimates:
## mean of x
## -0.2333058
############################method_1_2
x <- c(7.8, 6.6, 6.5, 7.4, 7.3, 7.0, 6.4, 7.1, 6.7, 7.6, 6.8)
y <- c(4.5, 5.4, 6.1, 6.1, 5.4, 5.0, 4.1, 5.5)
tsum.test(mean(x), s.x=sd(x), n.x=length(x) ,mean(y), s.y=sd(y), n.y=length(y))
##
## Welch Modified Two-Sample t-Test
##
## data: Summarized x and y
## t = 6.1281, df = 11.303, p-value = 6.617e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 1.127160 2.384203
## sample estimates:
## mean of x mean of y
## 7.018182 5.262500
t.test(x, y)
##
## Welch Two Sample t-test
##
## data: x and y
## t = 6.1281, df = 11.303, p-value = 6.617e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 1.127160 2.384203
## sample estimates:
## mean of x mean of y
## 7.018182 5.262500
###########################method_3
t.test.from.summary.data <- function(mean1, sd1, n1, mean2, sd2, n2, ...) {
data1 <- scale(1:n1)*sd1 + mean1
data2 <- scale(1:n2)*sd2 + mean2
t.test(data1, data2, ...)
}
t.test.from.summary.data(mean(x), sd(x), length(x) ,mean(y), sd(y), length(y))
##
## Welch Two Sample t-test
##
## data: data1 and data2
## t = 6.1281, df = 11.303, p-value = 6.617e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 1.127160 2.384203
## sample estimates:
## mean of x mean of y
## 7.018182 5.262500
#ref https://stats.stackexchange.com/questions/30394/how-to-perform-two-sample-t-tests-in-r-by-inputting-sample-statistics-rather-tha
#https://stackoverflow.com/questions/5526922/r-t-test-from-n-mean-sd