# Written by: Xavier Basagana # Last modified: 11/08/2007 # Contents: # --------- # 1. General functions: # 1.1. Functions to get parameters # 1.2. Functions that compute the variance of the parameter of interest # 1.3. Auxiliary and other functions # # 2. Modules # 2.1. Module to compute power, "long.power()". # 2.1.1. Functions # 2.1.2. User interface # 2.1.3. Batch command # 2.1.4. Batch functions # 2.2. Module to compute sample size, "long.N()". # 2.2.1. Functions # 2.2.2. User interface # 2.2.3. Batch command # 2.2.4. Batch functions # 2.3. Module to compute minimum detectable effect, "long.effect()". # 2.3.1. Functions # 2.3.2. User interface # 2.3.3. Batch command # 2.3.4. Batch functions # 2.4. Module to compute number of repeated measures, "long.r()". # 2.4.1. Functions # 2.4.2. User interface # 2.4.3. Batch command # 2.4.4. Batch functions # 2.5. Module to compute optimal combination (N,r) under cost constraint, "long.opt()". # 2.5.1. Functions # 2.5.2. User interface # 2.5.3. Batch command # 2.5.4. Batch functions # # 3. Function to get the name of the batch function and the # necessary parameters #---- ----------------------- ##### ####################### # 1 # # General functions # ##### ####################### #---- ----------------------- ####### ################################ # 1.1 # # Functions to get parameters # ####### ################################ get.opt.problem=function(opt.problem.old) { message=paste("Do you want to maximize power subject to a given cost (1) or to \n minimize the total cost subject to a given power (2)[",opt.problem.old,"]? ",sep="") options(warn=-1) opt.problem.text=readline(message) if (opt.problem.text=="") { opt.problem=opt.problem.old cat("\n") } else { opt.problem=as.numeric(opt.problem.text) if ((opt.problem!=1 && opt.problem!=2) || is.na(opt.problem)==T) opt.problem=get.opt.problem(opt.problem.old) else { cat("\n") options(warn=0) } } return(opt.problem) } get.N=function(N.old) { message=paste("Enter the total sample size (N) [",N.old,"]: ",sep="") options(warn=-1) N.text=readline(message) if (N.text=="") { N=N.old cat("\n") } else { N=as.numeric(N.text) if (N<1 || is.na(N)==T) N=get.N(N.old) else { options(warn=0) cat("\n") } } return(N) } get.r=function(r.old) { if (r.old==-999 || r.old==-888) r.old=1 message=paste("Enter the number of post-baseline measures (r) [",r.old,"]: ",sep="") options(warn=-1) r.text=readline(message) if (r.text=="") { r=r.old cat("\n") } else { r=as.numeric(r.text) if (r<0 || is.na(r)==T) r=get.r(r.old) else { cat("\n") options(warn=0) } } return(r) } get.r.ldd=function(r.old) { message=paste("Enter the number of post-baseline measures (r>0) [",r.old,"]: ",sep="") options(warn=-1) r.text=readline(message) if (r.text=="") { r=r.old cat("\n") } else { r=as.numeric(r.text) if (r<1 || is.na(r)==T) r=get.r.ldd(r.old) else { cat("\n") options(warn=0) } } return(r) } get.Pi=function(Pi.old) { message=paste("Enter the desired power (0=1 || is.na(Pi)==T) Pi=get.Pi(Pi.old) else { cat("\n") options(warn=0) } } return(Pi) } get.fixed=function(fixed.old) { message=paste("Are you assuming the time between measurements (s) is fixed (1), or \n the total duration of follow-up (tau) is fixed (2) [",fixed.old,"]? ",sep="") options(warn=-1) fixed.text=readline(message) if (fixed.text=="") { fixed=fixed.old cat("\n") } else { fixed=as.numeric(fixed.text) if ((fixed!=1 && fixed!=2) || is.na(fixed)==T) fixed=get.fixed(fixed.old) else { cat("\n") options(warn=0) } } return(fixed) } get.s=function(s.old) { message=paste("Enter the time between repeated measures (s) [",s.old,"]: ",sep="") options(warn=-1) s.text=readline(message) if (s.text=="") { s=s.old cat("\n") } else { s=as.numeric(s.text) if (s<=0 || is.na(s)==T) s=get.s(s.old) else { cat("\n") options(warn=0) } } return(s) } get.tau=function(tau.old) { message=paste("Enter the time of follow-up (tau) [",tau.old,"]: ",sep="") options(warn=-1) tau.text=readline(message) if (tau.text=="") { tau=tau.old cat("\n") } else { tau=as.numeric(tau.text) if (tau<=0 || is.na(tau)==T) tau=get.tau(tau.old) else { cat("\n") options(warn=0) } } return(tau) } get.tv=function(tv.old) { message=paste("Is the exposure time-invariant (1) or time-varying (2) [",tv.old,"]? ",sep="") options(warn=-1) tv.text=readline(message) if (tv.text=="") { tv=tv.old cat("\n") } else { tv=as.numeric(tv.text) if ((tv!=1 && tv!=2) || is.na(tv)==T) tv=get.tv(tv.old) else { cat("\n") options(warn=0) } } return(tv) } get.pe.type=function(pe.type.old) { message=paste("Do you assume that the exposure prevalence is constant over time (1),\n that it changes linearly with time (2), or you want to enter the prevalence at\n each time point(3) [",pe.type.old,"]? ",sep="") options(warn=-1) pe.type.text=readline(message) if (pe.type.text=="") { pe.type=pe.type.old cat("\n") } else { pe.type=as.numeric(pe.type.text) if ((pe.type!=1 && pe.type!=2 && pe.type!=3) || is.na(pe.type)==T) pe.type=get.pe.type(pe.type.old) else { cat("\n") options(warn=0) } } return(pe.type) } get.pe=function(pe.old) { message=paste("Enter the exposure prevalence (pe) (0=1 || is.na(pe)==T) pe=get.pe(pe.old) else { cat("\n") options(warn=0) } } return(pe) } get.pe.tv=function(pe.type,r,pe.tv.old) { if (pe.type==1) { if (length(pe.tv.old)>1) pe.tv.old=pe.tv.old[1] message=paste("Enter the mean exposure prevalence (0=1 || is.na(pe.tv)==T) pe.tv=get.pe.tv(pe.type,r,pe.tv.old) else { cat("\n") options(warn=0) } } } else if (pe.type==2) { options(warn=-1) pe.tv.old=matrix(pe.tv.old,nrow=r+1,ncol=1) options(warn=0) pe0.old=pe.tv.old[1] per.old=pe.tv.old[r+1] pe0=get.pei(pe0.old,0) per=get.pei(per.old,r) slope=(per-pe0)/r times=0:r pe.tv=pe0+slope*times } else if (pe.type==3) { options(warn=-1) pe.tv.old=matrix(pe.tv.old,nrow=r+1,ncol=1) options(warn=0) pe.tv=matrix(0,nrow=r+1,ncol=1) for (i in 1:(r+1)) { pe.tv[i]=get.pei(pe.tv.old[i],i-1) } } return(pe.tv) } get.pei=function(pei.old,i) { message=paste("Enter the exposure prevalence at time ",i," (0=1 || is.na(pei)==T) pei=get.pei(pei.old,i) else { cat("\n") options(warn=0) } } return(pei) } get.rhoe=function(r,pe,rhoe.old) { if (length(pe)==1) pe=rep(pe,times=r+1) min.rhoe=round(rhox2rhoe(r,pe,lower.rhox(r,pe))*1000,digits=0)/1000 max.rhoe=round(rhox2rhoe(r,pe,upper.rhox(r,pe))*1000,digits=0)/1000 if (rhoe.oldmax.rhoe) rhoe.old=(max.rhoe+min.rhoe)/2 message=paste("Enter the intraclass correlation of exposure (",min.rhoe,"max.rhoe || is.na(rhoe)==T) rhoe=get.rhoe(r,pe,rhoe.old) else { cat("\n") options(warn=0) } } return(rhoe) } get.rhoe.no.r=function(rhoe.old) { message=paste("Enter the intraclass correlation of exposure (rho.e<=1)\n (lower bound is not checked since it depends on r) [",rhoe.old,"]: ",sep="") options(warn=-1) rhoe.text=readline(message) if (rhoe.text=="") { rhoe=rhoe.old cat("\n") } else { rhoe=as.numeric(rhoe.text) if (rhoe<(-1) || rhoe>1 || is.na(rhoe)==T) rhoe=get.rhoe.no.r(rhoe.old) else { cat("\n") options(warn=0) } } return(rhoe) } get.vt0=function(vt0.old) { message=paste("Enter the variance of the time variable at baseline, V(t0) \n (enter 0 if all participants begin at the same time) [",vt0.old,"]: ",sep="") options(warn=-1) vt0.text=readline(message) if (vt0.text=="") { vt0=vt0.old cat("\n") } else { vt0=as.numeric(vt0.text) if (vt0<0 || is.na(vt0)==T) vt0=get.vt0(vt0.old) else { cat("\n") options(warn=0) } } return(vt0) } get.rho.exp.t0=function(rho.exp.t0.old) { message=paste("Enter the correlation between the time variable at baseline and exposure,\n rho_{e,t0} [",rho.exp.t0.old,"]: ",sep="") options(warn=-1) rho.exp.t0.text=readline(message) if (rho.exp.t0.text=="") { rho.exp.t0=rho.exp.t0.old cat("\n") } else { rho.exp.t0=as.numeric(rho.exp.t0.text) if (rho.exp.t0<(-1) || rho.exp.t0>1 || is.na(rho.exp.t0)==T) rho.exp.t0=get.rho.exp.t0(rho.exp.t0.old) else { cat("\n") options(warn=0) } } return(rho.exp.t0) } get.pattern=function(pattern.old) { message=paste("Constant mean difference (1) or Linearly divergent difference (2) [",pattern.old,"]: ",sep="") options(warn=-1) pattern.text=readline(message) if (pattern.text=="") { pattern=pattern.old cat("\n") } else { pattern=as.numeric(pattern.text) if ((pattern!=1 && pattern!=2) || is.na(pattern)==T) pattern=get.pattern(pattern.old) else { cat("\n") options(warn=0) } } return(pattern) } get.model.cmd=function(model.cmd.old) { cat("Which model are you basing your calculations on: (1) Model without time. No separation of between- and within-subject effects (2) Model without time. Within-subject contrast only (3) Model with time. No separation of between- and within-subject effects (4) Model with time. Within-subject contrast only\n") message=paste("Model [",model.cmd.old,"]: ",sep="") options(warn=-1) model.cmd.text=readline(message) if (model.cmd.text=="") { model.cmd=model.cmd.old cat("\n") } else { model.cmd=as.numeric(model.cmd.text) if ((model.cmd!=1 && model.cmd!=2 && model.cmd!=3 && model.cmd!=4) || is.na(model.cmd)==T) model.cmd=get.model.cmd(model.cmd.old) else { cat("\n") options(warn=0) } } return(model.cmd) } get.model.ldd=function(model.ldd.old) { cat("Which model are you basing your calculations on: (1) Cumulative exposure effect model. No separation of between- and\n within-subject effects (2) Cumulative exposure effect model. Within-subject contrast only (3) Acute exposure effect model. No separation of between- and\n within-subject effects (4) Acute exposure effect model. Within-subject contrast only\n") message=paste("Model [",model.ldd.old,"]: ",sep="") options(warn=-1) model.ldd.text=readline(message) if (model.ldd.text=="") { model.ldd=model.ldd.old cat("\n") } else { model.ldd=as.numeric(model.ldd.text) if ((model.ldd!=1 && model.ldd!=2 && model.ldd!=3 && model.ldd!=4) || is.na(model.ldd)==T) model.ldd=get.model.ldd(model.ldd.old) else { cat("\n") options(warn=0) } } return(model.ldd) } get.notation=function(notation.old) { message=paste("Will you specify the alternative hypothesis on the absolute (beta coefficient) \n scale (1) or the relative (percent) scale (2) [",notation.old,"]? ",sep="") options(warn=-1) notation.text=readline(message) if (notation.text=="") { notation=notation.old cat("\n") } else { notation=as.numeric(notation.text) if ((notation != 1 && notation !=2) || is.na(notation)==T) notation=get.notation(notation.old) else { options(warn=0) cat("\n") } } return(notation) } get.notation2=function(notation.old) { message=paste("Do you want the output as a coefficient (1) or as a percent change (2) [",notation.old,"]? ",sep="") options(warn=-1) notation.text=readline(message) if (notation.text=="") { notation=notation.old cat("\n") } else { notation=as.numeric(notation.text) if ((notation != 1 && notation !=2) || is.na(notation)==T) notation=get.notation2(notation.old) else { cat("\n") options(warn=0) } } return(notation) } get.mu00=function(mu00.old) { if (mu00.old==-999) mu00.old=10 message=paste("Enter mean response at baseline among unexposed (mu00) [",mu00.old,"]: ",sep="") options(warn=-1) mu00.text=readline(message) if (mu00.text=="") { mu00=mu00.old cat("\n") } else { mu00=as.numeric(mu00.text) if (is.na(mu00)==T) mu00=get.mu00(mu00.old) else { cat("\n") options(warn=0) } } return(mu00) } get.p1=function(p1.old) { if (p1.old==-999) p1.old=.1 message=paste("Enter the percent baseline difference between exposed \n and unexposed groups (p1) (e.g. enter .10 for a 10% difference) [",p1.old,"]: ",sep="") options(warn=-1) p1.text=readline(message) if (p1.text=="") { p1=p1.old cat("\n") } else { p1=as.numeric(p1.text) if (is.na(p1)==T) p1=get.p1(p1.old) else { cat("\n") options(warn=0) } } return(p1) } get.p2=function(fixed,p2.old) { # fixed=1 -> fixed s # fixed=2 -> fixed tau if (p2.old==-999) p2.old=.1 if (fixed==1) { message=paste("Enter the percent change from baseline to time=s among unexposed (p2) \n (e.g. enter 0.10 for a 10% change) [",p2.old,"]: ",sep="") options(warn=-1) p2.text=readline(message) if (p2.text=="") { p2=p2.old cat("\n") } else { p2=as.numeric(p2.text) if (is.na(p2)==T) p2=get.p2(1,p2.old) else { cat("\n") options(warn=0) } } return(p2) } else { message=paste("Enter the percent change from baseline to end of follow-up among unexposed (p2) \n (e.g. enter 0.10 for a 10% change) [",p2.old,"]: ",sep="") options(warn=-1) p2.text=readline(message) if (p2.text=="") { p2=p2.old cat("\n") } else { p2=as.numeric(p2.text) if (is.na(p2)==T) p2=get.p2(2,p2.old) else { cat("\n") options(warn=0) } } return(p2) } } get.p3=function(fixed,p3.old) { # fixed=1 -> fixed s # fixed=2 -> fixed tau if (fixed==1) { message=paste("Enter the percent difference between the change from baseline to time=s \n in the exposed group and the unexposed group (p3) \n (e.g. enter 0.1 for a 10% difference) [",p3.old,"]: ",sep="") options(warn=-1) p3.text=readline(message) if (p3.text=="") { p3=p3.old cat("\n") } else { p3=as.numeric(p3.text) if (is.na(p3)==T) p3=get.p3(1,p3.old) else { cat("\n") options(warn=0) } } return(p3) } else { message=paste("Enter the percent difference between the change from baseline to \n end of follow-up in the exposed group and the unexposed group (p3) \n (e.g. enter 0.10 for a 10% difference) [",p3.old,"]: ",sep="") options(warn=-1) p3.text=readline(message) if (p3.text=="") { p3=p3.old cat("\n") } else { p3=as.numeric(p3.text) if (is.na(p3)==T) p3=get.p3(2,p3.old) else { cat("\n") options(warn=0) } } return(p3) } } get.p3.p20=function(fixed,p3.old) { # used when p2 == 0 # fixed=1 -> fixed s # fixed=2 -> fixed tau if (fixed==1) { message=paste("Enter the percent change from baseline to time=s among the exposed (p3) \n (e.g. enter 0.10 for a 10% change) [",p3.old,"]: ",sep="") message=paste("Enter the percent difference between the change from baseline to time=s \n in the exposed group and the unexposed group (p3) \n (e.g. enter 0.1 for a 10% difference) [",p3.old,"]: ",sep="") options(warn=-1) p3.text=readline(message) if (p3.text=="") { p3=p3.old cat("\n") } else { p3=as.numeric(p3.text) if (is.na(p3)==T) p3=get.p3.p20(1,p3.old) else { cat("\n") options(warn=0) } } return(p3) } else { message=paste("Enter the percent change from baseline to end of follow-up among the exposed (p3) \n (e.g. enter 0.10 for a 10% change) [",p3.old,"]: ",sep="") options(warn=-1) p3.text=readline(message) if (p3.text=="") { p3=p3.old cat("\n") } else { p3=as.numeric(p3.text) if (is.na(p3)==T) p3=get.p3.p20(2,p3.old) else { cat("\n") options(warn=0) } } return(p3) } } get.beta=function(beta.old) { message=paste("Enter the difference between groups (beta2) [",beta.old,"]: ",sep="") options(warn=-1) beta.text=readline(message) if (beta.text=="") { beta=beta.old cat("\n") } else { beta=as.numeric(beta.text) if (is.na(beta)==T) beta=get.beta(beta.old) else { cat("\n") options(warn=0) } } return(beta) } get.beta.tv=function(beta.old) { message=paste("Enter the value of the coefficient of interest in your model, i.e. the\n difference between exposed and unexposed periods (beta) [",beta.old,"]: ",sep="") options(warn=-1) beta.text=readline(message) if (beta.text=="") { beta=beta.old cat("\n") } else { beta=as.numeric(beta.text) if (is.na(beta)==T) beta=get.beta.tv(beta.old) else { cat("\n") options(warn=0) } } return(beta) } get.gamma=function(gamma.old) { message=paste("Enter the interaction coefficient (gamma3) [",gamma.old,"]: ",sep="") options(warn=-1) gamma.text=readline(message) if (gamma.text=="") { gamma=gamma.old cat("\n") } else { gamma=as.numeric(gamma.text) if (is.na(gamma)==T) gamma=get.gamma(gamma.old) else { cat("\n") options(warn=0) } } return(gamma) } get.gamma.tv=function(gamma.old) { message=paste("Enter the value of the coefficient of interest in your model, i.e. the\n difference in the rates of change of exposed and unexposed periods\n (gamma) [",gamma.old,"]: ",sep="") options(warn=-1) gamma.text=readline(message) if (gamma.text=="") { gamma=gamma.old cat("\n") } else { gamma=as.numeric(gamma.text) if (is.na(gamma)==T) gamma=get.gamma.tv(gamma.old) else { cat("\n") options(warn=0) } } return(gamma) } get.correlation=function(correlation.old) { message=paste("Which covariance matrix are you assuming: compound symmetry (1),\n damped exponential (2) or random slopes (3) [",correlation.old,"]? ",sep="") options(warn=-1) correlation.text=readline(message) if (correlation.text=="") { correlation=correlation.old cat("\n") } else { correlation=as.numeric(correlation.text) if ((correlation!=1 && correlation!=2 && correlation!=3) || is.na(correlation)==T) correlation=get.correlation(correlation.old) else { options(warn=0) cat("\n") } } return(correlation) } get.sigma2=function(correlation,sigma2.old) { if (correlation==1 || correlation==2) { message=paste("Enter the residual variance of the response given the assumed model\n covariates (sigma2) [",sigma2.old,"]: ",sep="") } else { message=paste("Enter the variance of the response given the assumed model covariates \n at baseline (sigma2) [",sigma2.old,"]: ",sep="") } options(warn=-1) sigma2.text=readline(message) if (sigma2.text=="") { sigma2=sigma2.old cat("\n") } else { sigma2=as.numeric(sigma2.text) if (sigma2<=0 || is.na(sigma2)==T) sigma2=get.sigma2(correlation,sigma2.old) else { cat("\n") options(warn=0) } } return(sigma2) } get.rho=function(correlation,rho.old) { if (correlation==1) { message=paste("Enter the correlation between two measures of the same subject\n (0=1 || is.na(rho)==T) rho=get.rho(correlation,rho.old) else { cat("\n") options(warn=0) } } return(rho) } get.theta=function(theta.old) { message=paste("Enter the damping coefficient (theta) [",theta.old,"]: ",sep="") options(warn=-1) theta.text=readline(message) if (theta.text=="") { theta=theta.old cat("\n") } else { theta=as.numeric(theta.text) if (theta<0 || theta>1 || is.na(theta)==T) theta=get.theta(theta.old) else { cat("\n") options(warn=0) } } return(theta) } get.notation.rs=function(notation.rs.old) { message=paste("Enter (1) for standard notation (variance of residuals and random effects) \n or (2) for \"reliability\" notation [",notation.rs.old,"]: ",sep="") options(warn=-1) notation.rs.text=readline(message) if (notation.rs.text=="") { notation.rs=notation.rs.old cat("\n") } else { notation.rs=as.numeric(notation.rs.text) if ((notation.rs!=1 && notation.rs!=2) || is.na(notation.rs)==T) notation.rs=get.notation.rs(notation.rs.old) else { cat("\n") options(warn=0) } } return(notation.rs) } get.sigma2w=function(sigma2w.old) { message=paste("Enter the within-subject variance (sigma_within^2) [",sigma2w.old,"]: ",sep="") options(warn=-1) sigma2w.text=readline(message) if (sigma2w.text=="") { sigma2w=sigma2w.old cat("\n") } else { sigma2w=as.numeric(sigma2w.text) if (sigma2w<=0 || is.na(sigma2w)==T) sigma2w=get.sigma2w(sigma2w.old) else { cat("\n") options(warn=0) } } return(sigma2w) } get.sigma20=function(sigma20.old) { message=paste("Enter the variance of the intercept random effect (sigma_{b0}^2) [",sigma20.old,"]: ",sep="") options(warn=-1) sigma20.text=readline(message) if (sigma20.text=="") { sigma20=sigma20.old cat("\n") } else { sigma20=as.numeric(sigma20.text) if (sigma20<=0 || is.na(sigma20)==T) sigma20=get.sigma20(sigma20.old) else { cat("\n") options(warn=0) } } return(sigma20) } get.sigma21=function(sigma21.old) { message=paste("Enter the variance of the random effect associated with time\n (sigma_{b1}^2) [",sigma21.old,"]: ",sep="") options(warn=-1) sigma21.text=readline(message) if (sigma21.text=="") { sigma21=sigma21.old cat("\n") } else { sigma21=as.numeric(sigma21.text) if (sigma21<=0 || is.na(sigma21)==T) sigma21=get.sigma21(sigma21.old) else { cat("\n") options(warn=0) } } return(sigma21) } get.sigma01=function(sigma01.old) { message=paste("Enter the covariance of the random effects (sigma_{b0,b1}) [",sigma01.old,"]: ",sep="") options(warn=-1) sigma01.text=readline(message) if (sigma01.text=="") { sigma01=sigma01.old cat("\n") } else { sigma01=as.numeric(sigma01.text) if (is.na(sigma01)==T) sigma01=get.sigma01(sigma01.old) else { cat("\n") options(warn=0) } } return(sigma01) } get.r.tilde=function(r.tilde.old) { message=paste("Enter the trial value of the number of measurements at which the\n slope reliability will be provided (\\tilde r>0 ) [",r.tilde.old,"]: ",sep="") options(warn=-1) r.tilde.text=readline(message) if (r.tilde.text=="") { r.tilde=r.tilde.old cat("\n") } else { r.tilde=as.numeric(r.tilde.text) if (r.tilde<1 || is.na(r.tilde)==T) r.tilde=get.r.tilde(r.tilde.old) else { cat("\n") options(warn=0) } } return(r.tilde) } get.rho.b1=function(r.tilde,rho.b1.old) { options(warn=-1) message=paste("Enter the slope reliability for ", r.tilde, " repeated measurements\n (0=1 || is.na(rho.b1)==T) rho.b1=get.rho.b1(r.tilde,rho.b1.old) else { cat("\n") options(warn=0) } } return(rho.b1) } get.rho01=function(rho01.old) { message=paste("Enter the correlation between the random effects of slope\n and intercept (-1=1 || is.na(rho01)==T) rho01=get.rho01(rho01.old) else { cat("\n") options(warn=0) } } return(rho01) } get.budget=function(budget.old) { message=paste("Enter the available budget (C>0) [",budget.old,"]: ",sep="") options(warn=-1) budget.text=readline(message) if (budget.text=="") { budget=budget.old cat("\n") } else { budget=as.numeric(budget.text) if (budget<=0 || is.na(budget)==T) budget=get.budget(budget.old) else { cat("\n") options(warn=0) } } return(budget) } get.c1=function(c1.old) { message=paste("Enter the cost of the first observation of each subject (c1>0) [",c1.old,"]: ",sep="") options(warn=-1) c1.text=readline(message) if (c1.text=="") { c1=c1.old cat("\n") } else { c1=as.numeric(c1.text) if (c1<=0 || is.na(c1)==T) c1=get.c1(c1.old) else { cat("\n") options(warn=0) } } return(c1) } get.k=function(k.old) { message=paste("Enter the ratio of costs between the first measure and the rest (kappa) [",k.old,"]: ",sep="") options(warn=-1) k.text=readline(message) if (k.text=="") { k=k.old cat("\n") } else { k=as.numeric(k.text) if (k<=0 || is.na(k)==T) k=get.k(k.old) else { cat("\n") options(warn=0) } } return(k) } get.finish=function() { cat("\n") continue=readline("Do you want to continue using the program (y/n) [y]? ") if (continue=="y" || continue=="Y" || continue=="Yes" || continue=="yes" || continue=="YES" || continue=="") finish=F else finish=T cat("\n") return(finish) } ####### ################################################### # 1.2 # # Functions to compute variance of the parameter # ####### ################################################### # To get the variance, the result needs to be divided by N # -------------------------- # Time-invariant functions : # -------------------------- # ******************************* # * Var for CMD and CS, fixed s * # ******************************* long.var.s.CMD.CS=function(r,s,pe,vt0,rho.exp.t0,sigma2,rho) { if (vt0==0 || rho.exp.t0==0) { var=sigma2*(1+r*rho)/(pe*(1-pe)*(r+1)) } else { X.constant=rep(1,r+1) X.times=0:r X=cbind(X.constant,X.times) vec1=c(1,rep(rho,r)) sigma=toeplitz(vec1) A=t(X) %*% solve(sigma ) %*% X var=sigma2* ( (A[1,1]^2)*vt0-(A[1,2]^2)*(s^2)+A[1,1]*A[2,2]*(s^2) ) / ( A[1,1]*pe*(1-pe)*( det(A)*(s^2)+(A[1,1]^2)*(1-rho.exp.t0^2)*vt0 ) ) } var } # ********************************* # * Var for CMD and DEX, fixed s * # ********************************* long.var.s.CMD.DEX=function(r,s,pe,vt0,rho.exp.t0,sigma2,rho,theta) { if (vt0==0 || rho.exp.t0==0) { X.constant=rep(1,r+1) vec1=rep(0,r+1) vec1[1]=1 if (r==0) sigma=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } sigma=toeplitz(vec1) } var=sigma2/(pe*(1-pe)*(t(X.constant) %*% solve(sigma) %*% X.constant )) } else { X.constant=rep(1,r+1) X.times=0:r X=cbind(X.constant,X.times) vec1=rep(0,r+1) vec1[1]=1 if (r==0) sigma=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } sigma=toeplitz(vec1) } A=t(X) %*% solve(sigma ) %*% X var=sigma2* ( (A[1,1]^2)*vt0-(A[1,2]^2)*(s^2)+A[1,1]*A[2,2]*(s^2) ) / ( A[1,1]*pe*(1-pe)*( det(A)*(s^2)+(A[1,1]^2)*(1-rho.exp.t0^2)*vt0 ) ) } var } # ******************************* # * Var for CMD and RS, fixed s * # ******************************* # auxiliary functions fanoexp.normal.s=function(t0,pe,rr,ss,sigma2w,sigma20,sigma21,sigma01,vt0,rho.exp.t0) { a.num=12*sigma2w/(rr*(rr+1)*(rr+2)*(ss^2))+sigma21 c.num=6*sigma2w*(rr*ss+2*t0)/(rr*(rr+1)*(rr+2)*(ss^2))-sigma01 d.num=2*sigma2w*(rr*(1+2*rr)*(ss^2)+6*rr*ss*t0+6*(t0^2))/(rr*(rr+1)*(rr+2)*(ss^2))+sigma20 det.G=a.num*d.num-(c.num^2) a=a.num/det.G sig2=vt0*(1-rho.exp.t0^2) Et0.noexp=-rho.exp.t0 * sqrt(pe/(1-pe)) * sqrt(vt0) (1-pe)*a* ( (1/sqrt(2*pi*sig2))*exp(-.5*((t0-Et0.noexp)^2)/sig2) ) } faexp.normal.s=function(t0,pe,rr,ss,sigma2w,sigma20,sigma21,sigma01,vt0,rho.exp.t0) { a.num=12*sigma2w/(rr*(rr+1)*(rr+2)*(ss^2))+sigma21 c.num=6*sigma2w*(rr*ss+2*t0)/(rr*(rr+1)*(rr+2)*(ss^2))-sigma01 d.num=2*sigma2w*(rr*(1+2*rr)*(ss^2)+6*rr*ss*t0+6*(t0^2))/(rr*(rr+1)*(rr+2)*(ss^2))+sigma20 det.G=a.num*d.num-(c.num^2) a=a.num/det.G sig2=vt0*(1-rho.exp.t0^2) Et0.exp=rho.exp.t0 * sqrt((1-pe)/pe) * sqrt(vt0) pe*a* ( (1/sqrt(2*pi*sig2))*exp(-.5*((t0-Et0.exp)^2)/sig2) ) } fcnoexp.normal.s=function(t0,pe,rr,ss,sigma2w,sigma20,sigma21,sigma01,vt0,rho.exp.t0) { a.num=12*sigma2w/(rr*(rr+1)*(rr+2)*(ss^2))+sigma21 c.num=6*sigma2w*(rr*ss+2*t0)/(rr*(rr+1)*(rr+2)*(ss^2))-sigma01 d.num=2*sigma2w*(rr*(1+2*rr)*(ss^2)+6*rr*ss*t0+6*(t0^2))/(rr*(rr+1)*(rr+2)*(ss^2))+sigma20 det.G=a.num*d.num-(c.num^2) c=c.num/det.G sig2=vt0*(1-rho.exp.t0^2) Et0.noexp=-rho.exp.t0 * sqrt(pe/(1-pe)) * sqrt(vt0) (1-pe)*c* ( (1/sqrt(2*pi*sig2))*exp(-.5*((t0-Et0.noexp)^2)/sig2) ) } fcexp.normal.s=function(t0,pe,rr,ss,sigma2w,sigma20,sigma21,sigma01,vt0,rho.exp.t0) { a.num=12*sigma2w/(rr*(rr+1)*(rr+2)*(ss^2))+sigma21 c.num=6*sigma2w*(rr*ss+2*t0)/(rr*(rr+1)*(rr+2)*(ss^2))-sigma01 d.num=2*sigma2w*(rr*(1+2*rr)*(ss^2)+6*rr*ss*t0+6*(t0^2))/(rr*(rr+1)*(rr+2)*(ss^2))+sigma20 det.G=a.num*d.num-(c.num^2) c=c.num/det.G sig2=vt0*(1-rho.exp.t0^2) Et0.exp=rho.exp.t0 * sqrt((1-pe)/pe) * sqrt(vt0) pe*c* ( (1/sqrt(2*pi*sig2))*exp(-.5*((t0-Et0.exp)^2)/sig2) ) } fdnoexp.normal.s=function(t0,pe,rr,ss,sigma2w,sigma20,sigma21,sigma01,vt0,rho.exp.t0) { a.num=12*sigma2w/(rr*(rr+1)*(rr+2)*(ss^2))+sigma21 c.num=6*sigma2w*(rr*ss+2*t0)/(rr*(rr+1)*(rr+2)*(ss^2))-sigma01 d.num=2*sigma2w*(rr*(1+2*rr)*(ss^2)+6*rr*ss*t0+6*(t0^2))/(rr*(rr+1)*(rr+2)*(ss^2))+sigma20 det.G=a.num*d.num-(c.num^2) d=d.num/det.G sig2=vt0*(1-rho.exp.t0^2) Et0.noexp=-rho.exp.t0 * sqrt(pe/(1-pe)) * sqrt(vt0) (1-pe)*d* ( (1/sqrt(2*pi*sig2))*exp(-.5*((t0-Et0.noexp)^2)/sig2) ) } fdexp.normal.s=function(t0,pe,rr,ss,sigma2w,sigma20,sigma21,sigma01,vt0,rho.exp.t0) { a.num=12*sigma2w/(rr*(rr+1)*(rr+2)*(ss^2))+sigma21 c.num=6*sigma2w*(rr*ss+2*t0)/(rr*(rr+1)*(rr+2)*(ss^2))-sigma01 d.num=2*sigma2w*(rr*(1+2*rr)*(ss^2)+6*rr*ss*t0+6*(t0^2))/(rr*(rr+1)*(rr+2)*(ss^2))+sigma20 det.G=a.num*d.num-(c.num^2) d=d.num/det.G sig2=vt0*(1-rho.exp.t0^2) Et0.exp=rho.exp.t0 * sqrt((1-pe)/pe) * sqrt(vt0) pe*d* ( (1/sqrt(2*pi*sig2))*exp(-.5*((t0-Et0.exp)^2)/sig2) ) } long.var.s.CMD.RS=function(r,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) { if (vt0==0) { if (r==0) { var=(sigma2w+sigma20)*(1/(pe*(1-pe))) } else { X.constant=rep(1,r+1) X.times=(s)*(0:r) X=as.matrix(cbind(X.constant,X.times)) D=matrix(c(sigma20,sigma01,sigma01,sigma21),2,2) sigma=(X%*%D%*%t(X)+sigma2w*diag(r+1)) var=(1/(pe*(1-pe)))*(1/(X.constant%*%solve(sigma)%*%X.constant)) } } else { if (r==0) { var=(sigma2w+sigma20)*(1/(pe*(1-pe))) } else { E.a.exp=integrate(faexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value E.a.noexp=integrate(fanoexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value E.c.exp=integrate(fcexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value E.c.noexp=integrate(fcnoexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value E.d.exp=integrate(fdexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value E.d.noexp=integrate(fdnoexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value to.invert=matrix(c(E.a.exp+E.a.noexp,E.a.exp,E.c.exp+E.c.noexp, E.a.exp,E.a.exp,E.c.exp, E.c.exp+E.c.noexp,E.c.exp,E.d.exp+E.d.noexp),nrow=3,ncol=3) var=solve(to.invert)[2,2] } } var } #### LDD #### # ******************************* # * Var for LDD and CS, fixed s * # ******************************* long.var.s.LDD.CS=function(r,s,pe,vt0,rho.exp.t0,sigma2,rho) { if (vt0==0) { var=12*sigma2*(1-rho)*(1+r*rho)/(pe*(1-pe)* ((s^2)*r*(r+1)*(r+2)*(1+r*rho) + 12*(r+1)*(1-rho)*vt0)) } else { X.constant=rep(1,r+1) X.times=0:r vec1=c(1,rep(rho,r)) sigma=toeplitz(vec1) var=(t(X.constant)%*%solve(sigma)%*%X.constant) / ( vt0*((t(X.constant)%*%solve(sigma)%*%X.constant)^2)*(1-rho.exp.t0^2) + ((s^2))*((t(X.constant)%*%solve(sigma)%*%X.constant)* (t(X.times)%*%solve(sigma)%*%X.times)- ((t(X.constant)%*%solve(sigma)%*%X.times)^2)) ) var=sigma2*var/(pe*(1-pe)) } var } # ******************************** # * Var for LDD and DEX, fixed s * # ******************************** long.var.s.LDD.DEX=function(r,s,pe,vt0,rho.exp.t0,sigma2,rho,theta) { X.constant=rep(1,r+1) X.times=0:r vec1=rep(0,r+1) vec1[1]=1 for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } sigma=toeplitz(vec1) var=(t(X.constant)%*%solve(sigma)%*%X.constant) / ( vt0*((t(X.constant)%*%solve(sigma)%*%X.constant)^2)*(1-rho.exp.t0^2) + ((s^2))*((t(X.constant)%*%solve(sigma)%*%X.constant)* (t(X.times)%*%solve(sigma)%*%X.times)- ((t(X.constant)%*%solve(sigma)%*%X.times)^2)) ) var=sigma2*var/(pe*(1-pe)) var } # ******************************* # * Var for LDD and RS, fixed s * # ******************************* long.var.s.LDD.RS=function(r,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) { if (vt0 == 0) { var=(12*sigma2w/((s^2)*r*(r+1)*(r+2))+sigma21)/(pe*(1-pe)) } else { E.a.exp=integrate(faexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value E.a.noexp=integrate(fanoexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value E.c.exp=integrate(fcexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value E.c.noexp=integrate(fcnoexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value E.d.exp=integrate(fdexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value E.d.noexp=integrate(fdnoexp.normal.s,-Inf,Inf,pe=pe,rr=r,ss=s,sigma2w=sigma2w,sigma20=sigma20,sigma21=sigma21,sigma01=sigma01,vt0=vt0,rho.exp.t0=rho.exp.t0)$value to.invert=matrix(c(E.a.exp+E.a.noexp,E.a.exp,E.c.exp+E.c.noexp,E.c.exp, E.a.exp,E.a.exp,E.c.exp,E.c.exp, E.c.exp+E.c.noexp,E.c.exp,E.d.exp+E.d.noexp,E.d.exp, E.c.exp,E.c.exp,E.d.exp,E.d.exp),nrow=4,ncol=4) var=solve(to.invert)[4,4] } var } # ------------------------ # Time-varying functions : # ------------------------ ## CMD ## # ************************************************ # * Var for model with only exposure (marginal), * # * CMD, DEX response, CS exposure, fixed s * # ************************************************ long.var.s.tv.CMD.marg.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { # pe can be either a scalar or a vector of length r+1 if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx(s,Ex.x,sigma2,rho,theta) } var.exx=function(s,exx,sigma2,rho,theta) { # Var for model with only exposure (marginal), given the exposure covariance # CMD, DEX response, fixed s r=dim(exx)[1]-1 vec1=rep(0,r+1) vec1[1]=1 if (r==0) DEX=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } DEX=toeplitz(vec1) } inv=solve(sigma2*DEX) pe=diag(exx) sum(inv)/( sum(inv)*sum(inv*exx)-(sum(inv*pe)^2) ) } # *********************************************************** # * Var upper bound for a given rho.e and prevalence vector * # * Model with only exposure (marginal) * # * CMD, DEX response, CS exposure, fixed s * # *********************************************************** long.var.s.tv.upper.CMD.marg.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { exx=exx.upper(r,s,pe,rho.e,sigma2,rho,theta) if (exx[1,1]==-99) var=-99 else var=var.exx(s,exx,sigma2,rho,theta) var } # Function for known pej for all j, DEX response exx.upper=function(r,s,pe,rho.e,sigma2,rho,theta) { # 'A1%*%x <= b1', 'A2%*%x >= b2', 'A3%*%x = b3' and 'x >= 0' # pe can be either a scalar or a vector of length r+1 # returns the Ex.x matrix that would produce the upper bound of the variance # for non-conditional models if (length(pe)==1) pe=rep(pe,times=r+1) mean.pe=mean(pe) library(boot) vec1=rep(0,r+1) vec1[1]=1 if (r==0) DEX=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } DEX=toeplitz(vec1) } inv=solve(sigma2*DEX) nvars=(r+1)*r/2 #nvars=(r+1)*(r+2)/2 d=inv[lower.tri(inv)] const1=matrix(rep(2,nvars),nrow=1,byrow=T) bb1=mean.pe*(r+1)*r*(rho.e+mean.pe*(1-rho.e)) sum.pairs=matrix(0,nrow=nvars,ncol=1) ind=1 for (i in 1:r) { for (j in (i+1):(r+1)) { sum.pairs[ind]=pe[i]+pe[j] ind=ind+1 } } positive=(sum.pairs>1) if (sum(positive)>0) { bb3.2=sum.pairs-1 } mat.min=matrix(0,nrow=r+1,ncol=r+1) for (i in 1:r) { for (j in (i+1):(r+1)) { mat.min[j,i]=min(pe[i]*(1-pe[j]),pe[j]*(1-pe[i]))+pe[i]*pe[j] } } const3.3=diag(nvars) bb3.3=mat.min[lower.tri(mat.min)] k=1 if (r>2) { const4=matrix(0,ncol=nvars,nrow=2^(r+1)-(r+1)*(r+2)/2-2) bb4=matrix(0,ncol=1,nrow=2^(r+1)-(r+1)*(r+2)/2-2) for (m in 3:r) { subsets=combinations(r+1,m) for (i in 1:choose(r+1,m)) { indexes=subsets[,i] auxmat4=matrix(0,ncol=r+1,nrow=r+1) bb4[k]=sum(pe[indexes])-1 auxmat4[indexes,indexes]=1 const4[k,]=auxmat4[lower.tri(auxmat4)] k=k+1 } } # eliminate the non-positive ones positive2=(bb4>0) const4=const4[bb4>0,] bb4=bb4[bb4>0,] } else positive2=0 A1=const3.3 b1=bb3.3 A3=const1 b3=bb1 if (sum(positive)>0) { b1=bb3.3-as.integer(positive)*bb3.2 b3=bb1-A3%*%(as.integer(positive)*bb3.2) if (sum(positive2)>0) { bb4=bb4-const4%*%(as.integer(positive)*bb3.2) A2=const4 b2=bb4 sol=simplex(a=d,A1=A1,b1=b1,A2=A2,b2=b2,A3=A3,b3=b3) sol$soln=sol$soln+as.integer(positive)*bb3.2 } else { sol=simplex(a=d,A1=A1,b1=b1,A3=A3,b3=b3) sol$soln=sol$soln+as.integer(positive)*bb3.2 } } else { if (sum(positive2)>0) { A2=const4 b2=bb4 sol=simplex(a=d,A1=A1,b1=b1,A2=A2,b2=b2,A3=A3,b3=b3) } else { sol=simplex(a=d,A1=A1,b1=b1,A3=A3,b3=b3) } } if (sol$solved!=1) Ex.x=matrix(-99,nrow=r+1,ncol=r+1) else { Ex.x=matrix(0,ncol=r+1,nrow=r+1) Ex.x[lower.tri(Ex.x)]=sol$soln Ex.x=Ex.x+t(Ex.x) diag(Ex.x)=pe } return(Ex.x) } # *************************************************************************** # * Var for model with only exposure (conditional or model on differences), * # * CMD, DEX response, CS exposure, fixed s * # *************************************************************************** long.var.s.tv.CMD.cond.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.cond(s,Ex.x,sigma2,rho,theta) } var.exx.cond=function(s,exx,sigma2,rho,theta) { # Var for model with only exposure (conditional or model on differences), # given the exposure covariance # CMD, DEX response, fixed s r=dim(exx)[1]-1 vec1=rep(0,r+1) vec1[1]=1 if (r==0) DEX=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } DEX=toeplitz(vec1) } A=matrix(0,ncol=r+1,nrow=r) diag(A)=-1 for (i in 1:r) { A[i,i+1]=1 } M=t(A) %*% solve(A%*%(sigma2*DEX)%*%t(A)) %*% A pe=diag(exx) mean.pe=mean(pe) sigma=sum(M*exx) 1/sigma } # ****************************************************************** # * Var upper bound for a given rho.e and prevalence vector * # * Model with only exposure (conditional or model on differences) * * # * CMD, DEX response, CS exposure, fixed s * # ****************************************************************** # Function for known pej for all j, DEX response long.var.s.tv.upper.CMD.cond.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { exx=exx.upper.cond(r,s,pe,rho.e,sigma2,rho,theta) if (exx[1,1]==-99) var=-99 else var=var.exx.cond(s,exx,sigma2,rho,theta) var } exx.upper.cond=function(r,s,pe,rho.e,sigma2,rho,theta) { # 'A1%*%x <= b1', 'A2%*%x >= b2', 'A3%*%x = b3' and 'x >= 0' # pe can be either a scalar or a vector of length r+1 # returns the Ex.x matrix that would produce the upper bound of the variance # for conditional models if (length(pe)==1) pe=rep(pe,times=r+1) mean.pe=mean(pe) library(boot) vec1=rep(0,r+1) vec1[1]=1 if (r==0) DEX=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } DEX=toeplitz(vec1) } A=matrix(0,ncol=r+1,nrow=r) diag(A)=-1 for (i in 1:r) { A[i,i+1]=1 } M=t(A) %*% solve(A%*%(sigma2*DEX)%*%t(A)) %*% A nvars=(r+1)*r/2 #nvars=(r+1)*(r+2)/2 d=M[lower.tri(M)] const1=matrix(rep(2,nvars),nrow=1,byrow=T) bb1=mean.pe*(r+1)*r*(rho.e+mean.pe*(1-rho.e)) sum.pairs=matrix(0,nrow=nvars,ncol=1) ind=1 for (i in 1:r) { for (j in (i+1):(r+1)) { sum.pairs[ind]=pe[i]+pe[j] ind=ind+1 } } positive=(sum.pairs>1) if (sum(positive)>0) { bb3.2=sum.pairs-1 } mat.min=matrix(0,nrow=r+1,ncol=r+1) for (i in 1:r) { for (j in (i+1):(r+1)) { mat.min[j,i]=min(pe[i]*(1-pe[j]),pe[j]*(1-pe[i]))+pe[i]*pe[j] } } const3.3=diag(nvars) bb3.3=mat.min[lower.tri(mat.min)] k=1 if (r>2) { const4=matrix(0,ncol=nvars,nrow=2^(r+1)-(r+1)*(r+2)/2-2) bb4=matrix(0,ncol=1,nrow=2^(r+1)-(r+1)*(r+2)/2-2) for (m in 3:r) { subsets=combinations(r+1,m) for (i in 1:choose(r+1,m)) { indexes=subsets[,i] auxmat4=matrix(0,ncol=r+1,nrow=r+1) bb4[k]=sum(pe[indexes])-1 auxmat4[indexes,indexes]=1 const4[k,]=auxmat4[lower.tri(auxmat4)] k=k+1 } } # eliminate the non-positive ones positive2=(bb4>0) const4=const4[bb4>0,] bb4=bb4[bb4>0,] } else positive2=0 A1=const3.3 b1=bb3.3 A3=const1 b3=bb1 if (sum(positive)>0) { b1=bb3.3-as.integer(positive)*bb3.2 b3=bb1-A3%*%(as.integer(positive)*bb3.2) if (sum(positive2)>0) { bb4=bb4-const4%*%(as.integer(positive)*bb3.2) A2=const4 b2=bb4 sol=simplex(a=d,A1=A1,b1=b1,A2=A2,b2=b2,A3=A3,b3=b3) sol$soln=sol$soln+as.integer(positive)*bb3.2 } else { sol=simplex(a=d,A1=A1,b1=b1,A3=A3,b3=b3) sol$soln=sol$soln+as.integer(positive)*bb3.2 } } else { if (sum(positive2)>0) { A2=const4 b2=bb4 sol=simplex(a=d,A1=A1,b1=b1,A2=A2,b2=b2,A3=A3,b3=b3) } else { sol=simplex(a=d,A1=A1,b1=b1,A3=A3,b3=b3) } } if (sol$solved!=1) Ex.x=matrix(-99,nrow=r+1,ncol=r+1) else { Ex.x=matrix(0,ncol=r+1,nrow=r+1) Ex.x[lower.tri(Ex.x)]=sol$soln Ex.x=Ex.x+t(Ex.x) diag(Ex.x)=pe } return(Ex.x) } # ***************************************************** # * Var for model with exposure and time (marginal), * # * CMD, DEX response, CS exposure, fixed s, V(t0)=0 * # ***************************************************** long.var.s.tv.CMD.marg.time.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.time(s,Ex.x,sigma2,rho,theta) } var.exx.time=function(s,exx,sigma2,rho,theta) { # Var for model with exposure and time (marginal), # given the exposure covariance # CMD, DEX response, fixed s # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 r=dim(exx)[1]-1 vec1=rep(0,r+1) vec1[1]=1 if (r==0) DEX=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } DEX=toeplitz(vec1) } inv=solve(sigma2*DEX) pe=diag(exx) mean.pe=mean(pe) times=s*(0:r) ones=rep(1,r+1) a=sum(inv) b=t(times)%*%inv%*%ones c=t(times)%*%inv%*%times d=t(pe)%*%inv%*%ones e=sum(inv*exx) f=t(pe)%*%inv%*%times sigma=matrix(c(a,d,b, d,e,f, b,f,c),nrow=3,ncol=3) solve(sigma)[2,2] } # *********************************************************** # * Var upper bound for a given rho.e and prevalence vector * # * Model with exposure and time (marginal), * # * CMD, DEX response, CS exposure, fixed s * # *********************************************************** # Function for known pej for all j, DEX response long.var.s.tv.upper.CMD.marg.time.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { exx=exx.upper(r,s,pe,rho.e,sigma2,rho,theta) if (exx[1,1]==-99) var=-99 else var=var.exx.time(s,exx,sigma2,rho,theta) var } # ****************************************************************************** # * Var for model with exposure and time (conditional or model on differences) * # * CMD, DEX response, CS exposure, fixed s * # ****************************************************************************** long.var.s.tv.CMD.cond.time.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.cond.time(s,Ex.x,sigma2,rho,theta) } var.exx.cond.time=function(s,exx,sigma2,rho,theta) { # Var for model with exposure and time (conditional or model on differences), # given the exposure covariance # CMD, DEX response, fixed s r=dim(exx)[1]-1 vec1=rep(0,r+1) vec1[1]=1 if (r==0) DEX=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } DEX=toeplitz(vec1) } A=matrix(0,ncol=r+1,nrow=r) diag(A)=-1 for (i in 1:r) { A[i,i+1]=1 } M=t(A) %*% solve(A%*%(sigma2*DEX)%*%t(A)) %*% A pe=diag(exx) times=s*(0:r) c=t(times)%*%M%*%times e=sum(M*exx) f=t(pe)%*%M%*%times c/(e*c-(f^2)) } long.var.s.tv.upper.CMD.cond.time.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { exx=exx.upper.cond(r,s,pe,rho.e,sigma2,rho,theta) if (exx[1,1]==-99) var=-99 else var=var.exx.cond.time(s,exx,sigma2,rho,theta) var } ### RS ### # ************************************************ # * Var for model with only exposure (marginal), * # * CMD, RS response, CS exposure, fixed s * # ************************************************ long.var.s.tv.CMD.marg.RS=function(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) { # pe can be either a scalar or a vector of length r+1 if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.RS(s,Ex.x,sigma2w,sigma20,sigma21,sigma01) } var.exx.RS=function(s,exx,sigma2w,sigma20,sigma21,sigma01) { # Var for model with only exposure (marginal), given the exposure covariance # CMD, RS response, fixed s r=dim(exx)[1]-1 X.constant=rep(1,r+1) X.times=(s)*(0:r) X=as.matrix(cbind(X.constant,X.times)) D=matrix(c(sigma20,sigma01,sigma01,sigma21),2,2) RS=(X%*%D%*%t(X)+sigma2w*diag(r+1)) inv=solve(RS) pe=diag(exx) sum(inv)/( sum(inv)*sum(inv*exx)-(sum(inv*pe)^2) ) } # *************************************************************************** # * Var for model with only exposure (conditional or model on differences), * # * CMD, RS response, CS exposure, fixed s * # *************************************************************************** long.var.s.tv.CMD.cond.RS=function(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) { if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.cond.RS(s,Ex.x,sigma2w,sigma20,sigma21,sigma01) } var.exx.cond.RS=function(s,exx,sigma2w,sigma20,sigma21,sigma01) { # Var for model with only exposure (conditional or model on differences), # given the exposure covariance # CMD, DEX response, fixed s r=dim(exx)[1]-1 X.constant=rep(1,r+1) X.times=(s)*(0:r) X=as.matrix(cbind(X.constant,X.times)) D=matrix(c(sigma20,sigma01,sigma01,sigma21),2,2) RS=(X%*%D%*%t(X)+sigma2w*diag(r+1)) A=matrix(0,ncol=r+1,nrow=r) diag(A)=-1 for (i in 1:r) { A[i,i+1]=1 } M=t(A) %*% solve(A%*%(RS)%*%t(A)) %*% A pe=diag(exx) mean.pe=mean(pe) sigma=sum(M*exx) 1/sigma } # ***************************************************** # * Var for model with exposure and time (marginal), * # * CMD, RS response, CS exposure, fixed s, V(t0)=0 * # ***************************************************** long.var.s.tv.CMD.marg.time.RS=function(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) { # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.time.RS(s,Ex.x,sigma2w,sigma20,sigma21,sigma01) } var.exx.time.RS=function(s,exx,sigma2w,sigma20,sigma21,sigma01) { # Var for model with exposure and time (marginal), # given the exposure covariance # CMD, RS response, fixed s # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 r=dim(exx)[1]-1 X.constant=rep(1,r+1) X.times=(s)*(0:r) X=as.matrix(cbind(X.constant,X.times)) D=matrix(c(sigma20,sigma01,sigma01,sigma21),2,2) RS=(X%*%D%*%t(X)+sigma2w*diag(r+1)) inv=solve(RS) pe=diag(exx) mean.pe=mean(pe) times=s*(0:r) ones=rep(1,r+1) a=sum(inv) b=t(times)%*%inv%*%ones c=t(times)%*%inv%*%times d=t(pe)%*%inv%*%ones e=sum(inv*exx) f=t(pe)%*%inv%*%times sigma=matrix(c(a,d,b, d,e,f, b,f,c),nrow=3,ncol=3) solve(sigma)[2,2] } # ****************************************************************************** # * Var for model with exposure and time (conditional or model on differences) * # * CMD, RS response, CS exposure, fixed s * # ****************************************************************************** long.var.s.tv.CMD.cond.time.RS=function(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) { if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.cond.time.RS(s,Ex.x,sigma2w,sigma20,sigma21,sigma01) } var.exx.cond.time.RS=function(s,exx,sigma2w,sigma20,sigma21,sigma01) { # Var for model with exposure and time (conditional or model on differences), # given the exposure covariance # CMD, RS response, fixed s r=dim(exx)[1]-1 X.constant=rep(1,r+1) X.times=(s)*(0:r) X=as.matrix(cbind(X.constant,X.times)) D=matrix(c(sigma20,sigma01,sigma01,sigma21),2,2) RS=(X%*%D%*%t(X)+sigma2w*diag(r+1)) A=matrix(0,ncol=r+1,nrow=r) diag(A)=-1 for (i in 1:r) { A[i,i+1]=1 } M=t(A) %*% solve(A%*%(RS)%*%t(A)) %*% A pe=diag(exx) times=s*(0:r) c=t(times)%*%M%*%times e=sum(M*exx) f=t(pe)%*%M%*%times c/(e*c-(f^2)) } ## LDD ## # ***************************************************** # * Var for acute effect model (marginal), * # * LDD, DEX response, CS exposure, fixed s, V(t0)=0 * # ***************************************************** long.var.s.tv.LDD.acute.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.LDD.acute.DEX(s,Ex.x,sigma2,rho,theta) } var.exx.LDD.acute.DEX=function(s,exx,sigma2,rho,theta) { # Var for acute effect model (marginal), # given the exposure covariance # LDD, DEX response, fixed s # pe can be either a scalar or a vector of length r+1 # assuming time centered at 0, which has no effect on the result # assume vt0=0 (and mean(t0)=0) r=dim(exx)[1]-1 vec1=rep(0,r+1) vec1[1]=1 if (r==0) DEX=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } DEX=toeplitz(vec1) } inv=solve(sigma2*DEX) # Exposure process pe=diag(exx) mean.pe=mean(pe) Ex.x=exx # Needed quantities ones=rep(1,r+1) times=0:r a=sum(inv) b=t(times) %*% inv %*% ones c=t(times) %*% inv %*% times d=t(pe) %*% inv %*% ones e=sum(Ex.x*inv) f=t(pe) %*% inv %*% times h=t((pe*times)) %*% inv %*% ones k=t(times*pe)%*% inv %*% times p=t(times)%*% (Ex.x*inv) %*% ones u=t(times) %*% (Ex.x*inv) %*% times E.X.S.X=matrix(c(a,s*b,d,s*h, s*b,(s^2)*c,s*f,(s^2)*k, d,s*f,e,s*p, s*h,(s^2)*k,s*p,(s^2)*u),ncol=4,nrow=4) var=solve(E.X.S.X)[4,4] return(var) } long.var.s.tv.LDD.acute.RS=function(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) { # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.LDD.acute.RS(s,Ex.x,sigma2w,sigma20,sigma21,sigma01) } var.exx.LDD.acute.RS=function(s,exx,sigma2w,sigma20,sigma21,sigma01) { # Var for acute effect model (marginal), # given the exposure covariance # LDD, RS response, fixed s # pe can be either a scalar or a vector of length r+1 # assuming time centered at 0, which has no effect on the result # assume vt0=0 (and mean(t0)=0) r=dim(exx)[1]-1 ones=rep(1,r+1) times=(s)*(0:r) Z=as.matrix(cbind(ones,times)) D=matrix(c(sigma20,sigma01,sigma01,sigma21),2,2) sigma=(Z%*%D%*%t(Z)+sigma2w*diag(r+1)) inv=solve(sigma) # Exposure process pe=diag(exx) mean.pe=mean(pe) Ex.x=exx # Needed quantities ones=rep(1,r+1) times=0:r a=sum(inv) b=t(times) %*% inv %*% ones c=t(times) %*% inv %*% times d=t(pe) %*% inv %*% ones e=sum(Ex.x*inv) f=t(pe) %*% inv %*% times h=t((pe*times)) %*% inv %*% ones k=t(times*pe)%*% inv %*% times p=t(times)%*% (Ex.x*inv) %*% ones u=t(times) %*% (Ex.x*inv) %*% times E.X.S.X=matrix(c(a,s*b,d,s*h, s*b,(s^2)*c,s*f,(s^2)*k, d,s*f,e,s*p, s*h,(s^2)*k,s*p,(s^2)*u),ncol=4,nrow=4) var=solve(E.X.S.X)[4,4] return(var) } # ********************************************************************* # * Var for acute effect model (conditional or model on differences), * # * LDD, DEX response, CS exposure, fixed s, V(t0)=0 * # ********************************************************************* long.var.s.tv.LDD.acute.cond.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 if (rho.e==1) long.var.s.LDD.DEX(r,s,pe,vt0=0,rho.exp.t0=0,sigma2,rho,theta) else { if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.LDD.acute.cond.DEX(s,Ex.x,sigma2,rho,theta) } } var.exx.LDD.acute.cond.DEX=function(s,exx,sigma2,rho,theta) { # Var for acute effect model (conditional or model on differences), # given the exposure covariance # LDD, DEX response, fixed s # pe can be either a scalar or a vector of length r+1 # assuming time centered at 0, which has no effect on the result # assume vt0=0 (and mean(t0)=0) r=dim(exx)[1]-1 vec1=rep(0,r+1) vec1[1]=1 if (r==0) DEX=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } DEX=toeplitz(vec1) } A=matrix(0,ncol=r+1,nrow=r) diag(A)=-1 for (i in 1:r) { A[i,i+1]=1 } M=t(A) %*% solve(A%*%(sigma2*DEX)%*%t(A)) %*% A # Exposure process pe=diag(exx) mean.pe=mean(pe) Ex.x=exx # Needed quantities ones=rep(1,r+1) times=0:r c=t(times) %*% M %*% times e=sum(Ex.x*M) f=t(pe) %*% M %*% times k=t(times*pe)%*% M %*% times p=t(times)%*% (Ex.x*M) %*% ones u=t(times) %*% (Ex.x*M) %*% times E.X.S.X=matrix(c(e,s*f,s*p, s*f,(s^2)*c,(s^2)*k, s*p,(s^2)*k,(s^2)*u),ncol=3,nrow=3) var=solve(E.X.S.X)[3,3] return(var) } long.var.s.tv.LDD.acute.cond.RS=function(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) { # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 if (rho.e==1) long.var.s.LDD.RS(r,s,pe,vt0=0,rho.exp.t0=0,sigma2w,sigma20,sigma21,sigma01) else { if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.LDD.acute.cond.RS(s,Ex.x,sigma2w,sigma20,sigma21,sigma01) } } var.exx.LDD.acute.cond.RS=function(s,exx,sigma2w,sigma20,sigma21,sigma01) { # Var for acute effect model (conditional or model on differences), # given the exposure covariance # LDD, RS response, fixed s # pe can be either a scalar or a vector of length r+1 # assuming time centered at 0, which has no effect on the result # assume vt0=0 (and mean(t0)=0) r=dim(exx)[1]-1 ones=rep(1,r+1) times=(s)*(0:r) Z=as.matrix(cbind(ones,times)) D=matrix(c(sigma20,sigma01,sigma01,sigma21),2,2) sigma=(Z%*%D%*%t(Z)+sigma2w*diag(r+1)) A=matrix(0,ncol=r+1,nrow=r) diag(A)=-1 for (i in 1:r) { A[i,i+1]=1 } M=t(A) %*% solve(A%*%(sigma)%*%t(A)) %*% A # Exposure process pe=diag(exx) mean.pe=mean(pe) Ex.x=exx # Needed quantities ones=rep(1,r+1) times=0:r c=t(times) %*% M %*% times e=sum(Ex.x*M) f=t(pe) %*% M %*% times k=t(times*pe)%*% M %*% times p=t(times)%*% (Ex.x*M) %*% ones u=t(times) %*% (Ex.x*M) %*% times E.X.S.X=matrix(c(e,s*f,s*p, s*f,(s^2)*c,(s^2)*k, s*p,(s^2)*k,(s^2)*u),ncol=3,nrow=3) var=solve(E.X.S.X)[3,3] return(var) } # ***************************************************** # * Var for cumulative effect model (marginal), * # * LDD, DEX response, CS exposure, fixed s, V(t0)=0 * # ***************************************************** long.var.s.tv.LDD.cum.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.LDD.cum.DEX(s,Ex.x,sigma2,rho,theta) } var.exx.LDD.cum.DEX=function(s,exx,sigma2,rho,theta) { # Var for cumulative effect model (marginal), # given the exposure covariance # LDD, DEX response, fixed s # assuming vt0=0 and V(E*0)=0 r=dim(exx)[1]-1 vec1=rep(0,r+1) vec1[1]=1 if (r==0) DEX=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } DEX=toeplitz(vec1) } pe=diag(exx) mean.pe=mean(pe) Ex.x=exx inv=solve(sigma2*DEX) ones=rep(1,r+1) times=0:r mat=matrix(0,ncol=3,nrow=3) mat[1,1]=sum(inv) cum.pe=pe for (i in 1:(r+1)) cum.pe[i]=sum(pe[1:i]) CE=matrix(cum.pe,nrow=r+1,ncol=r+1) mat[2,1]<-mat[1,2]<-sum(inv*CE) SE=matrix(0,nrow=r+1,ncol=r+1) for (i in 1:(r+1)) { for (j in 1:(r+1)) { SE[i,j]=sum(Ex.x[1:i,1:j]) } } mat[2,2]=sum(inv*SE) mat[3,1]<-mat[1,3]<-s*(t(times)%*%inv%*%ones) times=0:r mt=matrix(times,nrow=r+1,ncol=r+1,byrow=T) mat[3,2]<-mat[2,3]<-s*sum(inv*CE*mt) mat[3,3]=(s^2)*(t(times)%*%inv%*%times) solve(mat)[2,2] } long.var.s.tv.LDD.cum.RS=function(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) { # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.LDD.cum.RS(s,Ex.x,sigma2w,sigma20,sigma21,sigma01) } var.exx.LDD.cum.RS=function(s,exx,sigma2w,sigma20,sigma21,sigma01) { # Var for cumulative effect model (marginal), # given the exposure covariance # LDD, RS response, fixed s # assuming vt0=0 and V(E*0)=0 r=dim(exx)[1]-1 ones=rep(1,r+1) times=(s)*(0:r) Z=as.matrix(cbind(ones,times)) D=matrix(c(sigma20,sigma01,sigma01,sigma21),2,2) sigma=(Z%*%D%*%t(Z)+sigma2w*diag(r+1)) inv=solve(sigma) pe=diag(exx) mean.pe=mean(pe) Ex.x=exx mat=matrix(0,ncol=3,nrow=3) mat[1,1]=sum(inv) cum.pe=pe for (i in 1:(r+1)) cum.pe[i]=sum(pe[1:i]) CE=matrix(cum.pe,nrow=r+1,ncol=r+1) mat[2,1]<-mat[1,2]<-sum(inv*CE) SE=matrix(0,nrow=r+1,ncol=r+1) for (i in 1:(r+1)) { for (j in 1:(r+1)) { SE[i,j]=sum(Ex.x[1:i,1:j]) } } mat[2,2]=sum(inv*SE) times=0:r mat[3,1]<-mat[1,3]<-s*(t(times)%*%inv%*%ones) mt=matrix(times,nrow=r+1,ncol=r+1,byrow=T) mat[3,2]<-mat[2,3]<-s*sum(inv*CE*mt) mat[3,3]=(s^2)*(t(times)%*%inv%*%times) solve(mat)[2,2] } # ************************************************************************** # * Var for cumulative effect model (conditional or model on differences), * # * LDD, DEX response, CS exposure, fixed s, V(t0)=0 * # ************************************************************************** long.var.s.tv.LDD.cum.cond.DEX=function(r,s,pe,rho.e,sigma2,rho,theta) { # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.LDD.cum.cond.DEX(s,Ex.x,sigma2,rho,theta) } var.exx.LDD.cum.cond.DEX=function(s,exx,sigma2,rho,theta) { # Var for cumulative effect model (contional), # given the exposure covariance # LDD, DEX response, fixed s r=dim(exx)[1]-1 vec1=rep(0,r+1) vec1[1]=1 if (r==0) DEX=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } DEX=toeplitz(vec1) } A=matrix(0,ncol=r+1,nrow=r) diag(A)=-1 for (i in 1:r) { A[i,i+1]=1 } pe=diag(exx) mean.pe=mean(pe) Ex.x=exx S=A%*%(sigma2*DEX)%*%t(A) W=solve(S) Ex.x.sub=Ex.x[-1,-1] pe.sub=pe[-1] ones=rep(1,r) a=sum(W) b=ones%*%W%*%pe.sub c=sum(W*Ex.x.sub) as.real(a/(a*c-b^2)) } long.var.s.tv.LDD.cum.cond.RS=function(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) { # pe can be either a scalar or a vector of length r+1 # assuming V(t0)=0 if (length(pe)==1) pe=rep(pe,times=r+1) else rho.e=rhoe2rhox(r,pe,rho.e) Ex.x=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) Ex.x=rho.e*Ex.x+pe%*%t(pe) diag(Ex.x)=pe var.exx.LDD.cum.cond.RS(s,Ex.x,sigma2w,sigma20,sigma21,sigma01) } var.exx.LDD.cum.cond.RS=function(s,exx,sigma2w,sigma20,sigma21,sigma01) { # Var for cumulative effect model (contional), # given the exposure covariance # LDD, RS response, fixed s r=dim(exx)[1]-1 ones=rep(1,r+1) times=(s)*(0:r) Z=as.matrix(cbind(ones,times)) D=matrix(c(sigma20,sigma01,sigma01,sigma21),2,2) sigma=(Z%*%D%*%t(Z)+sigma2w*diag(r+1)) A=matrix(0,ncol=r+1,nrow=r) diag(A)=-1 for (i in 1:r) { A[i,i+1]=1 } S=A%*%(sigma)%*%t(A) W=solve(S) pe=diag(exx) mean.pe=mean(pe) Ex.x=exx Ex.x.sub=Ex.x[-1,-1] pe.sub=pe[-1] ones=rep(1,r) a=sum(W) b=ones%*%W%*%pe.sub c=sum(W*Ex.x.sub) as.real(a/(a*c-b^2)) } ### CS #### long.var.s.tv.CMD.marg.CS=function(r,s,pe,rho.e,sigma2,rho) { long.var.s.tv.CMD.marg.DEX(r,s,pe,rho.e,sigma2,rho,theta=0) } long.var.s.tv.CMD.cond.CS=function(r,s,pe,rho.e,sigma2,rho) { long.var.s.tv.CMD.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta=0) } long.var.s.tv.CMD.marg.time.CS=function(r,s,pe,rho.e,sigma2,rho) { long.var.s.tv.CMD.marg.time.DEX(r,s,pe,rho.e,sigma2,rho,theta=0) } long.var.s.tv.CMD.cond.time.CS=function(r,s,pe,rho.e,sigma2,rho) { long.var.s.tv.CMD.cond.time.DEX(r,s,pe,rho.e,sigma2,rho,theta=0) } long.var.s.tv.LDD.acute.CS=function(r,s,pe,rho.e,sigma2,rho) { long.var.s.tv.LDD.acute.DEX(r,s,pe,rho.e,sigma2,rho,theta=0) } long.var.s.tv.LDD.acute.cond.CS=function(r,s,pe,rho.e,sigma2,rho) { long.var.s.tv.LDD.acute.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta=0) } long.var.s.tv.LDD.cum.CS=function(r,s,pe,rho.e,sigma2,rho) { long.var.s.tv.LDD.cum.DEX(r,s,pe,rho.e,sigma2,rho,theta=0) } long.var.s.tv.LDD.cum.cond.CS=function(r,s,pe,rho.e,sigma2,rho) { long.var.s.tv.LDD.cum.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta=0) } ####### ################################## # 1.3 # # Auxiliary and other functions # ####### ################################## rhoe2rhox=function(r,pe,rho.e) { # returns the correlation coefficient of a CS exposure matrix with # intraclass correlation rho.e if (length(pe)==1) pe=rep(pe,times=r+1) mean.pe=mean(pe) pe.pe=pe%*%t(pe) sq=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) rho.x=(mean.pe*r*(r+1)*(mean.pe*(1-rho.e)+rho.e)-(sum(pe.pe)-sum(diag(pe.pe))))/ (sum(sq)-sum(diag(sq))) rho.x } rhox2rhoe=function(r,pe,rhox) { if (length(pe)==1) pe=rep(pe,times=r+1) mean.pe=mean(pe) pe.pe=pe%*%t(pe) sq=(sqrt(pe*(1-pe)))%*%t(sqrt(pe*(1-pe))) rhoe=( rhox*(sum(sq)-sum(diag(sq))) + sum(pe.pe)-sum(diag(pe.pe)) - (mean.pe^2)*r*(r+1) )/ (mean.pe*r*(r+1)*(1-mean.pe)) rhoe } upper.rhox=function(r,pe.vec) { mm=matrix(pe.vec,nrow=r+1,ncol=r+1,byrow=T) min=pmin(mm,t(mm)) pe.pe=pe.vec%*%t(pe.vec) sqpe=sqrt(pe.vec)*sqrt(1-pe.vec) mat=(min-pe.pe)/(sqpe%*%t(sqpe)) upper1=min(mat[lower.tri(mat)]) upper2=rhoe2rhox(r,pe.vec,upper.rhoe(r,pe.vec)) min(upper1,upper2) } lower.rhox=function(r,pe.vec) { mm=matrix(pe.vec,nrow=r+1,ncol=r+1,byrow=T) tomax=-(1-mm-t(mm)) max=matrix(pmax(0,tomax),nrow=r+1) pe.pe=pe.vec%*%t(pe.vec) sqpe=sqrt(pe.vec)*sqrt(1-pe.vec) mat=(max-pe.pe)/(sqpe%*%t(sqpe)) lower1=max(mat[lower.tri(mat)]) lower2=rhoe2rhox(r,pe.vec,lower.rhoe(r,pe.vec)) max(lower1,lower2) } lower.rhoe=function(r,pe.vec) { mean.pe=mean(pe.vec) lower=-1/r+( ((r+1)*mean.pe-floor((r+1)*mean.pe)) * (1-(r+1)*mean.pe+floor((r+1)*mean.pe)) ) / (r*(r+1)*mean.pe*(1-mean.pe)) lower } upper.rhoe=function(r,pe.vec) { # returns the upper value for rhoe given the prev vector mean.pe=mean(pe.vec) ord=pe.vec[order(pe.vec)] summ=0 for (j in 1:r) { summ=summ+(r-(j-1))*ord[j] } upper=(1/(1-mean.pe))*(2*summ/(mean.pe*r*(r+1))-mean.pe) upper } combinations = function(n, k){ # I got it from the web # Compute all n choose k combinations of size k from 1:n # Return matrix with k rows and choose(n,k) columns. # Avoids recursion. if(!is.numeric(n) || length(n) != 1 || n%%1) stop("'n' must be an integer") if(!is.numeric(k) || length(k) != 1 || k%%1) stop("'k' must be an integer") if(k > n || k <= 0) return(numeric(0)) rowMatrix = function(n) structure(1:n, dim=c(1,n)) colMatrix = function(n) structure(1:n, dim=c(n,1)) if(k == n) return(colMatrix(n)) if(k == 1) return(rowMatrix(n)) L = vector("list", k) # L[[j]] will contain combinations(N, j) for N = 2:n L[[1]] = rowMatrix(2) L[[2]] = colMatrix(2) Diff = n-k for(N in seq(3, n, by=1)){ # loop over j in reverse order, to avoid overwriting for(j in seq(min(k, N-1), max(2, N-Diff), by= -1)) L[[j]] = cbind(L[[j]], rbind(L[[j-1]], N, deparse.level=1)) if(N <= Diff+1) L[[1]] = rowMatrix(N) else L[[N-(Diff+1)]] = numeric(0) if(N <= k) L[[N]] = colMatrix(N) } L[[k]] } DEX.matrix=function(r,s,rho,theta) { vec1=rep(0,r+1) vec1[1]=1 if (r==0) sigma=1 else { for (j in 1:r) { vec1[j+1]=rho^((j*s)^theta) } sigma=toeplitz(vec1) } print(sigma) } RS.matrix=function(r,s,sigma2w,sigma20,sigma21,sigma01) { X.constant=rep(1,r+1) X.times=s*(0:r) X=as.matrix(cbind(X.constant,X.times)) D=matrix(c(sigma20,sigma01,sigma01,sigma21),2,2) sigma=X%*%D%*%t(X)+sigma2w*diag(r+1) corr=solve(diag(sqrt(diag(sigma)))) %*% sigma %*% solve(diag(sqrt(diag(sigma)))) cat("Covariance matrix:\n") print(sigma) cat("\nCorrelation matrix:\n") print(corr) } RS.matrix.reliab=function(r,s,sigma2,rho,rho.b1,rho01,r.tilde) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) X.constant=rep(1,r+1) X.times=s*(0:r) X=as.matrix(cbind(X.constant,X.times)) D=matrix(c(sigma20,sigma01,sigma01,sigma21),2,2) sigma=X%*%D%*%t(X)+sigma2w*diag(r+1) corr=solve(diag(sqrt(diag(sigma)))) %*% sigma %*% solve(diag(sqrt(diag(sigma)))) cat("Covariance matrix:\n") print(sigma) cat("\nCorrelation matrix:\n") print(corr) } #----- ------------- ###### ############# # 2. # # Modules # ###### ############# #----- ------------- ############################################################################# ############################################################################# # 2.1 Power ############################################################################# ############################################################################# #################### # 2.1.1. Functions # #################### # ---------------- # Time-invariant # # ---------------- ### CMD ### # ******************************************************* # * Power for CMD and CS when user enters beta, fixed s * # ******************************************************* long.power.s.CMD.coef.CS=function(N,r,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha=0.05) { var=long.var.s.CMD.CS(r,s,pe,vt0,rho.exp.t0,sigma2,rho) pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) } # ******************************************************** # * Power for CMD and DEX when user enters beta, fixed s * # ******************************************************** long.power.s.CMD.coef.DEX=function(N,r,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.CMD.DEX(r,s,pe,vt0,rho.exp.t0,sigma2,rho,theta) pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) } # ********************************* # * Power for CMD and RS, fixed s * # ********************************* long.power.s.CMD.coef.RS=function(N,r,s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.CMD.RS(r,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) } #### LDD #### # ************************************************ # * Power for LDD and CS when user enters gamma3 * # ************************************************ long.power.s.LDD.coef.CS=function(N,r,s,pe,vt0,rho.exp.t0,gamma,sigma2,rho,alpha=0.05) { var=long.var.s.LDD.CS(r,s,pe,vt0,rho.exp.t0,sigma2,rho) pnorm(sqrt(N)*abs(gamma)/sqrt(var)-qnorm(1-alpha/2)) } # ********************************************************** # * Power for LDD and DEX when user enters gamma3, fixed s * # ********************************************************** long.power.s.LDD.coef.DEX=function(N,r,s,pe,vt0,rho.exp.t0,gamma,sigma2,rho,theta,alpha=0.05) { var=long.var.s.LDD.DEX(r,s,pe,vt0,rho.exp.t0,sigma2,rho,theta) pnorm(sqrt(N)*abs(gamma)/sqrt(var)-qnorm(1-alpha/2)) } # ********************************* # * Power for LDD and RS, fixed s * # ********************************* long.power.s.LDD.coef.RS=function(N,r,s,pe,vt0,rho.exp.t0,gamma,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.LDD.RS(r,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) pnorm(sqrt(N)*abs(gamma)/sqrt(var)-qnorm(1-alpha/2)) } # -------------- # Time-varying # # -------------- ### CMD ### # ******************************************************** # * Power for CMD and DEX when user enters beta, fixed s * # ******************************************************** # Model without time, marginal long.power.s.tv.CMD.marg.coef.DEX=function(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.marg.DEX(r,s,pe,rho.e,sigma2,rho,theta) pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) } ## upper ## long.power.s.tv.upper.CMD.marg.coef.DEX=function(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.marg.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) power=-99 else power=pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) power } # Model without time, conditional long.power.s.tv.CMD.cond.coef.DEX=function(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) } #### upper #### long.power.s.tv.upper.CMD.cond.coef.DEX=function(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) power=-99 else power=pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) power } # Model with time, marginal long.power.s.tv.CMD.marg.time.coef.DEX=function(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.marg.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) } ### upper ### long.power.s.tv.upper.CMD.marg.time.coef.DEX=function(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.marg.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) power=-99 else power=pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) power } # Model with time, conditional long.power.s.tv.CMD.cond.time.coef.DEX=function(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.cond.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) } ### upper #### long.power.s.tv.upper.CMD.cond.time.coef.DEX=function(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.cond.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) power=-99 else power=pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) power } ### CS: long.power.s.tv.CMD.marg.coef.CS=function(N,r,s,pe,rho.e,beta,sigma2,rho,alpha=0.05) { long.power.s.tv.CMD.marg.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta=0,alpha) } long.power.s.tv.CMD.cond.coef.CS=function(N,r,s,pe,rho.e,beta,sigma2,rho,alpha=0.05) { long.power.s.tv.CMD.cond.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta=0,alpha) } long.power.s.tv.CMD.marg.time.coef.CS=function(N,r,s,pe,rho.e,beta,sigma2,rho,alpha=0.05) { long.power.s.tv.CMD.marg.time.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta=0,alpha) } long.power.s.tv.CMD.cond.time.coef.CS=function(N,r,s,pe,rho.e,beta,sigma2,rho,alpha=0.05) { long.power.s.tv.CMD.cond.time.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta=0,alpha) } ### RS #### # ******************************************************** # * Power for CMD and RS when user enters beta, fixed s * # ******************************************************** # Model without time, marginal long.power.s.tv.CMD.marg.coef.RS=function(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.marg.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) } # Model without time, conditional long.power.s.tv.CMD.cond.coef.RS=function(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.cond.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) } # Model with time, marginal long.power.s.tv.CMD.marg.time.coef.RS=function(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.marg.time.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) } # Model with time, conditional long.power.s.tv.CMD.cond.time.coef.RS=function(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.cond.time.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) pnorm(sqrt(N)*abs(beta)/sqrt(var)-qnorm(1-alpha/2)) } #### LDD #### ## DEX ## # Acute, marginal # ********************************************************** # * Power for LDD and DEX when user enters gamma3, fixed s * # ********************************************************** long.power.s.tv.LDD.acute.coef.DEX=function(N,r,s,pe,rho.e,gamma,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.acute.DEX(r,s,pe,rho.e,sigma2,rho,theta) pnorm(sqrt(N)*abs(gamma)/sqrt(var)-qnorm(1-alpha/2)) } # Acute, conditional # ********************************************************** # * Power for LDD and DEX when user enters gamma3, fixed s * # ********************************************************** long.power.s.tv.LDD.acute.cond.coef.DEX=function(N,r,s,pe,rho.e,gamma,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.acute.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) pnorm(sqrt(N)*abs(gamma)/sqrt(var)-qnorm(1-alpha/2)) } # Cumulative, marginal # ********************************************************** # * Power for LDD and DEX when user enters gamma3, fixed s * # ********************************************************** long.power.s.tv.LDD.cum.coef.DEX=function(N,r,s,pe,rho.e,gamma,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.cum.DEX(r,s,pe,rho.e,sigma2,rho,theta) pnorm(sqrt(N)*abs(gamma)/sqrt(var)-qnorm(1-alpha/2)) } # Cumulative, marginal # ********************************************************** # * Power for LDD and DEX when user enters gamma3, fixed s * # ********************************************************** long.power.s.tv.LDD.cum.cond.coef.DEX=function(N,r,s,pe,rho.e,gamma,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.cum.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) pnorm(sqrt(N)*abs(gamma)/sqrt(var)-qnorm(1-alpha/2)) } ## CS ## long.power.s.tv.LDD.acute.coef.CS=function(N,r,s,pe,rho.e,gamma,sigma2,rho,alpha=0.05) { long.power.s.tv.LDD.acute.coef.DEX(N,r,s,pe,rho.e,gamma,sigma2,rho,theta=0,alpha) } long.power.s.tv.LDD.acute.cond.coef.CS=function(N,r,s,pe,rho.e,gamma,sigma2,rho,alpha=0.05) { long.power.s.tv.LDD.acute.cond.coef.DEX(N,r,s,pe,rho.e,gamma,sigma2,rho,theta=0,alpha) } long.power.s.tv.LDD.cum.coef.CS=function(N,r,s,pe,rho.e,gamma,sigma2,rho,alpha=0.05) { long.power.s.tv.LDD.cum.coef.DEX(N,r,s,pe,rho.e,gamma,sigma2,rho,theta=0,alpha) } long.power.s.tv.LDD.cum.cond.coef.CS=function(N,r,s,pe,rho.e,gamma,sigma2,rho,alpha=0.05) { long.power.s.tv.LDD.cum.cond.coef.DEX(N,r,s,pe,rho.e,gamma,sigma2,rho,theta=0,alpha) } ### RS ### # ********************************* # * Power for LDD and RS, fixed s * # ********************************* # Acute, marginal long.power.s.tv.LDD.acute.coef.RS=function(N,r,s,pe,rho.e,gamma,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.acute.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) pnorm(sqrt(N)*abs(gamma)/sqrt(var)-qnorm(1-alpha/2)) } # Acute, conditional long.power.s.tv.LDD.acute.cond.coef.RS=function(N,r,s,pe,rho.e,gamma,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.acute.cond.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) pnorm(sqrt(N)*abs(gamma)/sqrt(var)-qnorm(1-alpha/2)) } # Cumulative, marginal long.power.s.tv.LDD.cum.coef.RS=function(N,r,s,pe,rho.e,gamma,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.cum.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) pnorm(sqrt(N)*abs(gamma)/sqrt(var)-qnorm(1-alpha/2)) } # Cumulative, conditional long.power.s.tv.LDD.cum.cond.coef.RS=function(N,r,s,pe,rho.e,gamma,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.cum.cond.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) pnorm(sqrt(N)*abs(gamma)/sqrt(var)-qnorm(1-alpha/2)) } ######################### # 2.1.2. User interface # ######################### long.power <- function() { # Initialize parameters N=100 r=1 s=1 tv=1 pe.type=1 pe=.5 rho.e=0.5 vt0=0 rho.exp.t0=0 pattern=1 model.cmd=1 model.ldd=1 notation=1 beta=0.1 mu00=10 p1=.1 correlation=1 sigma2=1 rho=0.8 theta=0.5 notation.rs=1 sigma2w=0.1 sigma20=0.3 sigma21=0.01 sigma01=0 r.tilde=5 rho.b1=0.1 rho01=0 gamma3=.1 p2=.1 p3=.1 alpha=0.05 finish=F while (finish==F) { cat("\n* By just pressing after each question, the default value, shown\n between square brackets, will be entered.\n\n") cat("* Press to quit\n\n") N=get.N(N) r=get.r(r) s=get.s(s) tau=s*r tv=get.tv(tv) if (tv==1) { # time-invariant pe=get.pe(pe) vt0=get.vt0(vt0) if (vt0!=0) rho.exp.t0=get.rho.exp.t0(rho.exp.t0) else rho.exp.t0=0 pattern=get.pattern(pattern) if (pattern == 1) { # CMD notation=get.notation(notation) if (notation==1) { beta=get.beta(beta) } else { mu00=get.mu00(mu00) p1=get.p1(p1) beta=p1*mu00 } correlation=get.correlation(correlation) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) power=long.power.s.CMD.coef.CS(N,r,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha) cat("Power = ", power,"\n\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) power=long.power.s.CMD.coef.DEX(N,r,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) cat("Power = ", power,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.CMD.coef.RS(N,r,s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Power = ", power,"\n") } } else { # LDD notation=get.notation(notation) if (notation==1) { gamma3=get.gamma(gamma3) } else { mu00=get.mu00(mu00) p2=get.p2(2,p2) if (p2==0) { p1=get.p1(p1) p3=get.p3.p20(2,p3) gamma3=(1+p1)*p3*mu00/(s*r) } else { p3=get.p3(2,p3) gamma3=p2*p3*mu00/(s*r) } } correlation=get.correlation(correlation) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) power=long.power.s.LDD.coef.CS(N,r,s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha) cat("Power = ", power,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) power=long.power.s.LDD.coef.DEX(N,r,s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha) cat("Power = ", power,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) if (vt0 == 0) { sigma01=0 } else sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) if (vt0 == 0) { rho01=0 } else rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.LDD.coef.RS(N,r,s,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Power = ", power,"\n") } } # end LDD } else { # TIME-VARYING pe.type=get.pe.type(pe.type) pe=get.pe.tv(pe.type,r,pe) rho.e=get.rhoe(r,pe,rho.e) pattern=get.pattern(pattern) if (pattern == 1) { # CMD model.cmd=get.model.cmd(model.cmd) notation=get.notation(notation) if (notation==1) { beta=get.beta.tv(beta) } else { mu00=get.mu00(mu00) p1=get.p1(p1) beta=p1*mu00 } correlation=get.correlation(correlation) if (model.cmd==1) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) power=long.power.s.tv.CMD.marg.coef.CS(N,r,s,pe,rho.e,beta,sigma2,rho,alpha) cat("Power = ", power,"\n\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) power=long.power.s.tv.CMD.marg.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) cat("Power = ", power,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) power.lower=long.power.s.tv.upper.CMD.marg.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) if (power.lower==-99) cat("Power lower bound for rho.e=",rho.e," did not converge\n\n") else cat("Power lower bound for rho.e=",rho.e,": ",power.lower,"\n\n") } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.CMD.marg.coef.RS(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Power = ", power,"\n") } # end correlation } else if (model.cmd==2) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) power=long.power.s.tv.CMD.cond.coef.CS(N,r,s,pe,rho.e,beta,sigma2,rho,alpha) cat("Power = ", power,"\n\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) power=long.power.s.tv.CMD.cond.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) cat("Power = ", power,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) power.lower=long.power.s.tv.upper.CMD.cond.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) if (power.lower==-99) cat("Power lower bound for rho.e=",rho.e," did not converge\n\n") else cat("Power lower bound for rho.e=",rho.e,": ",power.lower,"\n\n") } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.CMD.cond.coef.RS(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Power = ", power,"\n") } # end correlation } else if (model.cmd==3) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) power=long.power.s.tv.CMD.marg.time.coef.CS(N,r,s,pe,rho.e,beta,sigma2,rho,alpha) cat("Power = ", power,"\n\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) power=long.power.s.tv.CMD.marg.time.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) cat("Power = ", power,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) power.lower=long.power.s.tv.upper.CMD.marg.time.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) if (power.lower==-99) cat("Power lower bound for rho.e=",rho.e," did not converge\n\n") else cat("Power lower bound for rho.e=",rho.e,": ",power.lower,"\n\n") } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.CMD.marg.time.coef.RS(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Power = ", power,"\n") } # end correlation } else { # (model.cmd==4) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) power=long.power.s.tv.CMD.cond.time.coef.CS(N,r,s,pe,rho.e,beta,sigma2,rho,alpha) cat("Power = ", power,"\n\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) power=long.power.s.tv.CMD.cond.time.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) cat("Power = ", power,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) power.lower=long.power.s.tv.upper.CMD.cond.time.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) if (power.lower==-99) cat("Power lower bound for rho.e=",rho.e," did not converge\n\n") else cat("Power lower bound for rho.e=",rho.e,": ",power.lower,"\n\n") } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.CMD.cond.time.coef.RS(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Power = ", power,"\n") } # end correlation } # end model.cmd } else { # LDD model.ldd=get.model.ldd(model.ldd) notation=get.notation(notation) if (notation==1) { gamma3=get.gamma.tv(gamma3) } else { mu00=get.mu00(mu00) p2=get.p2(2,p2) if (p2==0) { p1=get.p1(p1) p3=get.p3.p20(2,p3) gamma3=(1+p1)*p3*mu00/(s*r) } else { p3=get.p3(2,p3) gamma3=p2*p3*mu00/(s*r) } } correlation=get.correlation(correlation) if (model.ldd==1) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) power=long.power.s.tv.LDD.cum.coef.CS(N,r,s,pe,rho.e,gamma3,sigma2,rho,alpha) cat("Power = ", power,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) power=long.power.s.tv.LDD.cum.coef.DEX(N,r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("Power = ", power,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.LDD.cum.coef.RS(N,r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Power = ", power,"\n") } # end correlation } else if (model.ldd==2) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) power=long.power.s.tv.LDD.cum.cond.coef.CS(N,r,s,pe,rho.e,gamma3,sigma2,rho,alpha) cat("Power = ", power,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) power=long.power.s.tv.LDD.cum.cond.coef.DEX(N,r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("Power = ", power,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.LDD.cum.cond.coef.RS(N,r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Power = ", power,"\n") } # end correlation } else if (model.ldd==3) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) power=long.power.s.tv.LDD.acute.coef.CS(N,r,s,pe,rho.e,gamma3,sigma2,rho,alpha) cat("Power = ", power,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) power=long.power.s.tv.LDD.acute.coef.DEX(N,r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("Power = ", power,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.LDD.acute.coef.RS(N,r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Power = ", power,"\n") } # end correlation } else { # (model.ldd==4) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) power=long.power.s.tv.LDD.acute.cond.coef.CS(N,r,s,pe,rho.e,gamma3,sigma2,rho,alpha) cat("Power = ", power,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) power=long.power.s.tv.LDD.acute.cond.coef.DEX(N,r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("Power = ", power,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.LDD.acute.cond.coef.RS(N,r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Power = ", power,"\n") } # end correlation } # end model.ldd } # end LDD } # end time-varying finish=get.finish() } } ######################## # 2.1.3. Batch command # ######################## long.power.batch <- function(N=100,r=1,fixed=1,s.or.tau=1,tv=1,pe.type=1,pe=.5, rho.e=0.5,vt0=0,rho.exp.t0=0,pattern=1,model.cmd=1, model.ldd=1,notation=1,beta=.1,mu00=10,p1=.1, correlation=1,sigma2=1,rho=.8,theta=0, notation.rs=1,sigma2w=.03,sigma20=0.27, sigma21=0.01,sigma01=0,r.tilde=1,rho.b1=.1, rho01=0,gamma3=.1,p2=.1,p3=.1,alpha=0.05) { if (fixed==1) s=s.or.tau else s=s.or.tau/r if (tv==1) { # time-invariant if (pattern == 1) { # CMD if (notation==2) beta=p1*mu00 if (correlation==1) { power=long.power.s.CMD.coef.CS(N,r,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha) } else if (correlation==2) { power=long.power.s.CMD.coef.DEX(N,r,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.CMD.coef.RS(N,r,s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { # LDD if (notation==2) { if (p2==0) { gamma3=(1+p1)*p3*mu00/(s.or.tau) } else { gamma3=p2*p3*mu00/(s.or.tau) } } if (correlation==1) { power=long.power.s.LDD.coef.CS(N,r,s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha) } else if (correlation==2) { power=long.power.s.LDD.coef.DEX(N,r,s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.LDD.coef.RS(N,r,s,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } } # end LDD } else { # TIME-VARYING if (pattern == 1) { # CMD if (notation==2) beta=p1*mu00 if (model.cmd==1) { if (correlation==1) { power=long.power.s.tv.CMD.marg.coef.CS(N,r,s,pe,rho.e,beta,sigma2,rho,alpha) } else if (correlation==2) { power=long.power.s.tv.CMD.marg.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.CMD.marg.coef.RS(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } else if (model.cmd==2) { if (correlation==1) { power=long.power.s.tv.CMD.cond.coef.CS(N,r,s,pe,rho.e,beta,sigma2,rho,alpha) } else if (correlation==2) { power=long.power.s.tv.CMD.cond.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.CMD.cond.coef.RS(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } else if (model.cmd==3) { if (correlation==1) { power=long.power.s.tv.CMD.marg.time.coef.CS(N,r,s,pe,rho.e,beta,sigma2,rho,alpha) } else if (correlation==2) { power=long.power.s.tv.CMD.marg.time.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.CMD.marg.time.coef.RS(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } else { # (model.cmd==4) if (correlation==1) { power=long.power.s.tv.CMD.cond.time.coef.CS(N,r,s,pe,rho.e,beta,sigma2,rho,alpha) } else if (correlation==2) { power=long.power.s.tv.CMD.cond.time.coef.DEX(N,r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.CMD.cond.time.coef.RS(N,r,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } # end model.cmd } else { # LDD if (notation==2) { if (p2==0) { gamma3=(1+p1)*p3*mu00/(s.or.tau) } else { gamma3=p2*p3*mu00/(s.or.tau) } } if (model.ldd==1) { if (correlation==1) { power=long.power.s.tv.LDD.cum.coef.CS(N,r,s,pe,rho.e,gamma3,sigma2,rho,alpha) } else if (correlation==2) { power=long.power.s.tv.LDD.cum.coef.DEX(N,r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.LDD.cum.coef.RS(N,r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } else if (model.ldd==2) { if (correlation==1) { power=long.power.s.tv.LDD.cum.cond.coef.CS(N,r,s,pe,rho.e,gamma3,sigma2,rho,alpha) } else if (correlation==2) { power=long.power.s.tv.LDD.cum.cond.coef.DEX(N,r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.LDD.cum.cond.coef.RS(N,r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } else if (model.ldd==3) { if (correlation==1) { power=long.power.s.tv.LDD.acute.coef.CS(N,r,s,pe,rho.e,gamma3,sigma2,rho,alpha) } else if (correlation==2) { power=long.power.s.tv.LDD.acute.coef.DEX(N,r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.LDD.acute.coef.RS(N,r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } else { # (model.ldd==4) if (correlation==1) { power=long.power.s.tv.LDD.acute.cond.coef.CS(N,r,s,pe,rho.e,gamma3,sigma2,rho,alpha) } else if (correlation==2) { power=long.power.s.tv.LDD.acute.cond.coef.DEX(N,r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } power=long.power.s.tv.LDD.acute.cond.coef.RS(N,r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } # end model.ldd } # end LDD } # end time-varying power } ########################## # 2.1.4. Batch functions # ########################## ###### # P1 # ###### power.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","alpha")) pattern=1 notation=2 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # P2 # ###### power.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","theta","alpha")) pattern=1 notation=2 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # P3 # ###### power.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=2 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # P4 # ###### power.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=2 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # P5 # ###### power.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","alpha")) pattern=1 notation=1 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # P6 # ###### power.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","theta","alpha")) pattern=1 notation=1 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # P7 # ###### power.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=1 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # P8 # ###### power.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=1 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # P9 # ###### power.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","alpha")) pattern=2 notation=2 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P10 # ####### power.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","theta","alpha")) pattern=2 notation=2 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P11 # ####### power.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=2 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P12 # ####### power.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=2 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P13 # ####### power.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","alpha")) pattern=2 notation=1 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P14 # ####### power.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","theta","alpha")) pattern=2 notation=1 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P15 # ####### power.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=1 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P16 # ####### power.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=1 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P17 # ####### power.tv.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","p1","sigma2","rho","alpha")) pattern=1 notation=2 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P18 # ####### power.tv.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","p1","sigma2","rho","theta","alpha")) pattern=1 notation=2 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P19 # ####### power.tv.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","p1","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=2 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P20 # ####### power.tv.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","p1","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=2 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P21 # ####### power.tv.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","beta","sigma2","rho","alpha")) pattern=1 notation=1 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P22 # ####### power.tv.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","beta","sigma2","rho","theta","alpha")) pattern=1 notation=1 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P23 # ####### power.tv.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","beta","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=1 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P24 # ####### power.tv.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","beta","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=1 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P25 # ####### power.tv.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","alpha")) pattern=2 notation=2 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P26 # ####### power.tv.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","theta","alpha")) pattern=2 notation=2 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P27 # ####### power.tv.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=2 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P28 # ####### power.tv.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=2 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P29 # ####### power.tv.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","gamma3","sigma2","rho","alpha")) pattern=2 notation=1 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P30 # ####### power.tv.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","gamma3","sigma2","rho","theta","alpha")) pattern=2 notation=1 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P31 # ####### power.tv.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","gamma3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=1 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # P32 # ####### power.tv.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","gamma3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=1 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.power.batch(N=N[i],r=r[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ############################################################################# ############################################################################# # 2.2. Sample size ############################################################################# ############################################################################# # For sample size and power, it doesn't matter wheter it's fixed s or tau. # Knowing one of them, since r is fixed, I know the other #################### # 2.2.1. Functions # #################### # -------------- # Time-invariant # -------------- ### CMD ### # **************************************************** # * Sample size for CMD and CS when user enters beta * # **************************************************** long.N.s.CMD.coef.CS=function(r,Pi,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha=0.05) { var=long.var.s.CMD.CS(r,s,pe,vt0,rho.exp.t0,sigma2,rho) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) } # ************************************************************ # Sample size for CMD and DEX when user enters beta, fixed s * # ************************************************************ long.N.s.CMD.coef.DEX=function(r,Pi,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.CMD.DEX(r,s,pe,vt0,rho.exp.t0,sigma2,rho,theta) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) } # **************************************************** # * Sample size for CMD and RS when user enters beta * # **************************************************** long.N.s.CMD.coef.RS=function(r,Pi,s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.CMD.RS(r,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) } #### LDD #### # ****************************************************** # * Sample size for LDD and CS when user enters gamma3 * # ****************************************************** long.N.s.LDD.coef.CS=function(r,Pi,s,pe,vt0,rho.exp.t0,gamma,sigma2,rho,alpha=0.05) { var=long.var.s.LDD.CS(r,s,pe,vt0,rho.exp.t0,sigma2,rho) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma^2)) } # ******************************************************* # * Sample size for LDD and DEX when user enters gamma3 * # ******************************************************* long.N.s.LDD.coef.DEX=function(r,Pi,s,pe,vt0,rho.exp.t0,gamma,sigma2,rho,theta,alpha=0.05) { var=long.var.s.LDD.DEX(r,s,pe,vt0,rho.exp.t0,sigma2,rho,theta) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma^2)) } # ****************************************************** # * Sample size for LDD and RS when user enters gamma3 * # ****************************************************** long.N.s.LDD.coef.RS=function(r,Pi,s,pe,vt0,rho.exp.t0,gamma,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.LDD.RS(r,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma^2)) } # ------------ # Time-varying # ------------ ### CMD ### # **************************************************** # * N for CMD and DEX when user enters beta, fixed s * # **************************************************** # Model without time, marginal long.N.s.tv.CMD.marg.coef.DEX=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.marg.DEX(r,s,pe,rho.e,sigma2,rho,theta) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) } ## upper ## long.N.s.tv.upper.CMD.marg.coef.DEX=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.marg.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) N=-99 else N=ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) N } # Model without time, conditional long.N.s.tv.CMD.cond.coef.DEX=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) } ## upper ## long.N.s.tv.upper.CMD.cond.coef.DEX=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) N=-99 else N=ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) N } # Model with time, marginal long.N.s.tv.CMD.marg.time.coef.DEX=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.marg.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) } ## upper ## long.N.s.tv.upper.CMD.marg.time.coef.DEX=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.marg.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) N=-99 else N=ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) N } # Model with time, conditional long.N.s.tv.CMD.cond.time.coef.DEX=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.marg.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) } ## upper ## long.N.s.tv.upper.CMD.cond.time.coef.DEX=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.marg.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) N=-99 else N=ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) N } ### CS: long.N.s.tv.CMD.marg.coef.CS=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha=0.05) { long.N.s.tv.CMD.marg.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta=0,alpha) } long.N.s.tv.CMD.cond.coef.CS=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha=0.05) { long.N.s.tv.CMD.cond.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta=0,alpha) } long.N.s.tv.CMD.marg.time.coef.CS=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha=0.05) { long.N.s.tv.CMD.marg.time.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta=0,alpha) } long.N.s.tv.CMD.cond.time.coef.CS=function(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha=0.05) { long.N.s.tv.CMD.cond.time.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta=0,alpha) } ### RS #### # Model without time, marginal long.N.s.tv.CMD.marg.coef.RS=function(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.marg.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) } # Model without time, conditional long.N.s.tv.CMD.cond.coef.RS=function(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.cond.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) } # Model with time, marginal long.N.s.tv.CMD.marg.time.coef.RS=function(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.marg.time.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) } # Model with time, conditional long.N.s.tv.CMD.cond.time.coef.RS=function(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.marg.time.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) } #### LDD #### ## DEX ## # ****************************************************** # * N for LDD and DEX when user enters gamma3, fixed s * # ****************************************************** # Acute, marginal long.N.s.tv.LDD.acute.coef.DEX=function(r,Pi,s,pe,rho.e,gamma,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.acute.DEX(r,s,pe,rho.e,sigma2,rho,theta) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma^2)) } # Acute, conditional long.N.s.tv.LDD.acute.cond.coef.DEX=function(r,Pi,s,pe,rho.e,gamma,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.acute.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma^2)) } # Cumulative, marginal long.N.s.tv.LDD.cum.coef.DEX=function(r,Pi,s,pe,rho.e,gamma,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.cum.DEX(r,s,pe,rho.e,sigma2,rho,theta) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma^2)) } # Cumulative, conditional long.N.s.tv.LDD.cum.cond.coef.DEX=function(r,Pi,s,pe,rho.e,gamma,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.cum.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma^2)) } ## CS ## long.N.s.tv.LDD.acute.coef.CS=function(r,Pi,s,pe,rho.e,gamma,sigma2,rho,alpha=0.05) { long.N.s.tv.LDD.acute.coef.DEX(r,Pi,s,pe,rho.e,gamma,sigma2,rho,theta=0,alpha) } long.N.s.tv.LDD.acute.cond.coef.CS=function(r,Pi,s,pe,rho.e,gamma,sigma2,rho,alpha=0.05) { long.N.s.tv.LDD.acute.cond.coef.DEX(r,Pi,s,pe,rho.e,gamma,sigma2,rho,theta=0,alpha) } long.N.s.tv.LDD.cum.coef.CS=function(r,Pi,s,pe,rho.e,gamma,sigma2,rho,alpha=0.05) { long.N.s.tv.LDD.cum.coef.DEX(r,Pi,s,pe,rho.e,gamma,sigma2,rho,theta=0,alpha) } long.N.s.tv.LDD.cum.cond.coef.CS=function(r,Pi,s,pe,rho.e,gamma,sigma2,rho,alpha=0.05) { long.N.s.tv.LDD.cum.cond.coef.DEX(r,Pi,s,pe,rho.e,gamma,sigma2,rho,theta=0,alpha) } ### RS ### # ***************************** # * N for LDD and RS, fixed s * # ***************************** # Acute, marginal long.N.s.tv.LDD.acute.coef.RS=function(r,Pi,s,pe,rho.e,gamma,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.acute.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma^2)) } # Acute, conditional long.N.s.tv.LDD.acute.cond.coef.RS=function(r,Pi,s,pe,rho.e,gamma,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.acute.cond.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma^2)) } # Cumulative, marginal long.N.s.tv.LDD.cum.coef.RS=function(r,Pi,s,pe,rho.e,gamma,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.cum.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma^2)) } # Cumulative, conditional long.N.s.tv.LDD.cum.cond.coef.RS=function(r,Pi,s,pe,rho.e,gamma,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.cum.cond.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) ceiling(var*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma^2)) } ######################### # 2.2.2. User interface # ######################### long.N <- function() { # Initialize parameters r=1 Pi=0.8 s=1 tv=1 pe.type=1 pe=.5 vt0=0 rho.exp.t0=0 rho.e=0.5 pattern=1 model.cmd=1 model.ldd=1 notation=1 beta=0.1 mu00=10 p1=.1 correlation=1 sigma2=1 rho=0.8 theta=0.5 notation.rs=1 sigma2w=0.1 sigma20=0.3 sigma21=0.01 sigma01=0 r.tilde=5 rho.b1=0.1 rho01=0 gamma3=.1 p2=.1 p3=.1 alpha=0.05 finish=F while (finish==F) { cat("\n* By just pressing after each question, the default value, shown\n between square brackets, will be entered.\n\n") cat("* Press to quit\n\n") r=get.r(r) Pi=get.Pi(Pi) s=get.s(s) tau=s*r tv=get.tv(tv) if (tv==1) { # time-invariant pe=get.pe(pe) vt0=get.vt0(vt0) if (vt0!=0) rho.exp.t0=get.rho.exp.t0(rho.exp.t0) else rho.exp.t0=0 pattern=get.pattern(pattern) if (pattern == 1) { # CMD notation=get.notation(notation) if (notation == 1) { beta=get.beta(beta) } else { mu00=get.mu00(mu00) p1=get.p1(p1) beta=p1*mu00 } correlation=get.correlation(correlation) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) N=long.N.s.CMD.coef.CS(r,Pi,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha) cat("Sample size = ", N,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) N=long.N.s.CMD.coef.DEX(r,Pi,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) cat("Sample size = ", N,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.CMD.coef.RS(r,Pi,s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Sample size = ", N,"\n") } } else { # LDD notation=get.notation(notation) if (notation == 1) gamma3=get.gamma(gamma3) else { mu00=get.mu00(mu00) p2=get.p2(2,p2) if (p2==0) { p1=get.p1(p1) p3=get.p3.p20(2,p3) gamma3=(1+p1)*p3*mu00/(s*r) } else { p3=get.p3(2,p3) gamma3=p2*p3*mu00/(s*r) } } correlation=get.correlation(correlation) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) N=long.N.s.LDD.coef.CS(r,Pi,s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha) cat("Sample size = ", N,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) N=long.N.s.LDD.coef.DEX(r,Pi,s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha) cat("Sample size = ", N,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) if (vt0 == 0) { sigma01=0 } else { sigma01=get.sigma01(sigma01) } } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) if (vt0 == 0) rho01=0 else rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.LDD.coef.RS(r,Pi,s,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Sample size = ", N,"\n") } # end correlation } # end LDD } else { # TIME-VARYING pe.type=get.pe.type(pe.type) pe=get.pe.tv(pe.type,r,pe) rho.e=get.rhoe(r,pe,rho.e) pattern=get.pattern(pattern) if (pattern == 1) { # CMD model.cmd=get.model.cmd(model.cmd) notation=get.notation(notation) if (notation == 1) { beta=get.beta(beta) } else { mu00=get.mu00(mu00) p1=get.p1(p1) beta=p1*mu00 } correlation=get.correlation(correlation) if (model.cmd==1) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) N=long.N.s.tv.CMD.marg.coef.CS(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha) cat("Sample size = ", N,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) N=long.N.s.tv.CMD.marg.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) cat("Sample size = ", N,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) N.lower=long.N.s.tv.upper.CMD.marg.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) if (N.lower==-99) cat("Upper bound for N when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for N when rho.e=",rho.e,": ",N.lower,"\n\n") } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.CMD.marg.coef.RS(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Sample size = ", N,"\n") } # end correlation } else if (model.cmd==2) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) N=long.N.s.tv.CMD.cond.coef.CS(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha) cat("Sample size = ", N,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) N=long.N.s.tv.CMD.cond.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) cat("Sample size = ", N,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) N.lower=long.N.s.tv.upper.CMD.cond.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) if (N.lower==-99) cat("Upper bound for N when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for N when rho.e=",rho.e,": ",N.lower,"\n\n") } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.CMD.cond.coef.RS(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Sample size = ", N,"\n") } # end correlation } else if (model.cmd==3) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) N=long.N.s.tv.CMD.marg.time.coef.CS(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha) cat("Sample size = ", N,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) N=long.N.s.tv.CMD.marg.time.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) cat("Sample size = ", N,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) N.lower=long.N.s.tv.upper.CMD.marg.time.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) if (N.lower==-99) cat("Upper bound for N when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for N when rho.e=",rho.e,": ",N.lower,"\n\n") } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.CMD.marg.time.coef.RS(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Sample size = ", N,"\n") } # end correlation } else { # model.cmd==4 if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) N=long.N.s.tv.CMD.cond.time.coef.CS(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha) cat("Sample size = ", N,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) N=long.N.s.tv.CMD.cond.time.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) cat("Sample size = ", N,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) N.lower=long.N.s.tv.upper.CMD.cond.time.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) if (N.lower==-99) cat("Upper bound for N when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for N when rho.e=",rho.e,": ",N.lower,"\n\n") } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.CMD.cond.time.coef.RS(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Sample size = ", N,"\n") } # end correlation } # end model.cmd } else { # LDD model.ldd=get.model.ldd(model.ldd) notation=get.notation(notation) if (notation == 1) gamma3=get.gamma(gamma3) else { mu00=get.mu00(mu00) p2=get.p2(2,p2) if (p2==0) { p1=get.p1(p1) p3=get.p3.p20(2,p3) gamma3=(1+p1)*p3*mu00/(s*r) } else { p3=get.p3(2,p3) gamma3=p2*p3*mu00/(s*r) } } correlation=get.correlation(correlation) if (model.ldd==1) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) N=long.N.s.tv.LDD.cum.coef.CS(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,alpha) cat("Sample size = ", N,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) N=long.N.s.tv.LDD.cum.coef.DEX(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("Sample size = ", N,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.LDD.cum.coef.RS(r,Pi,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Sample size = ", N,"\n") }# end correlation } else if (model.ldd==2) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) N=long.N.s.tv.LDD.cum.cond.coef.CS(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,alpha) cat("Sample size = ", N,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) N=long.N.s.tv.LDD.cum.cond.coef.DEX(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("Sample size = ", N,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.LDD.cum.cond.coef.RS(r,Pi,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Sample size = ", N,"\n") }# end correlation } else if (model.ldd==3) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) N=long.N.s.tv.LDD.acute.coef.CS(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,alpha) cat("Sample size = ", N,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) N=long.N.s.tv.LDD.acute.coef.DEX(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("Sample size = ", N,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.LDD.acute.coef.RS(r,Pi,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Sample size = ", N,"\n") }# end correlation } else { # model.ldd==4 if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) N=long.N.s.tv.LDD.acute.cond.coef.CS(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,alpha) cat("Sample size = ", N,"\n") } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) N=long.N.s.tv.LDD.acute.cond.coef.DEX(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("Sample size = ", N,"\n") } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.LDD.acute.cond.coef.RS(r,Pi,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Sample size = ", N,"\n") }# end correlation } } # end LDD } # end time-varying finish=get.finish() } # end while } ######################## # 2.2.3. Batch command # ######################## long.N.batch <- function(r=1,Pi=0.8,fixed,s.or.tau=1,tv=1,pe.type=1,pe=.5,vt0=0,rho.exp.t0=0, rho.e=0.5,pattern=1,model.cmd=1,model.ldd=1,notation=1, beta=0.1,mu00=10,p1=.1,correlation=1,sigma2=1,rho=0.8, theta=0.5,notation.rs=1,sigma2w=0.1,sigma20=0.3,sigma21=0.01, sigma01=0,r.tilde=5,rho.b1=0.1,rho01=0,gamma3=.1,p2=.1,p3=.1, alpha=0.05) { if (fixed==1) s=s.or.tau else s=s.or.tau/r if (tv==1) { # time-invariant if (pattern == 1) { # CMD if (notation == 2) beta=p1*mu00 if (correlation==1) { N=long.N.s.CMD.coef.CS(r,Pi,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha) } else if (correlation==2) { N=long.N.s.CMD.coef.DEX(r,Pi,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.CMD.coef.RS(r,Pi,s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { # LDD if (notation == 2) { if (p2==0) { gamma3=(1+p1)*p3*mu00/s.or.tau } else { gamma3=p2*p3*mu00/s.or.tau } } if (correlation==1) { N=long.N.s.LDD.coef.CS(r,Pi,s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha) } else if (correlation==2) { N=long.N.s.LDD.coef.DEX(r,Pi,s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.LDD.coef.RS(r,Pi,s,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } # end LDD } else { # TIME-VARYING if (pattern == 1) { # CMD if (notation == 2) beta=p1*mu00 if (model.cmd==1) { if (correlation==1) { N=long.N.s.tv.CMD.marg.coef.CS(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha) } else if (correlation==2) { N=long.N.s.tv.CMD.marg.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.CMD.marg.coef.RS(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } else if (model.cmd==2) { if (correlation==1) { N=long.N.s.tv.CMD.cond.coef.CS(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha) } else if (correlation==2) { N=long.N.s.tv.CMD.cond.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.CMD.cond.coef.RS(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } else if (model.cmd==3) { if (correlation==1) { N=long.N.s.tv.CMD.marg.time.coef.CS(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha) } else if (correlation==2) { N=long.N.s.tv.CMD.marg.time.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.CMD.marg.time.coef.RS(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } else { # model.cmd==4 if (correlation==1) { N=long.N.s.tv.CMD.cond.time.coef.CS(r,Pi,s,pe,rho.e,beta,sigma2,rho,alpha) } else if (correlation==2) { N=long.N.s.tv.CMD.cond.time.coef.DEX(r,Pi,s,pe,rho.e,beta,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.CMD.cond.time.coef.RS(r,Pi,s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } # end correlation } # end model.cmd } else { # LDD if (notation == 2) { if (p2==0) { gamma3=(1+p1)*p3*mu00/(s.or.tau) } else { gamma3=p2*p3*mu00/(s.or.tau) } } if (model.ldd==1) { if (correlation==1) { N=long.N.s.tv.LDD.cum.coef.CS(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,alpha) } else if (correlation==2) { N=long.N.s.tv.LDD.cum.coef.DEX(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.LDD.cum.coef.RS(r,Pi,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) }# end correlation } else if (model.ldd==2) { if (correlation==1) { N=long.N.s.tv.LDD.cum.cond.coef.CS(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,alpha) } else if (correlation==2) { N=long.N.s.tv.LDD.cum.cond.coef.DEX(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.LDD.cum.cond.coef.RS(r,Pi,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) }# end correlation } else if (model.ldd==3) { if (correlation==1) { N=long.N.s.tv.LDD.acute.coef.CS(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,alpha) } else if (correlation==2) { N=long.N.s.tv.LDD.acute.coef.DEX(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.LDD.acute.coef.RS(r,Pi,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) }# end correlation } else { # model.ldd==4 if (correlation==1) { N=long.N.s.tv.LDD.acute.cond.coef.CS(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,alpha) } else if (correlation==2) { N=long.N.s.tv.LDD.acute.cond.coef.DEX(r,Pi,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } N=long.N.s.tv.LDD.acute.cond.coef.RS(r,Pi,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) }# end correlation } } # end LDD } # end time-varying N } ######################## # 2.2.4. Batch command # ######################## ###### # N1 # ###### N.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","alpha")) pattern=1 notation=2 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # N2 # ###### N.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","theta","alpha")) pattern=1 notation=2 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # N3 # ###### N.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=2 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # N4 # ###### N.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=2 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # N5 # ###### N.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","alpha")) pattern=1 notation=1 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # N6 # ###### N.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","theta","alpha")) pattern=1 notation=1 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # N7 # ###### N.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=1 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # N8 # ###### N.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=1 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # N9 # ###### N.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","alpha")) pattern=2 notation=2 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N10 # ####### N.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","theta","alpha")) pattern=2 notation=2 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N11 # ####### N.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=2 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N12 # ####### N.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=2 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N13 # ####### N.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","alpha")) pattern=2 notation=1 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N14 # ####### N.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","theta","alpha")) pattern=2 notation=1 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N15 # ####### N.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=1 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N16 # ####### N.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=1 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N17 # ####### N.tv.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","p1","sigma2","rho","alpha")) pattern=1 notation=2 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N18 # ####### N.tv.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","p1","sigma2","rho","theta","alpha")) pattern=1 notation=2 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N19 # ####### N.tv.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","p1","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=2 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N20 # ####### N.tv.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","p1","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=2 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N21 # ####### N.tv.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","beta","sigma2","rho","alpha")) pattern=1 notation=1 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N22 # ####### N.tv.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","beta","sigma2","rho","theta","alpha")) pattern=1 notation=1 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N23 # ####### N.tv.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","beta","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=1 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N24 # ####### N.tv.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","beta","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=1 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N25 # ####### N.tv.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","alpha")) pattern=2 notation=2 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N26 # ####### N.tv.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","theta","alpha")) pattern=2 notation=2 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N27 # ####### N.tv.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=2 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N28 # ####### N.tv.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=2 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N29 # ####### N.tv.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","gamma3","sigma2","rho","alpha")) pattern=2 notation=1 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N30 # ####### N.tv.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","gamma3","sigma2","rho","theta","alpha")) pattern=2 notation=1 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N31 # ####### N.tv.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","gamma3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=1 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # N32 # ####### N.tv.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","gamma3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=1 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.N.batch(r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ############################################################################# ############################################################################# # 2.3. Minimum detectable effect ############################################################################# ############################################################################# #################### # 2.3.1. Functions # #################### # -------------- # Time-invariant # -------------- ### CMD ### # ******************************************************* # * Minimum effect for CMD and CS when user enters beta * # ******************************************************* long.effect.s.CMD.coef.CS=function(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,alpha=0.05) { var=long.var.s.CMD.CS(r,s,pe,vt0,rho.exp.t0,sigma2,rho) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # ******************************************************** # * Minimum effect for CMD and DEX when user enters beta * # ******************************************************** long.effect.s.CMD.coef.DEX=function(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,theta,alpha=0.05) { var=long.var.s.CMD.DEX(r,s,pe,vt0,rho.exp.t0,sigma2,rho,theta) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # ******************************************************* # * Minimum effect for CMD and RS when user enters beta * # ******************************************************* long.effect.s.CMD.coef.RS=function(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.CMD.RS(r,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } #### LDD #### # ********************************************************* # * Minimum effect for LDD and CS when user enters gamma3 * # ********************************************************* long.effect.s.LDD.coef.CS=function(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,alpha=0.05) { var=long.var.s.LDD.CS(r,s,pe,vt0,rho.exp.t0,sigma2,rho) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # ********************************************************** # * Minimum effect for LDD and DEX when user enters gamma3 * # ********************************************************** long.effect.s.LDD.coef.DEX=function(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,theta,alpha=0.05) { var=long.var.s.LDD.DEX(r,s,pe,vt0,rho.exp.t0,sigma2,rho,theta) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # ********************************************************* # * Minimum effect for LDD and RS when user enters gamma3 * # ********************************************************* long.effect.s.LDD.coef.RS=function(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.LDD.RS(r,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # -------------- # Time-varying # -------------- #################################### #### Minimum detectable effect ################################### # ********************************************************* # * effect for CMD and DEX when user enters beta, fixed s * # ********************************************************* # Model without time, marginal long.effect.s.tv.CMD.marg.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.marg.DEX(r,s,pe,rho.e,sigma2,rho,theta) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } ## upper ## long.effect.s.tv.upper.CMD.marg.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.marg.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) effect=-99 else effect=(qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) effect } # Model without time, conditional long.effect.s.tv.CMD.cond.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } ## upper ## long.effect.s.tv.upper.CMD.cond.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) effect=-99 else effect=(qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) effect } # Model with time, marginal long.effect.s.tv.CMD.marg.time.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.marg.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } ## upper ## long.effect.s.tv.upper.CMD.marg.time.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.marg.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) effect=-99 else effect=(qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) effect } # Model with time, conditional long.effect.s.tv.CMD.cond.time.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.CMD.cond.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } ## upper ## long.effect.s.tv.upper.CMD.cond.time.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.upper.CMD.cond.time.DEX(r,s,pe,rho.e,sigma2,rho,theta) if (var==-99) effect=-99 else effect=(qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) effect } ### CS: long.effect.s.tv.CMD.marg.coef.CS=function(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha=0.05) { long.effect.s.tv.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta=0,alpha) } long.effect.s.tv.CMD.cond.coef.CS=function(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha=0.05) { long.effect.s.tv.CMD.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta=0,alpha) } long.effect.s.tv.CMD.marg.time.coef.CS=function(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha=0.05) { long.effect.s.tv.CMD.marg.time.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta=0,alpha) } long.effect.s.tv.CMD.cond.time.coef.CS=function(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha=0.05) { long.effect.s.tv.CMD.cond.time.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta=0,alpha) } ### RS #### # Model without time, marginal long.effect.s.tv.CMD.marg.coef.RS=function(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.marg.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # Model without time, conditional long.effect.s.tv.CMD.cond.coef.RS=function(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.cond.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # Model with time, marginal long.effect.s.tv.CMD.marg.time.coef.RS=function(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.marg.time.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # Model with time, conditional long.effect.s.tv.CMD.cond.time.coef.RS=function(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.CMD.cond.time.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } #### LDD #### ## DEX ## # *********************************************************** # * effect for LDD and DEX when user enters gamma3, fixed s * # *********************************************************** # Acute, marginal long.effect.s.tv.LDD.acute.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.acute.DEX(r,s,pe,rho.e,sigma2,rho,theta) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # Acute, conditional long.effect.s.tv.LDD.acute.cond.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.acute.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # Cumulative, marginal long.effect.s.tv.LDD.cum.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.cum.DEX(r,s,pe,rho.e,sigma2,rho,theta) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # Cumulative, conditional long.effect.s.tv.LDD.cum.cond.coef.DEX=function(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha=0.05) { var=long.var.s.tv.LDD.cum.cond.DEX(r,s,pe,rho.e,sigma2,rho,theta) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } ## CS ## long.effect.s.tv.LDD.acute.coef.CS=function(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha=0.05) { long.effect.s.tv.LDD.acute.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta=0,alpha) } long.effect.s.tv.LDD.acute.cond.coef.CS=function(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha=0.05) { long.effect.s.tv.LDD.acute.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta=0,alpha) } long.effect.s.tv.LDD.cum.coef.CS=function(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha=0.05) { long.effect.s.tv.LDD.cum.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta=0,alpha) } long.effect.s.tv.LDD.cum.cond.coef.CS=function(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha=0.05) { long.effect.s.tv.LDD.cum.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta=0,alpha) } ### RS ### # ********************************* # * effect for LDD and RS, fixed s * # ********************************* # Acute, marginal long.effect.s.tv.LDD.acute.coef.RS=function(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.acute.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # Acute, conditional long.effect.s.tv.LDD.acute.cond.coef.RS=function(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.acute.cond.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # Cumulative, marginal long.effect.s.tv.LDD.cum.coef.RS=function(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.cum.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } # Cumulative, conditional long.effect.s.tv.LDD.cum.cond.coef.RS=function(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha=0.05) { var=long.var.s.tv.LDD.cum.cond.RS(r,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) (qnorm(1-alpha/2)+qnorm(Pi))*sqrt(var/N) } ######################### # 2.3.2. User interface # ######################### long.effect <- function() { # Initialize parameters N=100 r=1 Pi=0.8 s=1 tv=1 pe.type=1 pe=.5 vt0=0 rho.exp.t0=0 rho.e=0.5 pattern=1 model.cmd=1 model.ldd=1 notation=1 mu00=10 p1=.1 correlation=1 sigma2=1 rho=0.8 theta=0.5 notation.rs=1 sigma2w=0.1 sigma20=0.3 sigma21=0.01 sigma01=0 r.tilde=5 rho.b1=0.1 rho01=0 p2=.1 alpha=0.05 finish=F while (finish==F) { cat("\n* By just pressing after each question, the default value, shown\n between square brackets, will be entered.\n\n") cat("* Press to quit\n\n") N=get.N(N) r=get.r(r) Pi=get.Pi(Pi) s=get.s(s) tau=s*r tv=get.tv(tv) if (tv==1) { # time-invariant pe=get.pe(pe) vt0=get.vt0(vt0) if (vt0!=0) rho.exp.t0=get.rho.exp.t0(rho.exp.t0) else rho.exp.t0=0 pattern=get.pattern(pattern) if (pattern == 1) { #CMD notation=get.notation2(notation) if (notation == 2) mu00=get.mu00(mu00) correlation=get.correlation(correlation) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (notation==1) { effect=long.effect.s.CMD.coef.CS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") } else { beta=long.effect.s.CMD.coef.CS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") } } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (notation==1) { effect=long.effect.s.CMD.coef.DEX(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,theta,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") } else { beta=long.effect.s.CMD.coef.DEX(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,theta,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.CMD.coef.RS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") } else { beta=long.effect.s.CMD.coef.RS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") } } } else { # LDD notation=get.notation2(notation) if (notation == 2) { mu00=get.mu00(mu00) p2=get.p2(2,p2) if (p2==0) p1=get.p1(p1) } correlation=get.correlation(correlation) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (notation==1) { effect=long.effect.s.LDD.coef.CS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.LDD.coef.CS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (notation==1) { effect=long.effect.s.LDD.coef.DEX(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,theta,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.LDD.coef.DEX(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,theta,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) if (vt0 == 0) sigma01=0 else sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) if (vt0 == 0) rho01=0 else rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.LDD.coef.RS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.LDD.coef.RS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } # end correlation } # end LDD } else { # TIME-VARYING pe.type=get.pe.type(pe.type) pe=get.pe.tv(pe.type,r,pe) rho.e=get.rhoe(r,pe,rho.e) pattern=get.pattern(pattern) if (pattern == 1) { #CMD model.cmd=get.model.cmd(model.cmd) notation=get.notation2(notation) if (notation == 2) mu00=get.mu00(mu00) correlation=get.correlation(correlation) if (model.cmd==1) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (notation==1) { effect=long.effect.s.tv.CMD.marg.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") } else { beta=long.effect.s.tv.CMD.marg.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") } } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (notation==1) { effect=long.effect.s.tv.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) effect.upper=long.effect.s.tv.upper.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (effect.upper==-99) cat("Upper bound for min. det. effect when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for min. det. effect when rho.e=",rho.e,": ",effect.upper,"\n\n") } } } else { beta=long.effect.s.tv.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) effect.upper=long.effect.s.tv.upper.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (effect.upper==-99) cat("Upper bound for min. det. effect when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for min. det. effect when rho.e=",rho.e,": ",effect.upper/mu00,"\n\n") } } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.CMD.marg.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") } else { beta=long.effect.s.tv.CMD.marg.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") } } # end correlation } else if (model.cmd==2) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (notation==1) { effect=long.effect.s.tv.CMD.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") } else { beta=long.effect.s.tv.CMD.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") } } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (notation==1) { effect=long.effect.s.tv.CMD.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) effect.upper=long.effect.s.tv.upper.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (effect.upper==-99) cat("Upper bound for min. det. effect when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for min. det. effect when rho.e=",rho.e,": ",effect.upper,"\n\n") } } } else { beta=long.effect.s.tv.CMD.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) effect.upper=long.effect.s.tv.upper.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (effect.upper==-99) cat("Upper bound for min. det. effect when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for min. det. effect when rho.e=",rho.e,": ",effect.upper/mu00,"\n\n") } } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.CMD.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") } else { beta=long.effect.s.tv.CMD.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") } } # end correlation } else if (model.cmd==3) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (notation==1) { effect=long.effect.s.tv.CMD.marg.time.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") } else { beta=long.effect.s.tv.CMD.marg.time.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") } } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (notation==1) { effect=long.effect.s.tv.CMD.marg.time.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) effect.upper=long.effect.s.tv.upper.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (effect.upper==-99) cat("Upper bound for min. det. effect when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for min. det. effect when rho.e=",rho.e,": ",effect.upper,"\n\n") } } } else { beta=long.effect.s.tv.CMD.marg.time.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) effect.upper=long.effect.s.tv.upper.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (effect.upper==-99) cat("Upper bound for min. det. effect when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for min. det. effect when rho.e=",rho.e,": ",effect.upper/mu00,"\n\n") } } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.CMD.marg.time.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") } else { beta=long.effect.s.tv.CMD.marg.time.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") } } # end correlation } else { # model.cmd==4 if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (notation==1) { effect=long.effect.s.tv.CMD.cond.time.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") } else { beta=long.effect.s.tv.CMD.cond.time.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") } } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (notation==1) { effect=long.effect.s.tv.CMD.cond.time.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) effect.upper=long.effect.s.tv.upper.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (effect.upper==-99) cat("Upper bound for min. det. effect when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for min. det. effect when rho.e=",rho.e,": ",effect.upper,"\n\n") } } } else { beta=long.effect.s.tv.CMD.cond.time.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") if (r>1 & r<7) { aaa=try(library(boot),silent=T) skip.upper=inherits(aaa, "try-error") # If false, library is installed and can # compute the upper bound if (skip.upper==F) { library(boot) effect.upper=long.effect.s.tv.upper.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (effect.upper==-99) cat("Upper bound for min. det. effect when rho.e=",rho.e," did not converge\n\n") else cat("Upper bound for min. det. effect when rho.e=",rho.e,": ",effect.upper/mu00,"\n\n") } } } } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.CMD.cond.time.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Minimum detectable beta2 = +/- ", effect,"\n") } else { beta=long.effect.s.tv.CMD.cond.time.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) effect=beta/mu00 cat("Minimum detectable p1 = +/- ", effect,"\n") } } # end correlation } # end model.cmd } else { # LDD model.ldd=get.model.ldd(model.ldd) notation=get.notation2(notation) if (notation == 2) { mu00=get.mu00(mu00) p2=get.p2(2,p2) if (p2==0) p1=get.p1(p1) } correlation=get.correlation(correlation) if (model.ldd==1) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (notation==1) { effect=long.effect.s.tv.LDD.cum.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.cum.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (notation==1) { effect=long.effect.s.tv.LDD.cum.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.cum.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } else if (correlation==3) { notation.rs=get.notation.rs(notation) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.LDD.cum.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.cum.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } # end correlation } else if (model.ldd==2) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (notation==1) { effect=long.effect.s.tv.LDD.cum.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.cum.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (notation==1) { effect=long.effect.s.tv.LDD.cum.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.cum.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } else if (correlation==3) { notation.rs=get.notation.rs(notation) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.LDD.cum.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.cum.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } # end correlation } else if (model.ldd==3) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (notation==1) { effect=long.effect.s.tv.LDD.acute.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.acute.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (notation==1) { effect=long.effect.s.tv.LDD.acute.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.acute.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } else if (correlation==3) { notation.rs=get.notation.rs(notation) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.LDD.acute.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.acute.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } # end correlation } else { # model.ldd==4) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (notation==1) { effect=long.effect.s.tv.LDD.acute.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.acute.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (notation==1) { effect=long.effect.s.tv.LDD.acute.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.acute.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } else if (correlation==3) { notation.rs=get.notation.rs(notation) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=r rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.LDD.acute.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) cat("Minimum detectable gamma3 = +/- ", effect,"\n") } else { gamma=long.effect.s.tv.LDD.acute.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) if (p2==0) effect=s*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) cat("Minimum detectable p3 = +/- ", effect,"\n") } } # end correlation } # end model.ldd } # end LDD } # end time-varying finish=get.finish() } } ######################## # 2.3.3. Batch command # ######################## long.effect.batch <- function(N=100,r=1,Pi=.8,fixed=1,s.or.tau=1,tv=1,pe.type=1, pe=.5,vt0=0,rho.exp.t0=0,rho.e=.5,pattern=1,model.cmd=1, model.ldd=1,notation=1,mu00=10,p1=.1,correlation=1,sigma2=1, rho=.8,theta=.5,notation.rs=1,sigma2w=.1,sigma20=.3,sigma21=.01, sigma01=0,r.tilde=5,rho.b1=.1,rho01=0,p2=.1,alpha=.05) { if (fixed==1) s=s.or.tau else s=s.or.tau/r if (tv==1) { # time-invariant if (pattern == 1) { #CMD if (correlation==1) { if (notation==1) { effect=long.effect.s.CMD.coef.CS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,alpha) } else { beta=long.effect.s.CMD.coef.CS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,alpha) effect=beta/mu00 } } else if (correlation==2) { if (notation==1) { effect=long.effect.s.CMD.coef.DEX(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,theta,alpha) } else { beta=long.effect.s.CMD.coef.DEX(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,theta,alpha) effect=beta/mu00 } } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.CMD.coef.RS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01,alpha) } else { beta=long.effect.s.CMD.coef.RS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01,alpha) effect=beta/mu00 } } } else { # LDD if (correlation==1) { if (notation==1) { effect=long.effect.s.LDD.coef.CS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,alpha) } else { gamma=long.effect.s.LDD.coef.CS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s*gamma/(p2*mu00) } } else if (correlation==2) { if (notation==1) { effect=long.effect.s.LDD.coef.DEX(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,theta,alpha) } else { gamma=long.effect.s.LDD.coef.DEX(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2,rho,theta,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.LDD.coef.RS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01,alpha) } else { gamma=long.effect.s.LDD.coef.RS(N,r,Pi,s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } # end correlation } # end LDD } else { # TIME-VARYING if (pattern == 1) { #CMD if (model.cmd==1) { if (correlation==1) { if (notation==1) { effect=long.effect.s.tv.CMD.marg.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) } else { beta=long.effect.s.tv.CMD.marg.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) effect=beta/mu00 } } else if (correlation==2) { if (notation==1) { effect=long.effect.s.tv.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) } else { beta=long.effect.s.tv.CMD.marg.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) effect=beta/mu00 } } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.CMD.marg.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) } else { beta=long.effect.s.tv.CMD.marg.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) effect=beta/mu00 } } # end correlation } else if (model.cmd==2) { if (correlation==1) { if (notation==1) { effect=long.effect.s.tv.CMD.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) } else { beta=long.effect.s.tv.CMD.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) effect=beta/mu00 } } else if (correlation==2) { if (notation==1) { effect=long.effect.s.tv.CMD.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) } else { beta=long.effect.s.tv.CMD.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) effect=beta/mu00 } } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.CMD.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) } else { beta=long.effect.s.tv.CMD.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) effect=beta/mu00 } } # end correlation } else if (model.cmd==3) { if (correlation==1) { if (notation==1) { effect=long.effect.s.tv.CMD.marg.time.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) } else { beta=long.effect.s.tv.CMD.marg.time.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) effect=beta/mu00 } } else if (correlation==2) { if (notation==1) { effect=long.effect.s.tv.CMD.marg.time.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) } else { beta=long.effect.s.tv.CMD.marg.time.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) effect=beta/mu00 } } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.CMD.marg.time.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) } else { beta=long.effect.s.tv.CMD.marg.time.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) effect=beta/mu00 } } # end correlation } else { # model.cmd==4 if (correlation==1) { if (notation==1) { effect=long.effect.s.tv.CMD.cond.time.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) } else { beta=long.effect.s.tv.CMD.cond.time.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) effect=beta/mu00 } } else if (correlation==2) { if (notation==1) { effect=long.effect.s.tv.CMD.cond.time.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) } else { beta=long.effect.s.tv.CMD.cond.time.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) effect=beta/mu00 } } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.CMD.cond.time.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) } else { beta=long.effect.s.tv.CMD.cond.time.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) effect=beta/mu00 } } # end correlation } # end model.cmd } else { # LDD if (model.ldd==1) { if (correlation==1) { if (notation==1) { effect=long.effect.s.tv.LDD.cum.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) } else { gamma=long.effect.s.tv.LDD.cum.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } else if (correlation==2) { if (notation==1) { effect=long.effect.s.tv.LDD.cum.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) } else { gamma=long.effect.s.tv.LDD.cum.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.LDD.cum.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) } else { gamma=long.effect.s.tv.LDD.cum.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } # end correlation } else if (model.ldd==2) { if (correlation==1) { if (notation==1) { effect=long.effect.s.tv.LDD.cum.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) } else { gamma=long.effect.s.tv.LDD.cum.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } else if (correlation==2) { if (notation==1) { effect=long.effect.s.tv.LDD.cum.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) } else { gamma=long.effect.s.tv.LDD.cum.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.LDD.cum.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) } else { gamma=long.effect.s.tv.LDD.cum.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } # end correlation } else if (model.ldd==3) { if (correlation==1) { if (notation==1) { effect=long.effect.s.tv.LDD.acute.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) } else { gamma=long.effect.s.tv.LDD.acute.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } else if (correlation==2) { if (notation==1) { effect=long.effect.s.tv.LDD.acute.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) } else { gamma=long.effect.s.tv.LDD.acute.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.LDD.acute.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) } else { gamma=long.effect.s.tv.LDD.acute.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } # end correlation } else { # model.ldd==4) if (correlation==1) { if (notation==1) { effect=long.effect.s.tv.LDD.acute.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) } else { gamma=long.effect.s.tv.LDD.acute.cond.coef.CS(N,r,Pi,s,pe,rho.e,sigma2,rho,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } else if (correlation==2) { if (notation==1) { effect=long.effect.s.tv.LDD.acute.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) } else { gamma=long.effect.s.tv.LDD.acute.cond.coef.DEX(N,r,Pi,s,pe,rho.e,sigma2,rho,theta,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (notation==1) { effect=long.effect.s.tv.LDD.acute.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) } else { gamma=long.effect.s.tv.LDD.acute.cond.coef.RS(N,r,Pi,s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01,alpha) if (p2==0) effect=s.or.tau*gamma/((1+p1)*mu00) else effect=s.or.tau*gamma/(p2*mu00) } } # end correlation } # end model.ldd } # end LDD } # end time-varying effect } ########################## # 2.3.4. Batch functions # ########################## ###### # E1 # ###### effect.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","sigma2","rho","alpha")) pattern=1 notation=2 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # E2 # ###### effect.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","sigma2","rho","theta","alpha")) pattern=1 notation=2 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # E3 # ###### effect.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=2 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # E4 # ###### effect.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=2 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # E5 # ###### effect.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","sigma2","rho","alpha")) pattern=1 notation=1 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # E6 # ###### effect.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","sigma2","rho","theta","alpha")) pattern=1 notation=1 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # E7 # ###### effect.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=1 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # E8 # ###### effect.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=1 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # E9 # ###### effect.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","sigma2","rho","alpha")) pattern=2 notation=2 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E10 # ####### effect.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","sigma2","rho","theta","alpha")) pattern=2 notation=2 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E11 # ####### effect.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=2 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E12 # ####### effect.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=2 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E13 # ####### effect.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","sigma2","rho","alpha")) pattern=2 notation=1 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E14 # ####### effect.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","sigma2","rho","theta","alpha")) pattern=2 notation=1 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E15 # ####### effect.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=1 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E16 # ####### effect.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=1 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E17 # ####### effect.tv.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","sigma2","rho","alpha")) pattern=1 notation=2 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E18 # ####### effect.tv.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","sigma2","rho","theta","alpha")) pattern=1 notation=2 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E19 # ####### effect.tv.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=2 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E20 # ####### effect.tv.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","mu00","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=2 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E21 # ####### effect.tv.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","sigma2","rho","alpha")) pattern=1 notation=1 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E22 # ####### effect.tv.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","sigma2","rho","theta","alpha")) pattern=1 notation=1 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E23 # ####### effect.tv.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=1 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E24 # ####### effect.tv.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.cmd","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=1 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.cmd=model.cmd[i], sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E25 # ####### effect.tv.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","sigma2","rho","alpha")) pattern=2 notation=2 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E26 # ####### effect.tv.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","sigma2","rho","theta","alpha")) pattern=2 notation=2 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E27 # ####### effect.tv.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=2 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E28 # ####### effect.tv.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","mu00","p1","p2","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=2 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E29 # ####### effect.tv.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","sigma2","rho","alpha")) pattern=2 notation=1 correlation=1 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E30 # ####### effect.tv.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","sigma2","rho","theta","alpha")) pattern=2 notation=1 correlation=2 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E31 # ####### effect.tv.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=1 correlation=3 notation.rs=1 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # E32 # ####### effect.tv.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","r","Pi","fixed","s.or.tau","pe0","per", "rho.e","model.ldd","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=1 correlation=3 notation.rs=2 tv=2 pe.type=2 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } slope=(per-pe0)/r pes=list() for (i in 1:(dim(data)[1])) { times=0:r[i] pes[[i]]=pe0[i]+slope[i]*t(times) } out=vector() for (i in 1:(dim(data)[1])) { pe=as.vector(pes[[i]]) out[i]=long.effect.batch(N=N[i],r=r[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe,rho.e=rho.e[i],model.ldd=model.ldd[i], sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ############################################################################# ############################################################################# # 2.4. Number of repeated Measures ############################################################################# ############################################################################# #################### # 2.4.1. Functions # #################### # -------------- # Time-invariant # -------------- ### CMD ### # ********************************************************** # * Repeated measures for CMD and CS when user enters beta * # ********************************************************** long.r.CMD.coef.CS=function(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 lim=pnorm(sqrt(N)*abs(beta)*sqrt(pe*(1-pe))/sqrt(sigma2*rho)-qnorm(1-alpha/2)) if (Pi>lim) { r=-999 } else { found=F r=0 if (fixed==1) { while (found==F && r=Pi) r=r+1 } } else { while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 } if (to.file==1) return(r) else { if (r==-999) { lim=pnorm(sqrt(N)*abs(beta)*sqrt(pe*(1-pe))/sqrt(sigma2*rho)-qnorm(1-alpha/2)) cat("The maximum power (as r->infinity) that can be obtained in your study is\n ",lim,"\n") cat("You should take the largest number of measurements possible and use\n module long.power() to calculate the power achieved\n") } else if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.CMD.coef.CS(N,max.r,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else if (r==0) { cat("You can achieve the pre-specified power without taking repeated measures\n") } else { cat("You need ",r," post-baseline measures\n") } } } # *********************************************************** # * Repeated measures for CMD and DEX when user enters beta * # *********************************************************** long.r.CMD.coef.DEX=function(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha=0.05,max.r=50,to.file=2) { # power increases with r # s.or.tau is s if fixed==1 or tau if fixed==2 found=F r=0 if (fixed==1) { while (found==F && r=Pi) r=r+1 } } else { while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.CMD.coef.DEX(N,max.r,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else if (r==0) { cat("You can achieve the pre-specified power without taking repeated measures\n") } else { cat("You need ",r," post-baseline measures\n") } } } # ********************************************************** # * Repeated measures for CMD and RS when user enters beta * # ********************************************************** long.r.CMD.coef.RS=function(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 # power not necessarily increasing with r found=F r=0 if (fixed==1) { while (found==F && r=Pi) r=r+1 } } else { while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.CMD.coef.RS(N,max.r,s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else if (r==0) { cat("You can achieve the pre-specified power without taking repeated measures\n") } else { cat("You need ",r," post-baseline measures\n") if ( fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) cat("Slope reliability at r=",r,": ",reliab,"\n") } } } # *********************************************************** # * Repeated measures for LDD and CS when user enters gamma * # *********************************************************** long.r.LDD.coef.CS=function(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 if (fixed==1) { found=F r=1 while (found==F && r=Pi) r=r+1 } } else { found=F r=1 while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.LDD.coef.CS(N,max.r,s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else { cat("You need ",r," post-baseline measures\n") } } } # ************************************************************ # * Repeated measures for LDD and DEX when user enters gamma * # ************************************************************ long.r.LDD.coef.DEX=function(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 if (fixed==1) { found=F r=1 while (found==F && r=Pi) r=r+1 } } else { found=F r=1 while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.LDD.coef.DEX(N,max.r,s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else { cat("You need ",r," post-baseline measures\n") } } } # *********************************************************** # * Repeated measures for LDD and RS when user enters gamma * # *********************************************************** long.r.LDD.coef.RS=function(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 if (sigma21==0) { r=long.r.LDD.coef.CS(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2w+sigma20,sigma20/(sigma2w+sigma20),alpha,max.r) } else { if (vt0==0) { lim=pnorm(sqrt(N*pe*(1-pe))*abs(gamma3)/sqrt(sigma21)-qnorm(1-alpha/2)) if (Pi>lim) r=-999 else { found=F r=1 while (found==F && r=Pi) r=r+1 } if (found==T) r=r-1 else r=-888 } } else { lim=pnorm( sqrt(N*pe*(1-pe)* ((-sigma01^2)+sigma21*(sigma20+sigma21*vt0))) * abs(gamma3) / sqrt(sigma21*(-(sigma01^2)+sigma20*sigma21))) if (Pi>lim) r=-999 else { found=F r=1 while (found==F && r=Pi) r=r+1 } if (found==T) r=r-1 else r=-888 } } } if (to.file==1) return(r) else { if (r==-999) { if (vt0==0) lim=pnorm(sqrt(N*pe*(1-pe))*abs(gamma3)/sqrt(sigma21)-qnorm(1-alpha/2)) else lim=pnorm( sqrt(N*pe*(1-pe)* ((-sigma01^2)+sigma21*(sigma20+sigma21*vt0))) * abs(gamma3) / sqrt(sigma21*(-(sigma01^2)+sigma20*sigma21))) cat("The maximum power (as r->infinity) that can be obtained in your study is\n ",lim,"\n") cat("You should take the largest number of measurements possible and use\n module long.power() to calculate the power achieved\n") } else if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.LDD.coef.RS(N,max.r,s,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else { cat("You need ",r," post-baseline measures\n") if ( fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) cat("Slope reliability at r=",r,": ",reliab,"\n") } } } # -------------- # Time-invariant # -------------- ### CMD ### # Model without time, marginal # ********************************************************** # * Repeated measures for CMD and DEX when user enters beta * # ********************************************************** long.r.tv.CMD.marg.coef.DEX=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 found=F r=0 if (fixed==1) { while (found==F && r=Pi) r=r+1 } } else { while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.CMD.marg.coef.DEX(N,max.r,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else if (r==0) { cat("You can achieve the pre-specified power without taking repeated measures\n") } else { cat("You need ",r," post-baseline measures\n") } } } # ********************************************************** # * Repeated measures for CMD and RS when user enters beta * # ********************************************************** long.r.tv.CMD.marg.coef.RS=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 found=F r=0 if (fixed==1) { while (found==F && r=Pi) r=r+1 } } else { while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.CMD.marg.coef.RS(N,max.r,s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else if (r==0) { cat("You can achieve the pre-specified power without taking repeated measures\n") } else { cat("You need ",r," post-baseline measures\n") } } } # CS # long.r.tv.CMD.marg.coef.CS=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha=0.05,max.r=50,to.file=2) { long.r.tv.CMD.marg.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta=0,alpha,max.r,to.file) } # Model without time, conditional # ********************************************************** # * Repeated measures for CMD and DEX when user enters beta * # ********************************************************** long.r.tv.CMD.cond.coef.DEX=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 found=F r=1 if (fixed==1) { while (found==F && r=Pi) r=r+1 } } else { while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.CMD.cond.coef.DEX(N,max.r,s,pe,rho.e,beta,sigma2,rho,theta,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else if (r==0) { cat("You can achieve the pre-specified power without taking repeated measures\n") } else { cat("You need ",r," post-baseline measures\n") } } } # ********************************************************** # * Repeated measures for CMD and RS when user enters beta * # ********************************************************** long.r.tv.CMD.cond.coef.RS=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 found=F r=1 if (fixed==1) { while (found==F && r=Pi) r=r+1 } } else { while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.CMD.cond.coef.RS(N,max.r,s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else if (r==0) { cat("You can achieve the pre-specified power without taking repeated measures\n") } else { cat("You need ",r," post-baseline measures\n") } } } # CS # long.r.tv.CMD.cond.coef.CS=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha=0.05,max.r=50,to.file=2) { long.r.tv.CMD.cond.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta=0,alpha,max.r,to.file) } # Model with time, marginal # ********************************************************** # * Repeated measures for CMD and DEX when user enters beta * # ********************************************************** long.r.tv.CMD.marg.time.coef.DEX=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 found=F r=1 if (fixed==1) { while (found==F && r=Pi) r=r+1 } } else { while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.CMD.marg.time.coef.DEX(N,max.r,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else if (r==0) { cat("You can achieve the pre-specified power without taking repeated measures\n") } else { cat("You need ",r," post-baseline measures\n") } } } # ********************************************************** # * Repeated measures for CMD and RS when user enters beta * # ********************************************************** long.r.tv.CMD.marg.time.coef.RS=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 found=F r=1 if (fixed==1) { while (found==F && r=Pi) r=r+1 } } else { while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.CMD.marg.time.coef.RS(N,max.r,s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else if (r==0) { cat("You can achieve the pre-specified power without taking repeated measures\n") } else { cat("You need ",r," post-baseline measures\n") } } } # CS # long.r.tv.CMD.marg.time.coef.CS=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha=0.05,max.r=50,to.file=2) { long.r.tv.CMD.marg.time.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta=0,alpha,max.r,to.file) } # Model with time, conditional # ********************************************************** # * Repeated measures for CMD and DEX when user enters beta * # ********************************************************** long.r.tv.CMD.cond.time.coef.DEX=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 found=F r=1 if (fixed==1) { while (found==F && r=Pi) r=r+1 } } else { while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.CMD.cond.time.coef.DEX(N,max.r,s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else if (r==0) { cat("You can achieve the pre-specified power without taking repeated measures\n") } else { cat("You need ",r," post-baseline measures\n") } } } # ********************************************************** # * Repeated measures for CMD and RS when user enters beta * # ********************************************************** long.r.tv.CMD.cond.time.coef.RS=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 found=F r=1 if (fixed==1) { while (found==F && r=Pi) r=r+1 } } else { while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.CMD.cond.time.coef.RS(N,max.r,s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else if (r==0) { cat("You can achieve the pre-specified power without taking repeated measures\n") } else { cat("You need ",r," post-baseline measures\n") } } } # CS # long.r.tv.CMD.cond.time.coef.CS=function(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha=0.05,max.r=50,to.file=2) { long.r.tv.CMD.cond.time.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta=0,alpha,max.r,to.file) } ### LDD ### ## acute exposure, marginal # ************************************************************ # * Repeated measures for LDD and DEX when user enters gamma * # ************************************************************ long.r.tv.LDD.acute.coef.DEX=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 if (fixed==1) { found=F r=1 while (found==F && r=Pi) r=r+1 } } else { found=F r=1 while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.LDD.acute.coef.DEX(N,max.r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else { cat("You need ",r," post-baseline measures\n") } } } # ************************************************************ # * Repeated measures for LDD and RS when user enters gamma * # ************************************************************ long.r.tv.LDD.acute.coef.RS=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 if (fixed==1) { found=F r=1 while (found==F && r=Pi) r=r+1 } } else { found=F r=1 while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.LDD.acute.coef.DEX(N,max.r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else { cat("You need ",r," post-baseline measures\n") } } } # CS # long.r.tv.LDD.acute.coef.CS=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha=0.05,max.r=50,to.file=2) { long.r.tv.LDD.acute.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta=0,alpha,max.r,to.file) } ### acute exposure, conditional # ************************************************************ # * Repeated measures for LDD and DEX when user enters gamma * # ************************************************************ long.r.tv.LDD.acute.cond.coef.DEX=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 if (fixed==1) { found=F r=1 while (found==F && r=Pi) r=r+1 } } else { found=F r=1 while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.LDD.acute.cond.coef.DEX(N,max.r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else { cat("You need ",r," post-baseline measures\n") } } } # ************************************************************ # * Repeated measures for LDD and RS when user enters gamma * # ************************************************************ long.r.tv.LDD.acute.cond.coef.RS=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 if (fixed==1) { found=F r=1 while (found==F && r=Pi) r=r+1 } } else { found=F r=1 while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.LDD.acute.cond.coef.DEX(N,max.r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else { cat("You need ",r," post-baseline measures\n") } } } # CS # long.r.tv.LDD.acute.cond.coef.CS=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha=0.05,max.r=50,to.file=2) { long.r.tv.LDD.acute.cond.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta=0,alpha,max.r,to.file) } ## cumulative exposure, marginal # ************************************************************ # * Repeated measures for LDD and DEX when user enters gamma * # ************************************************************ long.r.tv.LDD.cum.coef.DEX=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 if (fixed==1) { found=F r=1 while (found==F && r=Pi) r=r+1 } } else { found=F r=1 while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.LDD.cum.coef.DEX(N,max.r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else { cat("You need ",r," post-baseline measures\n") } } } # ************************************************************ # * Repeated measures for LDD and RS when user enters gamma * # ************************************************************ long.r.tv.LDD.cum.coef.RS=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 if (fixed==1) { found=F r=1 while (found==F && r=Pi) r=r+1 } } else { found=F r=1 while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.LDD.cum.coef.DEX(N,max.r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else { cat("You need ",r," post-baseline measures\n") } } } # CS # long.r.tv.LDD.cum.coef.CS=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha=0.05,max.r=50,to.file=2) { long.r.tv.LDD.cum.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta=0,alpha,max.r,to.file) } ## cumulative exposure, conditional # ************************************************************ # * Repeated measures for LDD and DEX when user enters gamma * # ************************************************************ long.r.tv.LDD.cum.cond.coef.DEX=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 if (fixed==1) { found=F r=1 while (found==F && r=Pi) r=r+1 } } else { found=F r=1 while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.LDD.cum.cond.coef.DEX(N,max.r,s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else { cat("You need ",r," post-baseline measures\n") } } } # ************************************************************ # * Repeated measures for LDD and RS when user enters gamma * # ************************************************************ long.r.tv.LDD.cum.cond.coef.RS=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha=0.05,max.r=50,to.file=2) { # s.or.tau is s if fixed==1 or tau if fixed==2 if (fixed==1) { found=F r=1 while (found==F && r=Pi) r=r+1 } } else { found=F r=1 while (found==F && r=Pi) r=r+1 } } if (found==T) r=r-1 else r=-888 if (to.file==1) return(r) else { if (r==-888) { if (fixed==1) s=s.or.tau else s=s.or.tau/max.r power=long.power.s.tv.LDD.cum.cond.coef.DEX(N,max.r,s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) cat("You cannot reach the specified power with less than ",max.r," post-baseline measures\n") cat("Power with r=",max.r,": ",power,"\n",sep="") } else { cat("You need ",r," post-baseline measures\n") } } } # CS # long.r.tv.LDD.cum.cond.coef.CS=function(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha=0.05,max.r=50,to.file=2) { long.r.tv.LDD.cum.cond.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta=0,alpha,max.r,to.file) } ######################### # 2.4.2. User interface # ######################### long.r <- function() { # Initialize parameters N=100 Pi=0.8 fixed=1 s.or.tau=1 tv=1 pe.type=1 pe=.5 vt0=0 rho.exp.t0=0 rho.e=.5 pattern=1 model.cmd=1 model.ldd=1 notation=1 beta=0.1 mu00=10 p1=.1 correlation=1 sigma2=1 rho=0.8 theta=0.5 notation.rs=1 sigma2w=0.1 sigma20=0.3 sigma21=0.01 sigma01=0 r.tilde=5 rho.b1=0.1 rho01=0 gamma3=.1 p2=.1 p3=.1 alpha=0.05 max.r=50 to.file=2 finish=F while (finish==F) { cat("\n* By just pressing after each question, the default value, shown\n between square brackets, will be entered.\n\n") cat("* Press to quit\n\n") N=get.N(N) Pi=get.Pi(Pi) fixed=get.fixed(fixed) if (fixed==1) s.or.tau=get.s(s.or.tau) else s.or.tau=get.tau(s.or.tau) # s.or.tau is s if fixed==1 or tau if fixed==2 tv=get.tv(tv) if (tv==1) { # time-invariant pe=get.pe(pe) vt0=get.vt0(vt0) if (vt0!=0) rho.exp.t0=get.rho.exp.t0(rho.exp.t0) else rho.exp.t0=0 pattern=get.pattern(pattern) if (pattern == 1 ) { # CMD notation=get.notation(notation) if (notation == 1) beta=get.beta(beta) else { mu00=get.mu00(mu00) p1=get.p1(p1) beta=p1*mu00 } correlation=get.correlation(correlation) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) long.r.CMD.coef.CS(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) long.r.CMD.coef.DEX(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.CMD.coef.RS(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else { # LDD notation=get.notation(notation) if (notation == 1) gamma3=get.gamma(gamma3) else { if (fixed==1) cat("** Your percent changes will refer to a change of s units,\n and NOT from beginning to end of follow-up\n\n") mu00=get.mu00(mu00) p2=get.p2(fixed,p2) if (p2==0) { p1=get.p1(p1) p3=get.p3.p20(fixed,p3) gamma3=(1+p1)*p3*mu00/(s.or.tau) } else { p3=get.p3(fixed,p3) gamma3=p2*p3*mu00/(s.or.tau) } } correlation=get.correlation(correlation) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) long.r.LDD.coef.CS(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) long.r.LDD.coef.DEX(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) if (vt0 == 0) sigma01=0 else sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) if (vt0 == 0) rho01=0 else rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.LDD.coef.RS(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } # end LDD } else { # TIME-VARYING pe.type=1 pe=get.pe(pe) rho.e=get.rhoe.no.r(rho.e) pattern=get.pattern(pattern) if (pattern == 1) { # CMD model.cmd=get.model.cmd(model.cmd) notation=get.notation(notation) if (notation == 1) beta=get.beta(beta) else { mu00=get.mu00(mu00) p1=get.p1(p1) beta=p1*mu00 } correlation=get.correlation(correlation) if (model.cmd==1) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) long.r.tv.CMD.marg.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) long.r.tv.CMD.marg.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.CMD.marg.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else if (model.cmd==2) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) long.r.tv.CMD.cond.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) long.r.tv.CMD.cond.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.CMD.cond.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else if (model.cmd==3) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) long.r.tv.CMD.marg.time.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) long.r.tv.CMD.marg.time.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.CMD.marg.time.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else { # model.cmd==4 if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) long.r.tv.CMD.cond.time.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) long.r.tv.CMD.cond.time.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.CMD.cond.time.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } # end model.cmd } else { # LDD model.ldd=get.model.ldd(model.ldd) notation=get.notation(notation) if (notation == 1) gamma3=get.gamma(gamma3) else { if (fixed==1) cat("** Your percent changes will refer to a change of s units,\n and NOT from beginning to end of follow-up\n\n") mu00=get.mu00(mu00) p2=get.p2(fixed,p2) if (p2==0) { p1=get.p1(p1) p3=get.p3.p20(fixed,p3) gamma3=(1+p1)*p3*mu00/(s.or.tau) } else { p3=get.p3(fixed,p3) gamma3=p2*p3*mu00/(s.or.tau) } } correlation=get.correlation(correlation) if (model.ldd==1) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) long.r.tv.LDD.cum.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) long.r.tv.LDD.cum.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.LDD.cum.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else if (model.ldd==2) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) long.r.tv.LDD.cum.cond.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) long.r.tv.LDD.cum.cond.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.LDD.cum.cond.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else if (model.ldd==3) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) long.r.tv.LDD.acute.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) long.r.tv.LDD.acute.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.LDD.acute.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else if (model.ldd==4) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) long.r.tv.LDD.acute.cond.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) long.r.tv.LDD.acute.cond.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.LDD.acute.cond.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } # end model.ldd } # end LDD } # end time-varying finish=get.finish() } } ######################### # 2.4.3. Batch command # ######################### long.r.batch <- function(N=100,Pi=0.8,fixed=1,s.or.tau=1,tv=1,pe.type=1,pe=.5, vt0=0,rho.exp.t0=0,rho.e=.5,pattern=1,model.cmd=1,model.ldd=1, notation=1,beta=0.1,mu00=10,p1=.1,correlation=1,sigma2=1, rho=0.8,theta=0.5,notation.rs=1,sigma2w=0.1,sigma20=0.3, sigma21=0.01,sigma01=0,r.tilde=5,rho.b1=0.1,rho01=0,gamma3=.1, p2=.1,p3=.1,alpha=0.05,max.r=50) { to.file=1 if (tv==1) { # time-invariant if (pattern == 1 ) { # CMD if (notation == 2) beta=p1*mu00 if (correlation==1) { long.r.CMD.coef.CS(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { long.r.CMD.coef.DEX(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.CMD.coef.RS(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else { # LDD if (notation == 2) { if (p2==0) { gamma3=(1+p1)*p3*mu00/(s.or.tau) } else { gamma3=p2*p3*mu00/(s.or.tau) } } if (correlation==1) { long.r.LDD.coef.CS(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { long.r.LDD.coef.DEX(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.LDD.coef.RS(N,Pi,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } # end LDD } else { # TIME-VARYING pe.type=1 if (pattern == 1) { # CMD if (notation == 2) beta=p1*mu00 if (model.cmd==1) { if (correlation==1) { long.r.tv.CMD.marg.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { long.r.tv.CMD.marg.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.CMD.marg.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else if (model.cmd==2) { if (correlation==1) { long.r.tv.CMD.cond.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { long.r.tv.CMD.cond.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.CMD.cond.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else if (model.cmd==3) { if (correlation==1) { long.r.tv.CMD.marg.time.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { long.r.tv.CMD.marg.time.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.CMD.marg.time.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else { # model.cmd==4 if (correlation==1) { long.r.tv.CMD.cond.time.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { long.r.tv.CMD.cond.time.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.CMD.cond.time.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } # end model.cmd } else { # LDD if (notation == 2) { if (p2==0) gamma3=(1+p1)*p3*mu00/(s.or.tau) else gamma3=p2*p3*mu00/(s.or.tau) } if (model.ldd==1) { if (correlation==1) { long.r.tv.LDD.cum.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { long.r.tv.LDD.cum.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.LDD.cum.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else if (model.ldd==2) { if (correlation==1) { long.r.tv.LDD.cum.cond.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { long.r.tv.LDD.cum.cond.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.LDD.cum.cond.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else if (model.ldd==3) { if (correlation==1) { long.r.tv.LDD.acute.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { long.r.tv.LDD.acute.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.LDD.acute.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } else if (model.ldd==4) { if (correlation==1) { long.r.tv.LDD.acute.cond.coef.CS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha,max.r,to.file) } else if (correlation==2) { long.r.tv.LDD.acute.cond.coef.DEX(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } long.r.tv.LDD.acute.cond.coef.RS(N,Pi,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha,max.r,to.file) } # end correlation } # end model.ldd } # end LDD } # end time-varying } ########################## # 2.4.4. Batch functions # ########################## ###### # r1 # ###### r.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","alpha")) pattern=1 notation=2 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # r2 # ###### r.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","theta","alpha")) pattern=1 notation=2 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # r3 # ###### r.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=2 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # r4 # ###### r.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=2 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # r5 # ###### r.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","alpha")) pattern=1 notation=1 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # r6 # ###### r.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","theta","alpha")) pattern=1 notation=1 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # r7 # ###### r.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=1 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # r8 # ###### r.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=1 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # r9 # ###### r.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","alpha")) pattern=2 notation=2 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r10 # ####### r.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","theta","alpha")) pattern=2 notation=2 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r11 # ####### r.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=2 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r12 # ####### r.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=2 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r13 # ####### r.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","alpha")) pattern=2 notation=1 correlation=1 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r14 # ####### r.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","theta","alpha")) pattern=2 notation=1 correlation=2 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r15 # ####### r.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=1 correlation=3 notation.rs=1 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r16 # ####### r.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=1 correlation=3 notation.rs=2 tv=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],vt0=vt0[i],rho.exp.t0=rho.exp.t0[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r17 # ####### r.tv.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2","rho","alpha")) pattern=1 notation=2 correlation=1 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r18 # ####### r.tv.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2","rho","theta","alpha")) pattern=1 notation=2 correlation=2 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r19 # ####### r.tv.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=2 correlation=3 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r20 # ####### r.tv.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=2 correlation=3 notation.rs=2 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.cmd=model.cmd[i], mu00=mu00[i],p1=p1[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r21 # ####### r.tv.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2","rho","alpha")) pattern=1 notation=1 correlation=1 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r22 # ####### r.tv.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2","rho","theta","alpha")) pattern=1 notation=1 correlation=2 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r23 # ####### r.tv.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=1 notation=1 correlation=3 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r24 # ####### r.tv.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=1 notation=1 correlation=3 notation.rs=2 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.cmd=model.cmd[i], beta=beta[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r25 # ####### r.tv.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","alpha")) pattern=2 notation=2 correlation=1 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r26 # ####### r.tv.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","theta","alpha")) pattern=2 notation=2 correlation=2 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r27 # ####### r.tv.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=2 correlation=3 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r28 # ####### r.tv.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=2 correlation=3 notation.rs=2 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.ldd=model.ldd[i], mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r29 # ####### r.tv.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2","rho","alpha")) pattern=2 notation=1 correlation=1 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r30 # ####### r.tv.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2","rho","theta","alpha")) pattern=2 notation=1 correlation=2 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i],theta=theta[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r31 # ####### r.tv.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2w","sigma20","sigma21", "sigma01","alpha")) pattern=2 notation=1 correlation=3 notation.rs=1 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2w=sigma2w[i],sigma20=sigma20[i], sigma21=sigma21[i],sigma01=sigma01[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # r32 # ####### r.tv.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("N","Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2","rho","rho.b1", "rho01","r.tilde","alpha")) pattern=2 notation=1 correlation=3 notation.rs=2 tv=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } out=vector() for (i in 1:(dim(data)[1])) { out[i]=long.r.batch(N=N[i],Pi=Pi[i],fixed=fixed[i], s.or.tau=s.or.tau[i],pe=pe[i],rho.e=rho.e[i],model.ldd=model.ldd[i], gamma3=gamma3[i],sigma2=sigma2[i],rho=rho[i], rho.b1=rho.b1[i],rho01=rho01[i],r.tilde=r.tilde[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ############################################################################# ############################################################################# # 2.5. Optimal using costs ############################################################################# ############################################################################# ###################### # 2.5.1. Functions # ###################### # ------------- # Time-varying # ------------- ### CMD ### # **************************************************** # * Optimal N,r for CMD and CS when user enters beta * # **************************************************** long.opt.CMD.coef.CS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=0:max.r var.vector=rep(0,max.r+1) to.min=rep(0,max.r+1) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { power.vector.power[i]=long.power.s.CMD.coef.CS(N.vector.power[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha) var.vector[i]=long.var.s.CMD.CS(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2,rho) } } else { for (i in 1:(max.r+1)) { if (r.vector[i]==0) s=0 else s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.CMD.coef.CS(N.vector.power[i],r.vector[i],s,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha) var.vector[i]=long.var.s.CMD.CS(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2,rho) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r+1) power.vector.cost=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { var.vector[i]=long.var.s.CMD.CS(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.CMD.coef.CS(N.vector.cost[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha) } } else { for (i in 1:(max.r+1)) { if (r.vector[i]==0) s=0 else s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.CMD.CS(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.CMD.coef.CS(N.vector.cost[i],r.vector[i],s,pe,vt0,rho.exp.t0,beta,sigma2,rho,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ***************************************************** # * Optimal N,r for CMD and DEX when user enters beta * # ***************************************************** long.opt.CMD.coef.DEX=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=0:max.r var.vector=rep(0,max.r+1) to.min=rep(0,max.r+1) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { power.vector.power[i]=long.power.s.CMD.coef.DEX(N.vector.power[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.CMD.DEX(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2,rho,theta) } } else { for (i in 1:(max.r+1)) { if (r.vector[i]==0) s=0 else s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.CMD.coef.DEX(N.vector.power[i],r.vector[i],s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.CMD.DEX(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2,rho,theta) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r+1) power.vector.cost=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { var.vector[i]=long.var.s.CMD.DEX(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.CMD.coef.DEX(N.vector.cost[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) } } else { for (i in 1:(max.r+1)) { if (r.vector[i]==0) s=0 else s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.CMD.DEX(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.CMD.coef.DEX(N.vector.cost[i],r.vector[i],s,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # **************************************************** # * Optimal N,r for CMD and RS when user enters beta * # **************************************************** long.opt.CMD.coef.RS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=0:max.r var.vector=rep(0,max.r+1) to.min=rep(0,max.r+1) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { power.vector.power[i]=long.power.s.CMD.coef.RS(N.vector.power[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.CMD.RS(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) } } else { for (i in 1:(max.r+1)) { if (r.vector[i]==0) s=0 else s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.CMD.coef.RS(N.vector.power[i],r.vector[i],s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.CMD.RS(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r+1) power.vector.cost=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { var.vector[i]=long.var.s.CMD.RS(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.CMD.coef.RS(N.vector.cost[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { for (i in 1:(max.r+1)) { if (r.vector[i]==0) s=0 else s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.CMD.RS(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.CMD.coef.RS(N.vector.cost[i],r.vector[i],s,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } ### LDD ### # ***************************************************** # * Optimal N,r for LDD and CS when user enters gamma * # ***************************************************** long.opt.LDD.coef.CS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.LDD.coef.CS(N.vector.power[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha) var.vector[i]=long.var.s.LDD.CS(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2,rho) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.LDD.coef.CS(N.vector.power[i],r.vector[i],s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha) var.vector[i]=long.var.s.LDD.CS(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2,rho) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.LDD.CS(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.LDD.coef.CS(N.vector.cost[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.LDD.CS(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.LDD.coef.CS(N.vector.cost[i],r.vector[i],s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ****************************************************** # * Optimal N,r for LDD and DEX when user enters gamma * # ****************************************************** long.opt.LDD.coef.DEX=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.LDD.coef.DEX(N.vector.power[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.LDD.DEX(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2,rho,theta) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.LDD.coef.DEX(N.vector.power[i],r.vector[i],s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.LDD.DEX(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2,rho,theta) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.LDD.DEX(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.LDD.coef.DEX(N.vector.cost[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.LDD.DEX(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.LDD.coef.DEX(N.vector.cost[i],r.vector[i],s,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ***************************************************** # * Optimal N,r for LDD and RS when user enters gamma * # ***************************************************** long.opt.LDD.coef.RS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.LDD.coef.RS(N.vector.power[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.LDD.RS(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.LDD.coef.RS(N.vector.power[i],r.vector[i],s,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.LDD.RS(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.LDD.RS(r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.LDD.coef.RS(N.vector.cost[i],r.vector[i],s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.LDD.RS(r.vector[i],s,pe,vt0,rho.exp.t0,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.LDD.coef.RS(N.vector.cost[i],r.vector[i],s,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ------------- # Time-varying # ------------- ### CMD ### # Model without time, marginal # **************************************************** # * Optimal N,r for CMD and CS when user enters beta * # **************************************************** long.opt.tv.CMD.marg.coef.CS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=0:max.r var.vector=rep(0,max.r+1) to.min=rep(0,max.r+1) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { power.vector.power[i]=long.power.s.tv.CMD.marg.coef.CS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.CMD.marg.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) } } else { for (i in 1:(max.r+1)) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.marg.coef.CS(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.CMD.marg.CS(r.vector[i],s,pe,rho.e,sigma2,rho) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r+1) power.vector.cost=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { var.vector[i]=long.var.s.tv.CMD.marg.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.coef.CS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,alpha) } } else { for (i in 1:(max.r+1)) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.marg.CS(r.vector[i],s,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.coef.CS(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ***************************************************** # * Optimal N,r for CMD and DEX when user enters beta * # ***************************************************** long.opt.tv.CMD.marg.coef.DEX=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=0:max.r var.vector=rep(0,max.r+1) to.min=rep(0,max.r+1) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { power.vector.power[i]=long.power.s.tv.CMD.marg.coef.DEX(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.CMD.marg.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) } } else { for (i in 1:(max.r+1)) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.marg.coef.DEX(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.CMD.marg.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r+1) power.vector.cost=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { var.vector[i]=long.var.s.tv.CMD.marg.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.coef.DEX(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha) } } else { for (i in 1:(max.r+1)) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.marg.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.coef.DEX(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,theta,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # **************************************************** # * Optimal N,r for CMD and RS when user enters beta * # **************************************************** long.opt.tv.CMD.marg.coef.RS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=0:max.r var.vector=rep(0,max.r+1) to.min=rep(0,max.r+1) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { power.vector.power[i]=long.power.s.tv.CMD.marg.coef.RS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.CMD.marg.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } else { for (i in 1:(max.r+1)) { if (r.vector[i]==0) s=0 else s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.marg.coef.RS(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.CMD.marg.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r+1) power.vector.cost=rep(0,max.r+1) if (fixed==1) { for (i in 1:(max.r+1)) { var.vector[i]=long.var.s.tv.CMD.marg.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.coef.RS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { for (i in 1:(max.r+1)) { if (r.vector[i]==0) s=0 else s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.marg.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.coef.RS(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # Model without time, conditional # **************************************************** # * Optimal N,r for CMD and CS when user enters beta * # **************************************************** long.opt.tv.CMD.cond.coef.CS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r var.vector=rep(0,max.r) to.min=rep(0,max.r) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { power.vector.power[i]=long.power.s.tv.CMD.cond.coef.CS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.CMD.cond.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.cond.coef.CS(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.CMD.cond.CS(r.vector[i],s,pe,rho.e,sigma2,rho) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { var.vector[i]=long.var.s.tv.CMD.cond.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.coef.CS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,alpha) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.cond.CS(r.vector[i],s,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.coef.CS(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ***************************************************** # * Optimal N,r for CMD and DEX when user enters beta * # ***************************************************** long.opt.tv.CMD.cond.coef.DEX=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r var.vector=rep(0,max.r) to.min=rep(0,max.r) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { power.vector.power[i]=long.power.s.tv.CMD.cond.coef.DEX(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.CMD.cond.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.cond.coef.DEX(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.CMD.cond.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { var.vector[i]=long.var.s.tv.CMD.cond.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.coef.DEX(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.cond.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.coef.DEX(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,theta,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # **************************************************** # * Optimal N,r for CMD and RS when user enters beta * # **************************************************** long.opt.tv.CMD.cond.coef.RS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r var.vector=rep(0,max.r) to.min=rep(0,max.r) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { power.vector.power[i]=long.power.s.tv.CMD.cond.coef.RS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.CMD.cond.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.cond.coef.RS(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.CMD.cond.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { var.vector[i]=long.var.s.tv.CMD.cond.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.coef.RS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.cond.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.coef.RS(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # Model with time, marginal # **************************************************** # * Optimal N,r for CMD and CS when user enters beta * # **************************************************** long.opt.tv.CMD.marg.time.coef.CS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r var.vector=rep(0,max.r) to.min=rep(0,max.r) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { power.vector.power[i]=long.power.s.tv.CMD.marg.time.coef.CS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.CMD.marg.time.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.marg.time.coef.CS(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.CMD.marg.time.CS(r.vector[i],s,pe,rho.e,sigma2,rho) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { var.vector[i]=long.var.s.tv.CMD.marg.time.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.time.coef.CS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,alpha) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.marg.time.CS(r.vector[i],s,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.time.coef.CS(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ***************************************************** # * Optimal N,r for CMD and DEX when user enters beta * # ***************************************************** long.opt.tv.CMD.marg.time.coef.DEX=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r var.vector=rep(0,max.r) to.min=rep(0,max.r) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { power.vector.power[i]=long.power.s.tv.CMD.marg.time.coef.DEX(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.CMD.marg.time.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.marg.time.coef.DEX(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.CMD.marg.time.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { var.vector[i]=long.var.s.tv.CMD.marg.time.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.time.coef.DEX(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.marg.time.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.time.coef.DEX(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,theta,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # **************************************************** # * Optimal N,r for CMD and RS when user enters beta * # **************************************************** long.opt.tv.CMD.marg.time.coef.RS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r var.vector=rep(0,max.r) to.min=rep(0,max.r) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { power.vector.power[i]=long.power.s.tv.CMD.marg.time.coef.RS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.CMD.marg.time.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.marg.time.coef.RS(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.CMD.marg.time.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { var.vector[i]=long.var.s.tv.CMD.marg.time.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.time.coef.RS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.marg.time.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.marg.time.coef.RS(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # Model with time, conditional # **************************************************** # * Optimal N,r for CMD and CS when user enters beta * # **************************************************** long.opt.tv.CMD.cond.time.coef.CS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r var.vector=rep(0,max.r) to.min=rep(0,max.r) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { power.vector.power[i]=long.power.s.tv.CMD.cond.time.coef.CS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.CMD.cond.time.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.cond.time.coef.CS(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.CMD.cond.time.CS(r.vector[i],s,pe,rho.e,sigma2,rho) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { var.vector[i]=long.var.s.tv.CMD.cond.time.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.time.coef.CS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,alpha) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.cond.time.CS(r.vector[i],s,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.time.coef.CS(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ***************************************************** # * Optimal N,r for CMD and DEX when user enters beta * # ***************************************************** long.opt.tv.CMD.cond.time.coef.DEX=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r var.vector=rep(0,max.r) to.min=rep(0,max.r) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { power.vector.power[i]=long.power.s.tv.CMD.cond.time.coef.DEX(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.CMD.cond.time.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.cond.time.coef.DEX(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.CMD.cond.time.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { var.vector[i]=long.var.s.tv.CMD.cond.time.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.time.coef.DEX(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2,rho,theta,alpha) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.cond.time.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.time.coef.DEX(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2,rho,theta,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # **************************************************** # * Optimal N,r for CMD and RS when user enters beta * # **************************************************** long.opt.tv.CMD.cond.time.coef.RS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r var.vector=rep(0,max.r) to.min=rep(0,max.r) if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { power.vector.power[i]=long.power.s.tv.CMD.cond.time.coef.RS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.CMD.cond.time.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.CMD.cond.time.coef.RS(N.vector.power[i],r.vector[i],s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.CMD.cond.time.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) if (fixed==1) { for (i in 1:(max.r)) { var.vector[i]=long.var.s.tv.CMD.cond.time.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.time.coef.RS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { for (i in 1:(max.r)) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.CMD.cond.time.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(beta^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.CMD.cond.time.coef.RS(N.vector.cost[i],r.vector[i],s,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } ### LDD ### ## acute exposure, marginal # ***************************************************** # * Optimal N,r for LDD and CS when user enters gamma * # ***************************************************** long.opt.tv.LDD.acute.coef.CS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.acute.coef.CS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.LDD.acute.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.acute.coef.CS(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.LDD.acute.CS(r.vector[i],s,pe,rho.e,sigma2,rho) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.acute.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.coef.CS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.acute.CS(r.vector[i],s,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.coef.CS(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ****************************************************** # * Optimal N,r for LDD and DEX when user enters gamma * # ****************************************************** long.opt.tv.LDD.acute.coef.DEX=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.acute.coef.DEX(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.LDD.acute.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.acute.coef.DEX(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.LDD.acute.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.acute.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.coef.DEX(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.acute.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.coef.DEX(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ***************************************************** # * Optimal N,r for LDD and RS when user enters gamma * # ***************************************************** long.opt.tv.LDD.acute.coef.RS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.acute.coef.RS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.LDD.acute.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.acute.coef.RS(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.LDD.acute.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.acute.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.coef.RS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.acute.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.coef.RS(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } ### acute exposure, conditional # ***************************************************** # * Optimal N,r for LDD and CS when user enters gamma * # ***************************************************** long.opt.tv.LDD.acute.cond.coef.CS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.acute.cond.coef.CS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.LDD.acute.cond.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.acute.cond.coef.CS(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.LDD.acute.cond.CS(r.vector[i],s,pe,rho.e,sigma2,rho) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.acute.cond.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.cond.coef.CS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.acute.cond.CS(r.vector[i],s,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.cond.coef.CS(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ****************************************************** # * Optimal N,r for LDD and DEX when user enters gamma * # ****************************************************** long.opt.tv.LDD.acute.cond.coef.DEX=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.acute.cond.coef.DEX(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.LDD.acute.cond.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.acute.cond.coef.DEX(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.LDD.acute.cond.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.acute.cond.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.cond.coef.DEX(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.acute.cond.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.cond.coef.DEX(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ***************************************************** # * Optimal N,r for LDD and RS when user enters gamma * # ***************************************************** long.opt.tv.LDD.acute.cond.coef.RS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.acute.cond.coef.RS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.LDD.acute.cond.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.acute.cond.coef.RS(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.LDD.acute.cond.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.acute.cond.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.cond.coef.RS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.acute.cond.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.acute.cond.coef.RS(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } ## cumulative exposure, marginal # ***************************************************** # * Optimal N,r for LDD and CS when user enters gamma * # ***************************************************** long.opt.tv.LDD.cum.coef.CS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.cum.coef.CS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.LDD.cum.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.cum.coef.CS(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.LDD.cum.CS(r.vector[i],s,pe,rho.e,sigma2,rho) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.cum.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.coef.CS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.cum.CS(r.vector[i],s,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.coef.CS(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ****************************************************** # * Optimal N,r for LDD and DEX when user enters gamma * # ****************************************************** long.opt.tv.LDD.cum.coef.DEX=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.cum.coef.DEX(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.LDD.cum.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.cum.coef.DEX(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.LDD.cum.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.cum.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.coef.DEX(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.cum.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.coef.DEX(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ***************************************************** # * Optimal N,r for LDD and RS when user enters gamma * # ***************************************************** long.opt.tv.LDD.cum.coef.RS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.cum.coef.RS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.LDD.cum.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.cum.coef.RS(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.LDD.cum.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.cum.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.coef.RS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.cum.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.coef.RS(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } ## cumulative exposure, conditional # ***************************************************** # * Optimal N,r for LDD and CS when user enters gamma * # ***************************************************** long.opt.tv.LDD.cum.cond.coef.CS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.cum.cond.coef.CS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.LDD.cum.cond.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.cum.cond.coef.CS(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,alpha) var.vector[i]=long.var.s.tv.LDD.cum.cond.CS(r.vector[i],s,pe,rho.e,sigma2,rho) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.cum.cond.CS(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.cond.coef.CS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.cum.cond.CS(r.vector[i],s,pe,rho.e,sigma2,rho) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.cond.coef.CS(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ****************************************************** # * Optimal N,r for LDD and DEX when user enters gamma * # ****************************************************** long.opt.tv.LDD.cum.cond.coef.DEX=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.cum.cond.coef.DEX(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.LDD.cum.cond.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.cum.cond.coef.DEX(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) var.vector[i]=long.var.s.tv.LDD.cum.cond.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.cum.cond.DEX(r.vector[i],s.or.tau,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.cond.coef.DEX(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.cum.cond.DEX(r.vector[i],s,pe,rho.e,sigma2,rho,theta) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.cond.coef.DEX(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2,rho,theta,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } # ***************************************************** # * Optimal N,r for LDD and RS when user enters gamma * # ***************************************************** long.opt.tv.LDD.cum.cond.coef.RS=function(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha=0.05,max.r=50,to.file=2) { # opt.problem=2 if min cost subject to a given power, # opt.problem=1 if max power subject to a given cost # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 # s.or.tau is s if fixed==1 or tau if fixed==2 r.vector=1:max.r if (opt.problem==1) { budget=Pi.or.budget N.vector.power=floor(budget*k/(c1*(k+r.vector))) power.vector.power=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { power.vector.power[i]=long.power.s.tv.LDD.cum.cond.coef.RS(N.vector.power[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.LDD.cum.cond.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] power.vector.power[i]=long.power.s.tv.LDD.cum.cond.coef.RS(N.vector.power[i],r.vector[i],s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) var.vector[i]=long.var.s.tv.LDD.cum.cond.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) } } to.max=unlist(power.vector.power) r=r.vector[match(max(to.max),to.max)] N.power=N.vector.power[match(max(to.max),to.max)] power.power=power.vector.power[match(max(to.max),to.max)] cost.power=N.power*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Power optimization problem (max power for a given cost):\n") cat(" Optimal r=",r,", Optimal N=",N.power,", Power=",round(power.power,2), ",Cost=",cost.power,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,power.vector.power,type="b",lty=2,pch=20,xlab="r",ylab="Power", ylim=c(0,1),main="Power for a given cost") } else { result=c(N.power,r,round(power.power,2),cost.power) return(result) } } else { Pi=Pi.or.budget N.vector.cost=rep(0,max.r) power.vector.cost=rep(0,max.r) var.vector=rep(0,max.r) to.min=rep(0,max.r) if (fixed==1) { for (i in 1:max.r) { var.vector[i]=long.var.s.tv.LDD.cum.cond.RS(r.vector[i],s.or.tau,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.cond.coef.RS(N.vector.cost[i],r.vector[i],s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } } else { for (i in 1:max.r) { s=s.or.tau/r.vector[i] var.vector[i]=long.var.s.tv.LDD.cum.cond.RS(r.vector[i],s,pe,rho.e,sigma2w,sigma20,sigma21,sigma01) to.min[i]=(r.vector[i]+k)*var.vector[i] N.vector.cost[i]=ceiling(var.vector[i]*((qnorm(1-alpha/2)+qnorm(Pi))^2)/(gamma3^2)) # for cost optimization problem power.vector.cost[i]=long.power.s.tv.LDD.cum.cond.coef.RS(N.vector.cost[i],r.vector[i],s,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,alpha) } } cost.vector.cost=N.vector.cost*c1*(1+r.vector/k) to.min.vec=unlist(cost.vector.cost) r=r.vector[match(min(to.min.vec),to.min.vec)] N.cost=N.vector.cost[match(min(to.min.vec),to.min.vec)] power.cost=power.vector.cost[match(min(to.min.vec),to.min.vec)] cost.cost=N.cost*c1*(1+r/k) if (to.file==2) { if (fixed==1) reliab=sigma21/(sigma21+12*sigma2w/((s.or.tau^2)*r*(r+1)*(r+2))) else reliab=sigma21/(sigma21+12*sigma2w*r/((s.or.tau^2)*(r+1)*(r+2))) if (r==0) reliab=0 cat("Cost optimization problem (min cost for a given power):\n") cat(" Optimal r=",r,", Optimal N=",N.cost,", Power=",round(power.cost,2), ",Cost=",cost.cost,"\n") cat("\n") cat("Slope reliability at r=",r,": ",reliab,"\n") plot(r.vector,cost.vector.cost,type="b",lty=2,pch=20,xlab="r",ylab="Cost", main="Cost for a given power") } else { result=c(N.cost,r,round(power.cost,2),cost.cost) return(result) } } } ######################### # 2.5.2. User interface # ######################### long.opt <- function() { # Initialize parameters opt.problem=1 Pi=0.8 budget=1000 fixed=1 s.or.tau=1 tv=1 pe.type=1 pe=.5 vt0=0 rho.exp.t0=0 rho.e=0.5 pattern=1 model.cmd=1 model.ldd=1 notation=1 beta=0.1 mu00=10 p1=.1 correlation=1 sigma2=1 rho=0.8 theta=0.5 notation.rs=1 sigma2w=0.1 sigma20=0.3 sigma21=0.01 sigma01=0 r.tilde=5 rho.b1=0.1 rho01=0 gamma3=.1 p2=.1 p3=.1 c1=80 k=2 alpha=.05 max.r=50 to.file=2 finish=F while (finish==F) { cat("\n* By just pressing after each question, the default value, shown\n between square brackets, will be entered.\n\n") cat("* Press to quit\n\n") # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 opt.problem=get.opt.problem(opt.problem) if (opt.problem==2) { Pi.or.budget=get.Pi(Pi) # minimize cost problem Pi=Pi.or.budget } fixed=get.fixed(fixed) if (fixed==1) s.or.tau=get.s(s.or.tau) else s.or.tau=get.tau(s.or.tau) tv=get.tv(tv) if (tv==1) { # time-invariant pe=get.pe(pe) vt0=get.vt0(vt0) if (vt0!=0) rho.exp.t0=get.rho.exp.t0(rho.exp.t0) pattern=get.pattern(pattern) if (pattern == 1) { # CMD notation=get.notation(notation) if (notation == 1) beta=get.beta(beta) else { mu00=get.mu00(mu00) p1=get.p1(p1) beta=p1*mu00 } correlation=get.correlation(correlation) if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.CMD.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.CMD.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.CMD.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else { # LDD notation=get.notation(notation) if (notation == 1) gamma3=get.gamma(gamma3) else { if (fixed==1) cat("** Your percent changes will refer to a change of s units,\n and NOT from beginning to end of follow-up\n") mu00=get.mu00(mu00) p2=get.p2(fixed,p2) if (p2==0) { p1=get.p1(p1) p3=get.p3.p20(fixed,p3) gamma3=(1+p1)*p3*mu00/(s.or.tau) } else { p3=get.p3(fixed,p3) gamma3=p2*p3*mu00/(s.or.tau) } } correlation=get.correlation(correlation) # s.or.tau is s if fixed==1 or tau if fixed==2 if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.LDD.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.LDD.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) if (vt0 == 0) sigma01=0 else sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) if (vt0 == 0) rho01=0 else rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.LDD.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } # end LDD } else { # TIME-VARYING pe.type=1 pe=get.pe(pe) rho.e=get.rhoe.no.r(rho.e) pattern=get.pattern(pattern) if (pattern == 1) { # CMD model.cmd=get.model.cmd(model.cmd) notation=get.notation(notation) if (notation == 1) beta=get.beta(beta) else { mu00=get.mu00(mu00) p1=get.p1(p1) beta=p1*mu00 } correlation=get.correlation(correlation) if (model.cmd==1) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.marg.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.marg.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.marg.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else if (model.cmd==2) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.cond.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.cond.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.cond.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else if (model.cmd==3) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.marg.time.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.marg.time.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.marg.time.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else { # model.cmd==4 if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.cond.time.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.cond.time.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.CMD.cond.time.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } # end model.cmd } else { # LDD model.ldd=get.model.ldd(model.ldd) notation=get.notation(notation) if (notation == 1) gamma3=get.gamma(gamma3) else { if (fixed==1) cat("** Your percent changes will refer to a change of s units,\n and NOT from beginning to end of follow-up\n") mu00=get.mu00(mu00) p2=get.p2(fixed,p2) if (p2==0) { p1=get.p1(p1) p3=get.p3.p20(fixed,p3) gamma3=(1+p1)*p3*mu00/(s.or.tau) } else { p3=get.p3(fixed,p3) gamma3=p2*p3*mu00/(s.or.tau) } } correlation=get.correlation(correlation) if (model.ldd==1) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.cum.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.cum.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.cum.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else if (model.ldd==2) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.cum.cond.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.cum.cond.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.cum.cond.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else if (model.ldd==3) { if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.acute.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.acute.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.acute.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else { # model.ldd==4 if (correlation==1) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.acute.cond.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) theta=get.theta(theta) if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.acute.cond.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { notation.rs=get.notation.rs(notation.rs) if (notation.rs==1) { sigma2w=get.sigma2w(sigma2w) sigma20=get.sigma20(sigma20) sigma21=get.sigma21(sigma21) sigma01=get.sigma01(sigma01) } else { sigma2=get.sigma2(correlation,sigma2) rho=get.rho(correlation,rho) r.tilde=get.r.tilde(r.tilde) rho.b1=get.rho.b1(r.tilde,rho.b1) rho01=get.rho01(rho01) sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) { Pi.or.budget=get.budget(budget) # maximize power problem budget=Pi.or.budget } c1=get.c1(c1) k=get.k(k) long.opt.tv.LDD.acute.cond.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } # end model.ldd } # end LDD } # end time-varying finish=get.finish() } } ######################## # 2.5.3. Batch command # ######################## long.opt.batch <- function(opt.problem=1,Pi.or.budget=0.8,fixed=1,s.or.tau=1, tv=1,pe.type=1,pe=.5,vt0=0,rho.exp.t0=0,rho.e=0.5,pattern=1, model.cmd=1,model.ldd=1,notation=1,beta=0.1,mu00=10,p1=.1, correlation=1,sigma2=1,rho=0.8,theta=0.5,notation.rs=1, sigma2w=.1,sigma20=.3,sigma21=0.01,sigma01=0,r.tilde=5, rho.b1=0.1,rho01=0,gamma3=0.1,p2=.1,p3=.1,c1=80,k=2,alpha=0.05, max.r=50) { to.file=1 # Pi.or.budget=Pi if opt.problem==2, Pi.or.budget=budget if opt.problem==1 if (opt.problem==2) { Pi=Pi.or.budget } if (tv==1) { # time-invariant if (pattern == 1) { # CMD if (notation == 2) beta=p1*mu00 if (correlation==1) { if (opt.problem==1) budget=Pi.or.budget long.opt.CMD.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { if (opt.problem==1) budget=Pi.or.budget long.opt.CMD.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) budget=Pi.or.budget long.opt.CMD.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else { # LDD if (notation == 2) { if (p2==0) { gamma3=(1+p1)*p3*mu00/(s.or.tau) } else { gamma3=p2*p3*mu00/(s.or.tau) } } if (correlation==1) { if (opt.problem==1) budget=Pi.or.budget long.opt.LDD.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { if (opt.problem==1) budget=Pi.or.budget long.opt.LDD.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) budget=Pi.or.budget long.opt.LDD.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,vt0,rho.exp.t0,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } # end LDD } else { # TIME-VARYING pe.type=1 if (pattern == 1) { # CMD if (notation == 2) beta=p1*mu00 if (model.cmd==1) { if (correlation==1) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.marg.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.marg.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.marg.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else if (model.cmd==2) { if (correlation==1) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.cond.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.cond.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.cond.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else if (model.cmd==3) { if (correlation==1) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.marg.time.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.marg.time.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.marg.time.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else { # model.cmd==4 if (correlation==1) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.cond.time.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.cond.time.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) budget=Pi.or.budget long.opt.tv.CMD.cond.time.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,beta,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } # end model.cmd } else { # LDD if (notation == 2) { if (p2==0) gamma3=(1+p1)*p3*mu00/(s.or.tau) else gamma3=p2*p3*mu00/(s.or.tau) } if (model.ldd==1) { if (correlation==1) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.cum.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.cum.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.cum.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else if (model.ldd==2) { if (correlation==1) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.cum.cond.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.cum.cond.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.cum.cond.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else if (model.ldd==3) { if (correlation==1) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.acute.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.acute.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.acute.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } else { # model.ldd==4 if (correlation==1) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.acute.cond.coef.CS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,c1,k,alpha,max.r,to.file) } else if (correlation==2) { if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.acute.cond.coef.DEX(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2,rho,theta,c1,k,alpha,max.r,to.file) } else if (correlation==3) { if (notation.rs==2) { sigma2w=(1-rho)*sigma2 sigma20=rho*sigma2 if (fixed==1) { # for fixed==1, s.or.tau is s sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2/((s.or.tau^2)*r.tilde*(r.tilde+1)*(r.tilde+2))) } else { # for fixed==2, s.or.tau is tau sigma21=(rho.b1/(1-rho.b1))*(12*(1-rho)*sigma2*r.tilde/((s.or.tau^2)*(r.tilde+1)*(r.tilde+2))) } sigma01=rho01*sqrt(sigma20)*sqrt(sigma21) } if (opt.problem==1) budget=Pi.or.budget long.opt.tv.LDD.acute.cond.coef.RS(opt.problem,Pi.or.budget,fixed,s.or.tau,pe,rho.e,gamma3,sigma2w,sigma20,sigma21,sigma01,c1,k,alpha,max.r,to.file) } # end correlation } # end model.ldd } # end LDD } # end time-varying } ########################## # 2.5.4. Batch functions # ########################## # opt.problem=1 # Pi.or.budget=budget # Max power for a given cost ###### # O1 # ###### opt.power.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=1 notation=2 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # O2 # ###### opt.power.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","theta","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=1 notation=2 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # O3 # ###### opt.power.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2w","sigma20","sigma21", "sigma01","budget","c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=1 notation=2 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # O4 # ###### opt.power.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","rho.b1","rho01", "r.tilde","budget","c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=1 notation=2 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # O5 # ###### opt.power.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=1 notation=1 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # O6 # ###### opt.power.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","theta","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=1 notation=1 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # O7 # ###### opt.power.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2w","sigma20","sigma21", "sigma01","budget","c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=1 notation=1 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],beta=beta[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # O8 # ###### opt.power.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","rho.b1","rho01", "r.tilde","budget","c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=1 notation=1 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ###### # O9 # ###### opt.power.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=2 notation=2 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O10 # ####### opt.power.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","theta","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=2 notation=2 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O11 # ####### opt.power.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2w","sigma20","sigma21", "sigma01","budget","c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=2 notation=2 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O12 # ####### opt.power.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","rho.b1","rho01", "r.tilde","budget","c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=2 notation=2 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O13 # ####### opt.power.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=2 notation=1 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O14 # ####### opt.power.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","theta","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=2 notation=1 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O15 # ####### opt.power.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2w","sigma20","sigma21", "sigma01","budget","c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=2 notation=1 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],gamma3=gamma3[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O16 # ####### opt.power.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","rho.b1","rho01", "r.tilde","budget","c1","k","max.r","alpha")) opt.problem=1 tv=1 pattern=2 notation=1 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O17 # ####### opt.power.tv.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2","rho","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=1 notation=2 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O18 # ####### opt.power.tv.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2","rho","theta","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=1 notation=2 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O19 # ####### opt.power.tv.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2w","sigma20","sigma21", "sigma01","budget","c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=1 notation=2 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],mu00=mu00[i],p1=p1[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O20 # ####### opt.power.tv.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2","rho","rho.b1","rho01", "r.tilde","budget","c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=1 notation=2 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O21 # ####### opt.power.tv.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2","rho","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=1 notation=1 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O22 # ####### opt.power.tv.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2","rho","theta","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=1 notation=1 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O23 # ####### opt.power.tv.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2w","sigma20","sigma21", "sigma01","budget","c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=1 notation=1 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],beta=beta[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O24 # ####### opt.power.tv.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2","rho","rho.b1","rho01", "r.tilde","budget","c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=1 notation=1 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O25 # ####### opt.power.tv.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=2 notation=2 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O26 # ####### opt.power.tv.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","theta","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=2 notation=2 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O27 # ####### opt.power.tv.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2w","sigma20","sigma21", "sigma01","budget","c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=2 notation=2 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O28 # ####### opt.power.tv.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","rho.b1","rho01", "r.tilde","budget","c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=2 notation=2 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O29 # ####### opt.power.tv.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2","rho","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=2 notation=1 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O30 # ####### opt.power.tv.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2","rho","theta","budget", "c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=2 notation=1 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O31 # ####### opt.power.tv.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2w","sigma20","sigma21", "sigma01","budget","c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=2 notation=1 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],gamma3=gamma3[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O32 # ####### opt.power.tv.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2","rho","rho.b1","rho01", "r.tilde","budget","c1","k","max.r","alpha")) opt.problem=1 tv=2 pattern=2 notation=1 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=budget out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } # opt.problem=2 # Pi.or.budget=Pi # Min cost for a given power ####### # O33 # ####### opt.cost.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho", "c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=1 notation=2 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O34 # ####### opt.cost.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","theta", "c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=1 notation=2 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O35 # ####### opt.cost.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2w","sigma20","sigma21", "sigma01","c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=1 notation=2 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O36 # ####### opt.cost.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","sigma2","rho","rho.b1","rho01", "r.tilde","c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=1 notation=2 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O37 # ####### opt.cost.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho", "c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=1 notation=1 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O38 # ####### opt.cost.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","theta", "c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=1 notation=1 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O39 # ####### opt.cost.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2w","sigma20","sigma21", "sigma01","c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=1 notation=1 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],beta=beta[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O40 # ####### opt.cost.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","beta","sigma2","rho","rho.b1","rho01", "r.tilde","c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=1 notation=1 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O41 # ####### opt.cost.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho", "c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=2 notation=2 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O42 # ####### opt.cost.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","theta", "c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=2 notation=2 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O43 # ####### opt.cost.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2w","sigma20","sigma21", "sigma01","c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=2 notation=2 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O44 # ####### opt.cost.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","mu00","p1","p2","p3","sigma2","rho","rho.b1","rho01", "r.tilde","c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=2 notation=2 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O45 # ####### opt.cost.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho", "c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=2 notation=1 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O46 # ####### opt.cost.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","theta", "c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=2 notation=1 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O47 # ####### opt.cost.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2w","sigma20","sigma21", "sigma01","c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=2 notation=1 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],gamma3=gamma3[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O48 # ####### opt.cost.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "vt0","rho.exp.t0","gamma3","sigma2","rho","rho.b1","rho01", "r.tilde","c1","k","max.r","alpha")) opt.problem=2 tv=1 pattern=2 notation=1 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], vt0=vt0[i],rho.exp.t0=rho.exp.t0[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O49 # ####### opt.cost.tv.CMD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2","rho", "c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=1 notation=2 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O50 # ####### opt.cost.tv.CMD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2","rho","theta", "c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=1 notation=2 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O51 # ####### opt.cost.tv.CMD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2w","sigma20","sigma21", "sigma01","c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=1 notation=2 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],mu00=mu00[i],p1=p1[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O52 # ####### opt.cost.tv.CMD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","mu00","p1","sigma2","rho","rho.b1","rho01", "r.tilde","c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=1 notation=2 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],mu00=mu00[i],p1=p1[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O53 # ####### opt.cost.tv.CMD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2","rho", "c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=1 notation=1 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O54 # ####### opt.cost.tv.CMD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2","rho","theta", "c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=1 notation=1 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O55 # ####### opt.cost.tv.CMD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2w","sigma20","sigma21", "sigma01","c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=1 notation=1 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],beta=beta[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O56 # ####### opt.cost.tv.CMD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.cmd","beta","sigma2","rho","rho.b1","rho01", "r.tilde","c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=1 notation=1 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.cmd=model.cmd[i],beta=beta[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O57 # ####### opt.cost.tv.LDD.p.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho", "c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=2 notation=2 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O58 # ####### opt.cost.tv.LDD.p.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","theta", "c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=2 notation=2 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O59 # ####### opt.cost.tv.LDD.p.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2w","sigma20","sigma21", "sigma01","c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=2 notation=2 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O60 # ####### opt.cost.tv.LDD.p.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","mu00","p1","p2","p3","sigma2","rho","rho.b1","rho01", "r.tilde","c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=2 notation=2 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],mu00=mu00[i],p1=p1[i],p2=p2[i],p3=p3[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O61 # ####### opt.cost.tv.LDD.coef.CS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2","rho", "c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=2 notation=1 correlation=1 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O62 # ####### opt.cost.tv.LDD.coef.DEX=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2","rho","theta", "c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=2 notation=1 correlation=2 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],theta=theta[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O63 # ####### opt.cost.tv.LDD.coef.RS=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2w","sigma20","sigma21", "sigma01","c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=2 notation=1 correlation=3 notation.rs=1 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],gamma3=gamma3[i], sigma2w=sigma2w[i],sigma20=sigma20[i],sigma21=sigma21[i], sigma01=sigma01[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } ####### # O64 # ####### opt.cost.tv.LDD.coef.RS.reliab=function(infile,outfile) { data=read.table(file=infile,col.names=c("Pi","fixed","s.or.tau","pe", "rho.e","model.ldd","gamma3","sigma2","rho","rho.b1","rho01", "r.tilde","c1","k","max.r","alpha")) opt.problem=2 tv=2 pattern=2 notation=1 correlation=3 notation.rs=2 pe.type=1 for (i in 1:(dim(data)[2])) { assign(colnames(data)[i],data[,i]) } Pi.or.budget=Pi out=matrix(0,nrow=dim(data)[1],ncol=4) for (i in 1:(dim(data)[1])) { out[i,]=long.opt.batch(fixed=fixed[i],s.or.tau=s.or.tau[i],pe=pe[i], rho.e=rho.e[i],model.ldd=model.ldd[i],gamma3=gamma3[i], sigma2=sigma2[i],rho=rho[i],rho.b1=rho.b1[i],rho01=rho01[i], r.tilde=r.tilde[i],Pi.or.budget=Pi.or.budget[i],c1=c1[i], k=k[i],max.r=max.r[i],alpha=alpha[i], pattern=pattern,notation=notation,correlation=correlation, notation.rs=notation.rs,tv=tv,pe.type=pe.type,opt.problem=opt.problem) } out=round(out,digits=3) write.table(out,outfile,row.names=F,col.names=F) } #---- ------------------------------------------------- ##### ################################################# # 3 # # Function to get which batch function to use # ##### ################################################# #---- ------------------------------------------------- get.quantity=function(quantity.old) { cat("Do you want to compute: (1) Power (Pi) (2) Number of participants (N) (3) Minimum detectable effect (4) Number of repeated measurements (r) (5) Optimal (N,r) to maximize power subject to a cost constraint (6) Optimal (N,r) to minimize cost subject to a power constraint\n") message=paste("Option [",quantity.old,"]: ",sep="") options(warn=-1) quantity.text=readline(message) if (quantity.text=="") { quantity=quantity.old cat("\n") } else { quantity=as.numeric(quantity.text) if ((quantity!=1 && quantity!=2 && quantity!=3 && quantity!=4 && quantity!=5 && quantity!=6) || is.na(quantity)==T) quantity=get.quantity(quantity.old) else { cat("\n") options(warn=0) } } return(quantity) } long.function=function() { # messages: P1="Function: power.CMD.p.CS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho alpha\n" P2="Function: power.CMD.p.DEX(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho theta alpha\n" P3="Function: power.CMD.p.RS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2w sigma20 sigma21 sigma01 alpha\n" P4="Function: power.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho rho.b1 rho01 r.tilde alpha\n" P5="Funciton: power.CMD.coef.CS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho alpha\n" P6="Function: power.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho theta alpha\n" P7="Function: power.CMD.coef.RS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2w sigma20 sigma21 sigma01 alpha\n" P8="Function: power.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho rho.b1 rho01 r.tilde alpha\n" P9="Function: power.LDD.p.CS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho alpha\n" P10="Function: power.LDD.p.DEX(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho theta alpha\n" P11="Function: power.LDD.p.RS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2w sigma20 sigma21 sigma01 alpha\n" P12="Function: power.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" P13="Function: power.LDD.coef.CS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho alpha\n" P14="Function: power.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho theta alpha\n" P15="Function: power.LDD.coef.RS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2w sigma20 sigma21 sigma01 alpha\n" P16="Function: power.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" P17="Function: power.tv.CMD.p.CS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.cmd mu00 p1 sigma2 rho alpha\n" P18="Function: power.tv.CMD.p.DEX(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.cmd mu00 p1 sigma2 rho theta alpha\n" P19="Function: power.tv.CMD.p.RS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.cmd mu00 p1 sigma2w sigma20 sigma21 sigma01 alpha\n" P20="Function: power.tv.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.cmd mu00 p1 sigma2 rho rho.b1 rho01 r.tilde alpha\n" P21="Function: power.tv.CMD.coef.CS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.cmd beta sigma2 rho alpha\n" P22="Function: power.tv.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.cmd beta sigma2 rho theta alpha\n" P23="Function: power.tv.CMD.coef.RS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.cmd beta sigma2w sigma20 sigma21 sigma01 alpha\n" P24="Function: power.tv.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.cmd beta sigma2 rho rho.b1 rho01 r.tilde alpha\n" P25="Function: power.tv.LDD.p.CS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 p3 sigma2 rho alpha\n" P26="Function: power.tv.LDD.p.DEX(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 p3 sigma2 rho theta alpha\n" P27="Function: power.tv.LDD.p.RS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 p3 sigma2w sigma20 sigma21 sigma01 alpha\n" P28="Function: power.tv.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 p3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" P29="Function: power.tv.LDD.coef.CS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.ldd gamma3 sigma2 rho alpha\n" P30="Function: power.tv.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.ldd gamma3 sigma2 rho theta alpha\n" P31="Function: power.tv.LDD.coef.RS(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.ldd gamma3 sigma2w sigma20 sigma21 sigma01 alpha\n" P32="Function: power.tv.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N r fixed s.or.tau pe0 per rho.e model.ldd gamma3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" N1="Function: N.CMD.p.CS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho alpha\n" N2="Function: N.CMD.p.DEX(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho theta alpha\n" N3="Function N.CMD.p.RS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2w sigma20 sigma21 sigma01 alpha\n" N4="Function: N.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho rho.b1 rho01 r.tilde alpha\n" N5="Function: N.CMD.coef.CS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho alpha\n" N6="Function: N.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho theta alpha\n" N7="Function: N.CMD.coef.RS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2w sigma20 sigma21 sigma01 alpha\n" N8="Function: N.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho rho.b1 rho01 r.tilde alpha\n" N9="Function: N.LDD.p.CS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho alpha\n" N10="Function: N.LDD.p.DEX(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho theta alpha\n" N11="Function: N.LDD.p.RS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2w sigma20 sigma21 sigma01 alpha\n" N12="Function: N.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" N13="Function: N.LDD.coef.CS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho alpha\n" N14="Function: N.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho theta alpha\n" N15="Function: N.LDD.coef.RS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2w sigma20 sigma21 sigma01 alpha\n" N16="Function: N.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" N17="Function: N.tv.CMD.p.CS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.cmd mu00 p1 sigma2 rho alpha\n" N18="Function: N.tv.CMD.p.DEX(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.cmd mu00 p1 sigma2 rho theta alpha\n" N19="Function: N.tv.CMD.p.RS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.cmd mu00 p1 sigma2w sigma20 sigma21 sigma01 alpha\n" N20="Function: N.tv.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.cmd mu00 p1 sigma2 rho rho.b1 rho01 r.tilde alpha\n" N21="Function: N.tv.CMD.coef.CS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.cmd beta sigma2 rho alpha\n" N22="Function: N.tv.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.cmd beta sigma2 rho theta alpha\n" N23="Function: N.tv.CMD.coef.RS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.cmd beta sigma2w sigma20 sigma21 sigma01 alpha\n" N24="Function: N.tv.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.cmd beta sigma2 rho rho.b1 rho01 r.tilde alpha\n" N25="Function: N.tv.LDD.p.CS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 p3 sigma2 rho alpha\n" N26="Function: N.tv.LDD.p.DEX(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 p3 sigma2 rho theta alpha\n" N27="Function: N.tv.LDD.p.RS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 p3 sigma2w sigma20 sigma21 sigma01 alpha\n" N28="Function: N.tv.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 p3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" N29="Function: N.tv.LDD.coef.CS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.ldd gamma3 sigma2 rho alpha\n" N30="Function: N.tv.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.ldd gamma3 sigma2 rho theta alpha\n" N31="Function: N.tv.LDD.coef.RS(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.ldd gamma3 sigma2w sigma20 sigma21 sigma01 alpha\n" N32="Function: N.tv.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: r Pi fixed s.or.tau pe0 per rho.e model.ldd gamma3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" E1="Function: effect.CMD.p.CS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 sigma2 rho alpha\n" E2="Function: effect.CMD.p.DEX(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 sigma2 rho theta alpha\n" E3="Function: effect.CMD.p.RS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 sigma2w sigma20 sigma21 sigma01 alpha\n" E4="Function: effect.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 sigma2 rho rho.b1 rho01 r.tilde alpha\n" E5="Function: effect.CMD.coef.CS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 sigma2 rho alpha\n" E6="Function: effect.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 sigma2 rho theta alpha\n" E7="Function: effect.CMD.coef.RS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 sigma2w sigma20 sigma21 sigma01 alpha\n" E8="Function: effect.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 sigma2 rho rho.b1 rho01 r.tilde alpha\n" E9="Function: effect.LDD.p.CS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 sigma2 rho alpha\n" E10="Function: effect.LDD.p.DEX(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 sigma2 rho theta alpha\n" E11="Function: effect.LDD.p.RS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 sigma2w sigma20 sigma21 sigma01 alpha\n" E12="Function: effect.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 sigma2 rho rho.b1 rho01 r.tilde alpha\n" E13="Function: effect.LDD.coef.CS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 sigma2 rho alpha\n" E14="Function: effect.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 sigma2 rho theta alpha\n" E15="Function: effect.LDD.coef.RS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 sigma2w sigma20 sigma21 sigma01 alpha\n" E16="Function: effect.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe vt0 rho.exp.t0 sigma2 rho rho.b1 rho01 r.tilde alpha\n" E17="Function: effect.tv.CMD.p.CS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.cmd mu00 sigma2 rho alpha\n" E18="Function: effect.tv.CMD.p.DEX(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.cmd mu00 sigma2 rho theta alpha\n" E19="Function: effect.tv.CMD.p.RS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.cmd mu00 sigma2w sigma20 sigma21 sigma01 alpha\n" E20="Function: effect.tv.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.cmd mu00 sigma2 rho rho.b1 rho01 r.tilde alpha\n" E21="Function: effect.tv.CMD.coef.CS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.cmd sigma2 rho alpha\n" E22="Function: effect.tv.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.cmd sigma2 rho theta alpha\n" E23="Function: effect.tv.CMD.coef.RS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.cmd sigma2w sigma20 sigma21 sigma01 alpha\n" E24="Function: effect.tv.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.cmd sigma2 rho rho.b1 rho01 r.tilde alpha\n" E25="Function: effect.tv.LDD.p.CS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 sigma2 rho alpha\n" E26="Function: effect.tv.LDD.p.DEX(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 sigma2 rho theta alpha\n" E27="Function: effect.tv.LDD.p.RS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 sigma2w sigma20 sigma21 sigma01 alpha\n" E28="Function: effect.tv.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.ldd mu00 p1 p2 sigma2 rho rho.b1 rho01 r.tilde alpha\n" E29="Function: effect.tv.LDD.coef.CS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.ldd sigma2 rho alpha\n" E30="Function: effect.tv.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.ldd sigma2 rho theta alpha\n" E31="Function: effect.tv.LDD.coef.RS(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.ldd sigma2w sigma20 sigma21 sigma01 alpha\n" E32="Function: effect.tv.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N r Pi fixed s.or.tau pe0 per rho.e model.ldd sigma2 rho rho.b1 rho01 r.tilde alpha\n" r1="Function: r.CMD.p.CS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho alpha\n" r2="Function: r.CMD.p.DEX(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho theta alpha\n" r3="Function: r.CMD.p.RS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2w sigma20 sigma21 sigma01 alpha\n" r4="Function: r.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho rho.b1 rho01 r.tilde alpha\n" r5="Function: r.CMD.coef.CS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho alpha\n" r6="Function: r.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho theta alpha\n" r7="Function: r.CMD.coef.RS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2w sigma20 sigma21 sigma01 alpha\n" r8="Function: r.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho rho.b1 rho01 r.tilde alpha\n" r9="Function: r.LDD.p.CS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho alpha\n" r10="Function: r.LDD.p.DEX(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho theta alpha\n" r11="Function: r.LDD.p.RS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2w sigma20 sigma21 sigma01 alpha\n" r12="Function: r.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" r13="Function: r.LDD.coef.CS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho alpha\n" r14="Function: r.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho theta alpha\n" r15="Function: r.LDD.coef.RS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2w sigma20 sigma21 sigma01 alpha\n" r16="Function: r.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" r17="Function: r.tv.CMD.p.CS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2 rho alpha\n" r18="Function: r.tv.CMD.p.DEX(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2 rho theta alpha\n" r19="Function: r.tv.CMD.p.RS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2w sigma20 sigma21 sigma01 alpha\n" r20="Function: r.tv.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2 rho rho.b1 rho01 r.tilde alpha\n" r21="Function: r.tv.CMD.coef.CS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.cmd beta sigma2 rho alpha\n" r22="Function: r.tv.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.cmd beta sigma2 rho theta alpha\n" r23="Function: r.tv.CMD.coef.RS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.cmd beta sigma2w sigma20 sigma21 sigma01 alpha\n" r24="Function: r.tv.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.cmd beta sigma2 rho rho.b1 rho01 r.tilde alpha\n" r25="Function: r.tv.LDD.p.CS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2 rho alpha\n" r26="Function: r.tv.LDD.p.DEX(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2 rho theta alpha\n" r27="Function: r.tv.LDD.p.RS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2w sigma20 sigma21 sigma01 alpha\n" r28="Function: r.tv.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" r29="Function: r.tv.LDD.coef.CS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.ldd gamma3 sigma2 rho alpha\n" r30="Function: r.tv.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.ldd gamma3 sigma2 rho theta alpha\n" r31="Function: r.tv.LDD.coef.RS(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.ldd gamma3 sigma2w sigma20 sigma21 sigma01 alpha\n" r32="Function: r.tv.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: N Pi fixed s.or.tau pe rho.e model.ldd gamma3 sigma2 rho rho.b1 rho01 r.tilde alpha\n" o1="Function: opt.power.CMD.p.CS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho budget c1 k max.r alpha\n" o2="Function: opt.power.CMD.p.DEX(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho theta budget c1 k max.r alpha\n" o3="Function: opt.power.CMD.p.RS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2w sigma20 sigma21 sigma01 budget c1 k max.r alpha\n" o4="Function: opt.power.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho rho.b1 rho01 r.tilde budget c1 k max.r alpha\n" o5="Function: opt.power.CMD.coef.CS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho budget c1 k max.r alpha\n" o6="Function: opt.power.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho theta budget c1 k max.r alpha\n" o7="Function: opt.power.CMD.coef.RS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2w sigma20 sigma21 sigma01 budget c1 k max.r alpha\n" o8="Function: opt.power.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho rho.b1 rho01 r.tilde budget c1 k max.r alpha\n" o9="Function: opt.power.LDD.p.CS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho budget c1 k max.r alpha\n" o10="Function: opt.power.LDD.p.DEX(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho theta budget c1 k max.r alpha\n" o11="Function: opt.power.LDD.p.RS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2w sigma20 sigma21 sigma01 budget c1 k max.r alpha\n" o12="Function: opt.power.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho rho.b1 rho01 r.tilde budget c1 k max.r alpha\n" o13="Function: opt.power.LDD.coef.CS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho budget c1 k max.r alpha\n" o14="Function: opt.power.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho theta budget c1 k max.r alpha\n" o15="Function: opt.power.LDD.coef.RS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2w sigma20 sigma21 sigma01 budget c1 k max.r alpha\n" o16="Function: opt.power.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho rho.b1 rho01 r.tilde budget c1 k max.r alpha\n" o17="Function: opt.power.tv.CMD.p.CS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2 rho budget c1 k max.r alpha\n" o18="Function: opt.power.tv.CMD.p.DEX(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2 rho theta budget c1 k max.r alpha\n" o19="Function: opt.power.tv.CMD.p.RS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2w sigma20 sigma21 sigma01 budget c1 k max.r alpha\n" o20="Function: opt.power.tv.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2 rho rho.b1 rho01 r.tilde budget c1 k max.r alpha\n" o21="Function: opt.power.tv.CMD.coef.CS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.cmd beta sigma2 rho budget c1 k max.r alpha\n" o22="Function: opt.power.tv.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.cmd beta sigma2 rho theta budget c1 k max.r alpha\n" o23="Function: opt.power.tv.CMD.coef.RS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.cmd beta sigma2w sigma20 sigma21 sigma01 budget c1 k max.r alpha\n" o24="Function: opt.power.tv.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.cmd beta sigma2 rho rho.b1 rho01 r.tilde budget c1 k max.r alpha\n" o25="Function: opt.power.tv.LDD.p.CS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2 rho budget c1 k max.r alpha\n" o26="Function: opt.power.tv.LDD.p.DEX(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2 rho theta budget c1 k max.r alpha\n" o27="Function: opt.power.tv.LDD.p.RS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2w sigma20 sigma21 sigma01 budget c1 k max.r alpha\n" o28="Function: opt.power.tv.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2 rho rho.b1 rho01 r.tilde budget c1 k max.r alpha\n" o29="Function: opt.power.tv.LDD.coef.CS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.ldd gamma3 sigma2 rho budget c1 k max.r alpha\n" o30="Function: opt.power.tv.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.ldd gamma3 sigma2 rho theta budget c1 k max.r alpha\n" o31="Function: opt.power.tv.LDD.coef.RS(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.ldd gamma3 sigma2w sigma20 sigma21 sigma01 budget c1 k max.r alpha\n" o32="Function: opt.power.tv.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: fixed s.or.tau pe rho.e model.ldd gamma3 sigma2 rho rho.b1 rho01 r.tilde budget c1 k max.r alpha\n" o33="Function: opt.cost.CMD.p.CS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho c1 k max.r alpha\n" o34="Function: opt.cost.CMD.p.DEX(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho theta c1 k max.r alpha\n" o35="Function: opt.cost.CMD.p.RS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2w sigma20 sigma21 sigma01 c1 k max.r alpha\n" o36="Function: opt.cost.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 sigma2 rho rho.b1 rho01 r.tilde c1 k max.r alpha\n" o37="Function: opt.cost.CMD.coef.CS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho c1 k max.r alpha\n" o38="Function: opt.cost.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho theta c1 k max.r alpha\n" o39="Function: opt.cost.CMD.coef.RS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2w sigma20 sigma21 sigma01 c1 k max.r alpha\n" o40="Function: opt.cost.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 beta sigma2 rho rho.b1 rho01 r.tilde c1 k max.r alpha\n" o41="Function: opt.cost.LDD.p.CS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho c1 k max.r alpha\n" o42="Function: opt.cost.LDD.p.DEX(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho theta c1 k max.r alpha\n" o43="Function: opt.cost.LDD.p.RS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2w sigma20 sigma21 sigma01 c1 k max.r alpha\n" o44="Function: opt.cost.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 mu00 p1 p2 p3 sigma2 rho rho.b1 rho01 r.tilde c1 k max.r alpha\n" o45="Function: opt.cost.LDD.coef.CS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho c1 k max.r alpha\n" o46="Function: opt.cost.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho theta c1 k max.r alpha\n" o47="Function: opt.cost.LDD.coef.RS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2w sigma20 sigma21 sigma01 c1 k max.r alpha\n" o48="Function: opt.cost.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe vt0 rho.exp.t0 gamma3 sigma2 rho rho.b1 rho01 r.tilde c1 k max.r alpha\n" o49="Function: opt.cost.tv.CMD.p.CS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2 rho c1 k max.r alpha\n" o50="Function: opt.cost.tv.CMD.p.DEX(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2 rho theta c1 k max.r alpha\n" o51="Function: opt.cost.tv.CMD.p.RS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2w sigma20 sigma21 sigma01 c1 k max.r alpha\n" o52="Function: opt.cost.tv.CMD.p.RS.reliab(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.cmd mu00 p1 sigma2 rho rho.b1 rho01 r.tilde c1 k max.r alpha\n" o53="Function: opt.cost.tv.CMD.coef.CS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.cmd beta sigma2 rho c1 k max.r alpha\n" o54="Function: opt.cost.tv.CMD.coef.DEX(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.cmd beta sigma2 rho theta c1 k max.r alpha\n" o55="Function: opt.cost.tv.CMD.coef.RS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.cmd beta sigma2w sigma20 sigma21 sigma01 c1 k max.r alpha\n" o56="Function: opt.cost.tv.CMD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.cmd beta sigma2 rho rho.b1 rho01 r.tilde c1 k max.r alpha\n" o57="Function: opt.cost.tv.LDD.p.CS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2 rho c1 k max.r alpha\n" o58="Function: opt.cost.tv.LDD.p.DEX(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2 rho theta c1 k max.r alpha\n" o59="Function: opt.cost.tv.LDD.p.RS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2w sigma20 sigma21 sigma01 c1 k max.r alpha\n" o60="Function: opt.cost.tv.LDD.p.RS.reliab(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.ldd mu00 p1 p2 p3 sigma2 rho rho.b1 rho01 r.tilde c1 k max.r alpha\n" o61="Function: opt.cost.tv.LDD.coef.CS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.ldd gamma3 sigma2 rho c1 k max.r alpha\n" o62="Function: opt.cost.tv.LDD.coef.DEX(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.ldd gamma3 sigma2 rho theta c1 k max.r alpha\n" o63="Function: opt.cost.tv.LDD.coef.RS(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.ldd gamma3 sigma2w sigma20 sigma21 sigma01 c1 k max.r alpha\n" o64="Function: opt.cost.tv.LDD.coef.RS.reliab(infile,outfile) The input file should contain the following columns: Pi fixed s.or.tau pe rho.e model.ldd gamma3 sigma2 rho rho.b1 rho01 r.tilde c1 k max.r alpha\n" # Inititalize quantity=1 tv=1 pattern=1 notation=1 correlation=1 notation.rs=1 finish=F while (finish==F) { cat("\n* By just pressing after each question, the default value, shown\n between square brackets, will be entered.\n\n") cat("* Press to quit\n\n") quantity=get.quantity(quantity) if (quantity==1) { # power tv=get.tv(tv) pattern=get.pattern(pattern) notation=get.notation(notation) correlation=get.correlation(correlation) if (correlation==3) notation.rs=get.notation.rs(notation.rs) if (tv==1) { if (pattern==1) { if (notation==2) { if (correlation==1) { message=P1 } else if (correlation==2) { message=P2 } else { # RS if (notation.rs==1) { message=P3 } else { message=P4 } } # end correlation } else { # notation=2 if (correlation==1) { message=P5 } else if (correlation==2) { message=P6 } else { # RS if (notation.rs==1) { message=P7 } else { message=P8 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=P9 } else if (correlation==2) { message=P10 } else { # RS if (notation.rs==1) { message=P11 } else { message=P12 } } # end correlation } else { # notation=2 if (correlation==1) { message=P13 } else if (correlation==2) { message=P14 } else { # RS if (notation.rs==1) { message=P15 } else { message=P16 } } # end correlation } # end notation } # end pattern } else { # tv=2 if (pattern==1) { if (notation==2) { if (correlation==1) { message=P17 } else if (correlation==2) { message=P18 } else { # RS if (notation.rs==1) { message=P19 } else { message=P20 } } # end correlation } else { # notation=2 if (correlation==1) { message=P21 } else if (correlation==2) { message=P22 } else { # RS if (notation.rs==1) { message=P23 } else { message=P24 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=P25 } else if (correlation==2) { message=P26 } else { # RS if (notation.rs==1) { message=P27 } else { message=P28 } } # end correlation } else { # notation=2 if (correlation==1) { message=P29 } else if (correlation==2) { message=P30 } else { # RS if (notation.rs==1) { message=P31 } else { message=P32 } } # end correlation } # end notation } # end pattern } # end tv } else if (quantity==2) { # N tv=get.tv(tv) pattern=get.pattern(pattern) notation=get.notation(notation) correlation=get.correlation(correlation) if (correlation==3) notation.rs=get.notation.rs(notation.rs) if (tv==1) { if (pattern==1) { if (notation==2) { if (correlation==1) { message=N1 } else if (correlation==2) { message=N2 } else { # RS if (notation.rs==1) { message=N3 } else { message=N4 } } # end correlation } else { # notation=2 if (correlation==1) { message=N5 } else if (correlation==2) { message=N6 } else { # RS if (notation.rs==1) { message=N7 } else { message=N8 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=N9 } else if (correlation==2) { message=N10 } else { # RS if (notation.rs==1) { message=N11 } else { message=N12 } } # end correlation } else { # notation=2 if (correlation==1) { message=N13 } else if (correlation==2) { message=N14 } else { # RS if (notation.rs==1) { message=N15 } else { message=N16 } } # end correlation } # end notation } # end pattern } else { # tv=2 if (pattern==1) { if (notation==2) { if (correlation==1) { message=N17 } else if (correlation==2) { message=N18 } else { # RS if (notation.rs==1) { message=N19 } else { message=N20 } } # end correlation } else { # notation=2 if (correlation==1) { message=N21 } else if (correlation==2) { message=N22 } else { # RS if (notation.rs==1) { message=N23 } else { message=N24 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=N25 } else if (correlation==2) { message=N26 } else { # RS if (notation.rs==1) { message=N27 } else { message=N28 } } # end correlation } else { # notation=2 if (correlation==1) { message=N29 } else if (correlation==2) { message=N30 } else { # RS if (notation.rs==1) { message=N31 } else { message=N32 } } # end correlation } # end notation } # end pattern } # end tv } else if (quantity==3) { # e tv=get.tv(tv) pattern=get.pattern(pattern) notation=get.notation2(notation) correlation=get.correlation(correlation) if (correlation==3) notation.rs=get.notation.rs(notation.rs) if (tv==1) { if (pattern==1) { if (notation==2) { if (correlation==1) { message=E1 } else if (correlation==2) { message=E2 } else { # RS if (notation.rs==1) { message=E3 } else { message=E4 } } # end correlation } else { # notation=2 if (correlation==1) { message=E5 } else if (correlation==2) { message=E6 } else { # RS if (notation.rs==1) { message=E7 } else { message=E8 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=E9 } else if (correlation==2) { message=E10 } else { # RS if (notation.rs==1) { message=E11 } else { message=E12 } } # end correlation } else { # notation=2 if (correlation==1) { message=E13 } else if (correlation==2) { message=E14 } else { # RS if (notation.rs==1) { message=E15 } else { message=E16 } } # end correlation } # end notation } # end pattern } else { # tv=2 if (pattern==1) { if (notation==2) { if (correlation==1) { message=E17 } else if (correlation==2) { message=E18 } else { # RS if (notation.rs==1) { message=E19 } else { message=E20 } } # end correlation } else { # notation=2 if (correlation==1) { message=E21 } else if (correlation==2) { message=E22 } else { # RS if (notation.rs==1) { message=E23 } else { message=E24 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=E25 } else if (correlation==2) { message=E26 } else { # RS if (notation.rs==1) { message=E27 } else { message=E28 } } # end correlation } else { # notation=2 if (correlation==1) { message=E29 } else if (correlation==2) { message=E30 } else { # RS if (notation.rs==1) { message=E31 } else { message=E32 } } # end correlation } # end notation } # end pattern } # end tv } else if (quantity==4) { # r tv=get.tv(tv) pattern=get.pattern(pattern) notation=get.notation(notation) correlation=get.correlation(correlation) if (correlation==3) notation.rs=get.notation.rs(notation.rs) if (tv==1) { if (pattern==1) { if (notation==2) { if (correlation==1) { message=r1 } else if (correlation==2) { message=r2 } else { # RS if (notation.rs==1) { message=r3 } else { message=r4 } } # end correlation } else { # notation=2 if (correlation==1) { message=r5 } else if (correlation==2) { message=r6 } else { # RS if (notation.rs==1) { message=r7 } else { message=r8 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=r9 } else if (correlation==2) { message=r10 } else { # RS if (notation.rs==1) { message=r11 } else { message=r12 } } # end correlation } else { # notation=2 if (correlation==1) { message=r13 } else if (correlation==2) { message=r14 } else { # RS if (notation.rs==1) { message=r15 } else { message=r16 } } # end correlation } # end notation } # end pattern } else { # tv=2 if (pattern==1) { if (notation==2) { if (correlation==1) { message=r17 } else if (correlation==2) { message=r18 } else { # RS if (notation.rs==1) { message=r19 } else { message=r20 } } # end correlation } else { # notation=2 if (correlation==1) { message=r21 } else if (correlation==2) { message=r22 } else { # RS if (notation.rs==1) { message=r23 } else { message=r24 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=r25 } else if (correlation==2) { message=r26 } else { # RS if (notation.rs==1) { message=r27 } else { message=r28 } } # end correlation } else { # notation=2 if (correlation==1) { message=r29 } else if (correlation==2) { message=r30 } else { # RS if (notation.rs==1) { message=r31 } else { message=r32 } } # end correlation } # end notation } # end pattern } # end tv } else if (quantity==5) { # (N,r) cost constr tv=get.tv(tv) pattern=get.pattern(pattern) notation=get.notation(notation) correlation=get.correlation(correlation) if (correlation==3) notation.rs=get.notation.rs(notation.rs) if (tv==1) { if (pattern==1) { if (notation==2) { if (correlation==1) { message=o1 } else if (correlation==2) { message=o2 } else { # RS if (notation.rs==1) { message=o3 } else { message=o4 } } # end correlation } else { # notation=2 if (correlation==1) { message=o5 } else if (correlation==2) { message=o6 } else { # RS if (notation.rs==1) { message=o7 } else { message=o8 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=o9 } else if (correlation==2) { message=o10 } else { # RS if (notation.rs==1) { message=o11 } else { message=o12 } } # end correlation } else { # notation=2 if (correlation==1) { message=o13 } else if (correlation==2) { message=o14 } else { # RS if (notation.rs==1) { message=o15 } else { message=o16 } } # end correlation } # end notation } # end pattern } else { # tv=2 if (pattern==1) { if (notation==2) { if (correlation==1) { message=o17 } else if (correlation==2) { message=o18 } else { # RS if (notation.rs==1) { message=o19 } else { message=o20 } } # end correlation } else { # notation=2 if (correlation==1) { message=o21 } else if (correlation==2) { message=o22 } else { # RS if (notation.rs==1) { message=o23 } else { message=o24 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=o25 } else if (correlation==2) { message=o26 } else { # RS if (notation.rs==1) { message=o27 } else { message=o28 } } # end correlation } else { # notation=2 if (correlation==1) { message=o29 } else if (correlation==2) { message=o30 } else { # RS if (notation.rs==1) { message=o31 } else { message=o32 } } # end correlation } # end notation } # end pattern } # end tv } else { # (N,r) power constr tv=get.tv(tv) pattern=get.pattern(pattern) notation=get.notation(notation) correlation=get.correlation(correlation) if (correlation==3) notation.rs=get.notation.rs(notation.rs) if (tv==1) { if (pattern==1) { if (notation==2) { if (correlation==1) { message=o33 } else if (correlation==2) { message=o34 } else { # RS if (notation.rs==1) { message=o35 } else { message=o36 } } # end correlation } else { # notation=2 if (correlation==1) { message=o37 } else if (correlation==2) { message=o38 } else { # RS if (notation.rs==1) { message=o39 } else { message=o40 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=o41 } else if (correlation==2) { message=o42 } else { # RS if (notation.rs==1) { message=o43 } else { message=o44 } } # end correlation } else { # notation=2 if (correlation==1) { message=o45 } else if (correlation==2) { message=o46 } else { # RS if (notation.rs==1) { message=o47 } else { message=o48 } } # end correlation } # end notation } # end pattern } else { # tv=2 if (pattern==1) { if (notation==2) { if (correlation==1) { message=o49 } else if (correlation==2) { message=o50 } else { # RS if (notation.rs==1) { message=o51 } else { message=o52 } } # end correlation } else { # notation=2 if (correlation==1) { message=o53 } else if (correlation==2) { message=o54 } else { # RS if (notation.rs==1) { message=o55 } else { message=o56 } } # end correlation } # end notation } else { # pattern=2 if (notation==2) { if (correlation==1) { message=o57 } else if (correlation==2) { message=o58 } else { # RS if (notation.rs==1) { message=o59 } else { message=o60 } } # end correlation } else { # notation=2 if (correlation==1) { message=o61 } else if (correlation==2) { message=o62 } else { # RS if (notation.rs==1) { message=o63 } else { message=o64 } } # end correlation } # end notation } # end pattern } # end tv } # end quantity cat(message) cat("\n") finish=get.finish() } # end while }