首页 > > 详细

辅导R语言程序、R设计讲解、讲解Python、C/C++ Assignment解析

# This program "Paper-Table3.r" is written by Huan Yin, Weizhen Wang, and
# Zhongzhan Zhang. All rights reserved.
# 1. This program computes the expected sample size, type I error rate and power
# in Section 3 of the paper "On Construction of Two-Stage Designs with
# Consideration of Both Response and Toxicity" (Yin, Wang and Zhang). It confirms
# the results in Table 3.
# 2. The expected sample size, type I error rate and power are computed with data (X and Y),
# where X=(X11,X10,X01) is a multinomial variable Multinom(n1,p) in Stage I, and
# Y=(Y11,Y10,Y01) is Multinom(n2,p) in Stage II for p=(p11,p10,p01).
# Two probabilities, the probability of response pr=p11+p10 and the probability of nontoxcity
# pt=p11+p01, are introduced in Table 1.
# 3. The rejection region is R_m (Case A).
# P(R_A) = P( X11+X10>=ar, X11+X10+Y11+Y10>=cr, X11+X01>=at, X11+X01+Y11+Y01>=ct)
# 4. The expected sample size in H0 is calculated at two points, p*r0 and p*t0 (introduced
# in Theorem 2) , and we record the larger value.
# The maximum type I error rate of the test R_m is achieved at two points, p*r0 and p*t0, and
# we record the larger one.
# The minimum power is at a line p*A, introduced in Theorem 3.
# Here, (pr,pt,p11)=(pr0,1,pr0)=p*r0 and (pr,pt,p11)=(1,pt0,pt0)=p*t0.
# 5. The input is f(pr0,pt0,pr1,pt1,n1,ar,at,n2,cr,ct),
# a function of pr0, pt0, pr1, pt1, n1, ar, at, n2, cr, ct,
# where
# a) pr0,pt0,pr1,pt1, for four boundries of hypotheses in (1) of the paper;
# b) n1, for the sample size in Stage I;
# c) n2, for the sample size in Stage II;
# d) ar and at, for moving into Stage II from Stage I. i.e., if Xr belongs to
# [ar,n1) or Xt belongs to [at,n1), the trial moves into Stage II;
# e) cr and ct, for the Stage II critical values.
# 6. The three output values include:
# a) the bigger value of the expected sample sizes at p*r0 and p*t0;
# b) the maximum type I error rate;
# c) the minimum power.
# 7. For example,
# input: f(0.5,0.7,0.7,0.9,14,8,11,26,24,33)
# output: 24.2768555 0.1074260 0.8026355
RES1)|any(prob 1)
stop("Sum of 'P' must not be greater than 1.")
if(any( Rn]=n+1
sump=0
if(R[1]1]=1
for(i in (0:r1))
{
if(b==1) sump n)return(0)

if((j*r)==n)
{
pj =ar x11+x01>=at) {sam=rbind(sam,c(x11,x10,x01,x00))}
}
}
sam
}

SS1=ar Xt>=at
SS1=ar x11+x01>=at) {sam=rbind(sam,c(x11,x10,x01,x00))}
}
}
}
sam
}


SSS1=ar Xt>=at
SSS1=1-beta)
# RESS<-RES[aa,]
# if(length(aa)==1) RESS<-matrix(RESS,ncol =3,byrow =T)
# bb<-min(RESS[,1])
# cc<-which(RESS[,1]==bb)
# RESS<-RESS[cc,]
# RESS
#####################
# Jin's #
#####################
tim=Sys.time()
f(0.5,0.7,0.7,0.9,15,9,12,29,25,36) # this is the output of the expected sample size, type I error and power
Sys.time()-tim
# EN TypeIerror Power
# [1,] 23.80496 0.140913 0.7927383
tim=Sys.time()
f(0.5,0.7,0.7,0.9,20,12,16,16,21,30) # this is the output of the expected sample size, type I error and power
Sys.time()-tim
# [1] 24.0275574 0.1400109 0.7955622
tim=Sys.time()
f(0.5,0.7,0.7,0.9,14,8,11,26,24,33) # this is the output of the expected sample size, type I error and power
Sys.time()-tim
# [1,] 24.27686 0.107426 0.8026355
 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!