#delim ; * Certification script for -multproc- and -smileplot- *; * Begin certification script *; cscript "Certification of multproc and smileplot" adofiles multproc smileplot; * Input the sequence of P-values and calculated cut-offs from: Benjamini Y, Krieger A, Yekutieli D. Two-staged linear step up FDR controlling procedure. Downloadable from http://www.math.tau.ac.il/~ybenja/. *; clear; #delim cr; input prank p cutoff1 cutoff2 1 .006 .005 .00625 2 .009 .010 .01250 3 .018 .015 .01875 4 .028 .020 .02500 5 .030 .025 .03125 6 .045 .030 .03750 7 .150 .035 .04375 8 .430 .040 .05000 9 .625 .045 .05625 10 .810 .050 .06250 end #delim ; lab var prank "Rank of p-value"; lab var p "p-value"; lab var cutoff1 "Cutoff First Stage"; lab var cutoff2 "Cutoff Second Stage"; format p cutoff1 %8.3f;format cutoff2 %8.5f; desc; list; * Define fantasy estimate for smile plots *; gene estimate=invnorm(1-p/2)*(2*mod(_n,2)-1); * All methods *; * Error capture *; cap noi multproc,me(bogus); assert _rc==498; cap noi multproc,punc(-1); assert _rc==498; cap noi multproc,punc(1.5); assert _rc==498; cap noi multproc,pc(-1); assert _rc==498; cap noi multproc,pc(1.5); assert _rc==498; multproc,pc(0.005); for M in any bonferroni sidak holm holland liu1 liu2 hochberg rom simes yekutieli krieger: smileplot,me(M) t1("Smile plot for method(M)") \ more; * P-plots and trivial validations *; for M in any bonferroni sidak holm holland liu1 liu2 hochberg rom simes yekutieli krieger: multproc,me(M) ra(rank) cr(pc_M) nh(nhcred) rej(nhrej) \ assert nhrej==!nhcred \ graph7 p pc_M rank,s(O.) c(.L) xlab ylab t1("P-plot for method(M)") \ more \ drop rank nhcred nhrej; assert pc_bonferroni1; assert pc_bonferroni==pc_holm if prank==1; assert pc_sidak1; assert pc_sidak==pc_holland if prank==1; assert pc_yekutielipc_simes; for M in any bonferroni sidak:summ pc_M \ assert r(min)==r(max); for M in any holm holland liu1 liu2 hochberg rom simes yekutieli krieger: summ pc_M \ assert 050"; lab def prgp 1 "<10" 2 ">10"; lab val agegp agegp;lab val prgp prgp; lab var pval "P-value"; lab var pcliu1_10 "Liu (1999a) 10% cutoff"; lab var pcliu1_05 "Liu (1999a) 5% cutoff"; desc; list; * Liu (1999a) procedure at 10% level *; multproc,pv(pval) me(liu1) cr(cu1) ra(ra1) nh(nh1) rej(rj1) punc(0.10); format cu1 %8.4f; gene rd1=reldif(pcliu1_10,cu1); assert rd1<=1e-4; count if nh1; assert r(N)==1; assert nh1==1-rj1; list agegp prgp ra1 pval pcliu1_10 cu1 rd1 nh1 rj1; graph7 cu1 pcliu1_10;more; * Liu (1999a) procedure at 5% level *; multproc,pv(pval) me(liu1) cr(cu2) ra(ra2) nh(nh2) rej(rj2) punc(0.05); format cu2 %8.4f; gene rd2=reldif(pcliu1_05,cu2); assert rd2<=1e-4; count if nh2; assert r(N)==3; assert nh2==1-rj2; list agegp prgp ra2 pval pcliu1_05 cu2 rd2 nh2 rj2; graph7 cu2 pcliu1_05;more; /* Demonstrate the argument of: Holm, S. A Simple Sequentially Rejective Multiple Test Procedure. Scandinavian Journal of Statistics 1979; 6: 65-70. */ clear; #delim cr; input refdunt seqbont 1.70 1.70 1.99 2.04 2.15 2.23 2.25 2.36 2.33 2.46 2.40 2.54 2.45 2.60 2.50 2.66 2.54 2.71 end #delim ; gsort -refdunt; gene refdunp=ttail(30,refdunt)*2; gene seqbonp=ttail(30,seqbont)*2; lab var refdunt "Refined Dunnett t"; lab var refdunp "Refined Dunnett P"; lab var seqbont "Sequential Bonferroni t"; lab var seqbonp "Sequential Bonferroni P"; format refdunt seqbont %8.2f; format refdunp seqbonp %9.2e; desc; list; gene p=0.1*_n/_N; * Compare Holm procedure with seqbonp *; multproc,method(holm) punc(0.1) cr(holmp); format holmp %9.2e; gene holmrd=reldif(holmp,seqbonp); assert holmrd<=1e-3; desc; list; graph7 holmp seqbonp seqbonp,s(o.) c(.L);more; * Compare Holland-Copenhaver procedure with refdunp *; multproc,method(holland) punc(0.1) cr(hollp); format hollp %9.2e; gene hollrd=reldif(hollp,refdunp); assert holmrd<=1e-2; desc; list; graph7 hollp refdunp refdunp,s(o.) c(.L);more; * Show that -by varlist:- works *; clear; local nbygp=20; set obs `nbygp'; set seed 9876543210; * True mean SND *; local trumu=1; expgen npinbygp=(_n*(_n+1))/2,oldseq(bygp) copyseq(pvseq); lab var npinbygp "N of P-values in by-group"; lab var bygp "By-group"; lab var pvseq "P-value sequence within by-group"; sort bygp pvseq; gene double ranexp=`trumu'*0.5*invchi2(2,uniform()); gene double rangau=invnorm(uniform()); gene double ranmix=rangau+ranexp; gene double pvalmix=1-norm(ranmix); lab var ranexp "Random exponential(mu=`trumu') deviate"; lab var rangau "Random Gaussian(0,1) deviate"; lab var ranmix "Random deviate from mixture distribution"; lab var pvalmix "P-value for testing mu=0"; desc; for X in var ranexp rangau ranmix pvalmix:graph7 X,xlabel freq bin(20) \ more; * Show that the -saving- option of -smileplot- works as it should (ie not in presence of -by varlist:- but in absence of -by varlist:-) *; tempfile tf0; conf new file `tf0'; smileplot,pv(pvalmix) est(ranmix) meth(simes) t1(" ") saving(`tf0',replace); conf file `tf0'; graph use `tf0'; erase `tf0'; conf new file `tf0'; by bygp,rc0:smileplot,pv(pvalmix) est(ranmix) meth(simes) t1(" ") saving(`tf0',replace); conf new file `tf0'; * Show that -by varlist:- works in the absence of -saving- *; foreach M in bonferroni sidak holm holland liu1 liu2 hochberg rom simes yekutieli krieger {; disp _n as text "Analysis using by-groups with method: " as result "`M'"; by bygp:multproc,pv(pvalmix) me(`M') rank(rank_`M') gpunc(gpunc_`M') gpcor(gpcor_`M') crit(crit_`M') rej(rej_`M') nh(nh_`M'); savedresults save lastby r(); assert inlist(rej_`M',0,1);assert inlist(nh_`M',0,1); assert rej_`M'==1-nh_`M'; disp _n as text "Analysis using if-groups with method: " as result "`M'"; forv i1=1(1)`nbygp' {; multproc if bygp==`i1',pv(pvalmix) me(`M') rank(rank) gpunc(gpunc) gpcor(gpcor) crit(crit) rej(rej) nh(nh); if `i1'==`nbygp' {; disp _n as text "Comparing saved results of last if-group with saved results from last by-group:"; savedresults compare lastby r(),verbose; }; foreach X of var rank gpunc gpcor crit rej nh {; assert `X'==`X'_`M' if bygp==`i1'; assert `X'==. if bygp!=`i1'; }; drop rank gpunc gpcor crit rej nh; }; disp _n as text "Repeat the analysis using the -gpcuncor- and -gpcor- variables"; by bygp,rc0:smileplot,pv(pvalmix) est(ranmix) punc(gpunc_`M') pcor(gpcor_`M') me(`M') rank(rank) gpunc(gpunc) gpcor(gpcor) crit(crit) rej(rej) nh(nh); foreach X of var rank gpunc gpcor rej nh {; assert `X'==`X'_`M'; }; assert crit==gpcor; drop rank gpunc gpcor crit rej nh; savedresults drop lastby; }; exit;