R Language Learning Note (eight): efficacy analysis

Source: Internet
Author: User

T detection #计算期望的样本大小install. Packages ("PWR") library (PWR) pwr.t.test (d=.8,sig.level=.05,power=.9,type= "Two.sample")

Two-sample T Test power calculation

n = 33.82555 #样本大小
D = 0.8 #效应值, the difference between standardized mean values
Sig.level = 0.05 #显著水平
Power = 0.9 #功效水平, how much success to measure the effect
Alternative = two.sided #检测类型, selectable type: dual-sided or single-sided detection

Note:n is number in *each* group

#在固定的样本大小内, the correct range of results pwr.t.test (n=20,d=.5,sig.level =. 01,type= "Two.sample")

Two-sample T Test power calculation

n = 20
D = 0.5
Sig.level = 0.01
Power = 0.1439551
Alternative = two.sided

Note:n is number in *each* group

#方差分析, expect sample size pwr.anova.test (K=5,f=.25,sig.level =. 05,power=.8)

Balanced one-way analysis of variance power calculation

K = 5 #分组数量
n = 39.1534 #每组的数据量
f = 0.25 #效应值,
Sig.level = 0.05 #显著水平
Power = 0.8 #功效

Note:n is number in each group

#相关性, expect sample size pwr.r.test (R=.25,sig.level =. 05,power=.90,alternative = "Greater")

Approximate correlation power calculation (Arctangh transformation)

n = 133.2803 #样本大小
R = 0.25 #效应值
Sig.level = 0.05 #显著水平
Power = 0.9 #功效值
Alternative = Greater

#线性模型, the desired sample size, n-k-1= sample size pwr.f2.test (U=3,f2=0.0769,sig.level =0.05,power=0.90)

Multiple regression power calculation

U = 3 #集合只差
v = 184.2426 #N-The total number of variables -1=v--=v+ Total variables +1
F2 = 0.0769 #效应值
Sig.level = 0.05 #显著性
Power = 0.9 #功效值


#比例检测, expect sample size pwr.2p.test (H=es.h (. 65,.6), Sig.level =. 05,power=.9,alternative = "Greater")


Difference of proportion power calculation for binomial distribution (arcsine transformation)

H = 0.1033347 #效应值
n = 1604.007 #样本大小
Sig.level = 0.05 #显著水平
Power = 0.9 #功效值
Alternative = Greater #测试类型, double-tailed or single-tailed

Note:same Sample Sizes

#卡方检验, expect sample size Prob<-matrix (C (. 42,.28,.03,.07,.10,.10), byrow=true,nrow=3) es.w2 (prob) pwr.chisq.test (W=ES.W2 ( Prob), df=2,sig.level=.05,power=.9)


Chi Squared Power Calculation

W = 0.1853198 #效应值
N = 368.4528 #样本大小
DF = 2 #自由度
Sig.level = 0.05
Power = 0.9

Note:n is the number of observations

The sample size required for detecting significant effects in single factor Anova es<-seq (. 1,.5,.01) Nes<-length (es) samsize<-null for (i in 1:nes) {   result<- Pwr.anova.test (k=5,f=es[i],sig.level =. 05,power=.9)   samsize[i]<-ceiling (result$n)}  plot (Samsize,es, Type= "L", lwd=2,col= "Red", ylab= "Effect Szie", xlab= "Sample Szie (per cell)", main= "one-by-one" Anova with power=.90 and alpha=. 05 ")   

R<-seq (. 1,.5,.01) #在. 1 and. 5 generate a numeric sequence with a. 01 Step nr<-length (R)   p<-seq (. 4,.9,.1) Np<-length (p)  samsize <-array (Numeric (NR*NP), Dim=c (NR,NP)) #samsize for (i-1:NP) {for   (J-in 1:nr)   {     result<-pwr.r.test ( N=null,r=r[j],sig.level =. 05,power = p[i],alternative = "two.sided")     samsize[j,i]<-ceiling (result$n)             }    }# samsize  xrange<-range (R) Yrange<-round (range (samsize)) Colors<-rainbow (length (p)) plot (xrange , yrange,type= "n", xlab= "Correlation coefficient (R)", ylab= "Sample Size (N)") for  (i in 1:NP) {   lines (r,samsize [, I],type= "L", Lwd=2,col=colors[i])}  abline (V=0,h=seq (0,yrange[2],50), lty=2,col= "grey89") Abline (H=0,v=seq ( xrange[1],xrange[2],.02), lty=2,col= "gray89") title ("Sample Szie estimation for Correlation studies\n") Legend (" TopRight ", title=" Power ", As.character (p), fill=colors)

What is the significance of the test

The thought of the significance test is very simple, that is, the small probability event cannot occur. Although we have always stressed that the small probability event must occur in probability theory, the significance test still believes that the small probability event did not occur in the test I did.

The significance test is used to determine whether there is a difference between the experimental treatment group and the control group or the effects of the two different treatments, and whether the difference is significant.

A hypothesis that is to be tested is often referred to as H0, which is called the original hypothesis (or 0 hypothesis), and H0 's contradictory hypothesis is H1, called the alternative hypothesis.

⑴ when the original hypothesis is true, decides to abandon the original hypothesis, called the first kind of error, the probability of its occurrence is usually recorded as α;

⑵ in the original hypothesis, the decision to accept the original hypothesis, called the second type of error, the probability of its occurrence is usually recorded as beta.

usually only the maximum probability α of the first type of error is defined, and the probability of the second type of error is not considered beta. This hypothesis test is also called the significance test, and the probability α is called the significance level.

R Language Learning Note (eight): efficacy analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.