第 5 章 AB-test

Code
x=rnorm(100,100,4)
sigma=rnorm(100)
y=2+x+sigma
max(x,y)
## [1] 111.4
Code
min(x,y)
## [1] 91.05
Code
plot(x,ylim=c(min(x,y)-2,max(x,y)+2))
points(y,col='red')
abline(h=mean(y),col="red")
abline(h=mean(x))

Code
t.test(x,y)
## 
##  Welch Two Sample t-test
## 
## data:  x and y
## t = -3.5, df = 198, p-value = 6e-04
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.9923 -0.8392
## sample estimates:
## mean of x mean of y 
##      99.8     101.7
Code
t.test(x,y,paired = T)
## 
##  Paired t-test
## 
## data:  x and y
## t = -17, df = 99, p-value <2e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -2.137 -1.694
## sample estimates:
## mean difference 
##          -1.916
Code
library(pwrss)
t.test(y,x)
## 
##  Welch Two Sample t-test
## 
## data:  y and x
## t = 3.5, df = 198, p-value = 6e-04
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.8392 2.9923
## sample estimates:
## mean of x mean of y 
##     101.7      99.8
Code
design_2means=pwrss.t.2means(mu1=mean(x), mu2=mean(y), sd1=sd(x), sd2=sd(y), alpha=0.05, power=0.8, alternative="less")
##  Difference between Two means 
##  (Independent Samples t Test) 
##  H0: mu1 = mu2 
##  HA: mu1 < mu2 
##  ------------------------------ 
##   Statistical power = 0.8 
##   n1 = 51 
##   n2 = 51 
##  ------------------------------ 
##  Alternative = "less" 
##  Degrees of freedom = 100 
##  Non-centrality parameter = -2.506 
##  Type I error rate = 0.05 
##  Type II error rate = 0.2
Code
plot(design_2means)

重复测量Repeated-Measure Design 集群随机化Cluster Randomization
差中差估计Difference in Differences