program define ciscalc version 4.0 preserve clear global C1_1 "Case 1: Mean of normal, sigma^2 known: Give n, sigma^2, xbar." wdctl static C1_1 5 5 260 8 global C1_2 "Case 2: Mean of normal, sigma^2 unknown: Give n, s^2, xbar." wdctl static C1_2 5 13 260 8 global C1_3 "Case 3: Mean of nonnormal, sigma^2 unknown but n large: Give n, s^2, xbar." wdctl static C1_3 5 21 260 8 global C1_4 "Case 4: Variance of normal: Give n, s^2." wdctl static C1_4 5 29 260 8 global C1_5 "Case 5: 0-1 proportion pi (exact): Give n and p." wdctl static C1_5 5 37 260 8 global C1_6 "Case 6: 0-1 proportion pi (approximate): Give n and p." wdctl static C1_6 5 45 260 8 global C1_7 "Case 7: Ratio of normal variances: Give n1, n2, s1^2, s2^2." wdctl static C1_7 5 53 260 8 global C1_8 "Case 8: Difference of normal means, independent samples, variances equal: Give n1, n2, s1^2, s2^2, xbar1, xbar2." wdctl static C1_8 5 61 260 16 global C1_9 "Case 9: Difference of normal means, independent samples, variances unequal: Give n1, n2, s1^2, s2^2, xbar1, xbar2." wdctl static C1_9 5 77 260 16 global C1_10 "Case 10: Mean of difference in paired data: Give n (# of pairs), s^2 for differences in pairs, xbar=mean of pair differences." wdctl static C1_10 5 93 260 16 global C1_11 "Case 11: Difference of proportions pi1-pi2: Give n1, n2, p1, p2." wdctl static C1_11 5 109 260 8 global D1_1 "CI for Mean of normal, sigma known:" global D1_2 "CI for Mean of normal, sigma unknown:" global D1_3 "CI for Mean of nonnormal, sigma unknown but n large:" global D1_4 "CI for Variance of normal:" global D1_5 "CI for 0-1 proportion pi (exact):" global D1_6 "CI for 0-1 proportion pi (approximate):" global D1_7 "CI for Ratio of normal variances:" global D1_8 "CI for Difference of normal means, independent samples, variances equal:" global D1_9 "CI for Difference of normal means, independent samples, variances unequal:" global D1_10 "CI for Mean of difference in paired data:" global D1_11 "CI for Difference of proportions pi1-pi2:" global C_1 "Case" global C_3 "1 2 3 4 5 6 7 8 9 10 11" wdctl static C_1 270 5 20 10 global C_2 "1" wdctl ssimple C_2 C_3 270 15 20 110 global D_alpha "alpha" wdctl static D_alpha 5 125 18 8 global alpha=.05 wdctl edit alpha 25 125 18 8 global D_n "n" wdctl static D_n 45 125 18 8 global n=0 wdctl edit n 65 125 18 8 global D_xbar "xbar" wdctl static D_xbar 85 125 18 8 global xbar=0 wdctl edit xbar 105 125 18 8 global D_sigma2 "sig^2" wdctl static D_sigma2 125 125 18 8 global sigma2=0 wdctl edit sigma2 145 125 18 8 global D_s2 "s^2" wdctl static D_s2 165 125 18 8 global s2=0 wdctl edit s2 185 125 18 8 global D_p "p" wdctl static D_p 205 125 18 8 global p=0 wdctl edit p 225 125 18 8 global D_n1 "n1" wdctl static D_n1 5 135 18 8 global n1=0 wdctl edit n1 25 135 18 8 global D_n2 "n2" wdctl static D_n2 45 135 18 8 global n2=0 wdctl edit n2 65 135 18 8 global D_xbar1 "xbar1" wdctl static D_xbar1 85 135 18 8 global xbar1=0 wdctl edit xbar1 105 135 18 8 global D_xbar2 "xbar2" wdctl static D_xbar2 125 135 18 8 global xbar2=0 wdctl edit xbar2 145 135 18 8 global D_s12 "s1^2" wdctl static D_s12 165 135 18 8 global s12=0 wdctl edit s12 185 135 18 8 global D_s22 "s2^2" wdctl static D_s22 205 135 18 8 global s22=0 wdctl edit s22 225 135 18 8 global D_p1 "p1" wdctl static D_p1 5 145 18 8 global p1=0 wdctl edit p1 25 145 18 8 global D_p2 "p2" wdctl static D_p2 45 145 18 8 global p2=0 wdctl edit p2 65 145 18 8 wdctl button "Run" 5 160 30 14 D_b1 wdctl button "Close" 40 160 30 14 D_b2 wdctl button "Help" 75 160 30 14 D_b3 help global D_b1 "ciscaldr" global D_b2 "exit 1234" global D_b3 "whelp cis" cap noi wdlg "Confidence Intervals" $D_dlgx $D_dlgy 300 200 restore end program define ciscaldr version 4.0 /* Put Stuff from Dialog Boxes into Local Macros: */ if $alpha<=0 | $alpha >=.5 { sstopbox stop "alpha must be in (0,.5)" exit} local case=$C_2 if `case'==1 { if $n < 1 { sstopbox stop "n must be at least 1" exit} if $sigma2 <= 0 { sstopbox stop "sigma^2 must be positive" exit} if $xbar==0 { sstopbox stop "you must give xbar" exit} local alpha1: display %6.3f 100*(1-$alpha) di " " di `alpha1' "% " "$D1_1" di "n = " $n ", sigma^2 = " $sigma2 ", xbar = " $xbar local zas=invnorm(1-$alpha/2)*sqrt($sigma2/$n) local ll=$xbar-`zas' local lu=$xbar+`zas'} if `case'==2 | `case'==3{ if $n < 1 { sstopbox stop "n must be at least 1" exit} if $s2 <= 0 { sstopbox stop "s^2 must be positive" exit} if $xbar==0 { sstopbox stop "you must give xbar" exit} local alpha1: display %6.3f 100*(1-$alpha) di " " di `alpha1' "% " "$D1_2" di "n = " $n ", s^2 = " $s2 ", xbar = " $xbar local tas=invt($n-1,1-$alpha)*sqrt($s2/$n) local ll=$xbar-`tas' local lu=$xbar+`tas'} if `case'==4 { if $n < 1 { sstopbox stop "n must be at least 1" exit} if $s2 <= 0 { sstopbox stop "s^2 must be positive" exit} local alpha1: display %6.3f 100*(1-$alpha) di " " di `alpha1' "% " "$D1_4" di "n = " $n ", s^2 = " $s2 local chiu=invnchi($n-1,0,$alpha/2) local chil=invnchi($n-1,0,1-($alpha/2)) local ll=($n-1)*$s2/`chil' local lu=($n-1)*$s2/`chiu'} if `case'==5 { if $n < 1 { sstopbox stop "n must be at least 1" exit} if $p <= 0 | $p >= 1{ sstopbox stop "p must be between 0 and 1" exit} local alpha1: display %6.3f 100*(1-$alpha) di " " di `alpha1' "% " "$D1_5" local px = int($n*$p+.5) di "n = " $n ", p = " $p ", X = " `px' local df1=int(2*`px') local df2=int(2*($n-`px'+1)) local f1 = invfprob(`df1',`df2',1-$alpha/2) local ll=(`px'*`f1')/(($n-`px'+1)+`px'*`f1') local df1=`df1'+2 local df2=`df2'-2 local f1 = invfprob(`df1',`df2',$alpha/2) local lu=((`px'+1)*`f1')/(($n-`px')+(`px'+1)*`f1')} if `case'==6 { if $n < 1 { sstopbox stop "n must be at least 1" exit} if $p<=0 | $p>=1 { sstopbox stop "p must be between 0 and 1" exit} local alpha1: display %6.3f 100*(1-$alpha) di " " di `alpha1' "% " "$D1_6" di "n = " $n ", p = " $p local zas=invnorm(1-$alpha/2)*sqrt($p*(1-$p)/$n) local ll=$p-`zas' local lu=$p+`zas'} if `case'==7 { if $n1 < 1 | $n2 < 1 { sstopbox stop "n1 and n2 must be at least 1" exit} if $s12<=0 | $s22<=0 { sstopbox stop "s1^2 and s2^2 must be positive" exit} local alpha1: display %6.3f 100*(1-$alpha) di " " di `alpha1' "% " "$D1_7" di "n1 = " $n1 ", n2 = " $n2 ", s1^2 = " $s12 ", s2^2 = " $s22 local fu=invfprob($n1-1,$n2-1,$alpha/2) local fl=invfprob($n1-1,$n2-1,1-($alpha/2)) local ll=($s12/$s22)/`fu' local lu=($s12/$s22)/`fl'} if `case'==8 { if $n1 < 1 | $n2 < 1 { sstopbox stop "n1 and n2 must be at least 1" exit} if $xbar1==0 | $xbar2==0 { sstopbox stop "you must specify xbar1 and xbar2" exit} if $s12<=0 | $s22<=0 { sstopbox stop "s1^2 and s2^2 must be positive" exit} local alpha1: display %6.3f 100*(1-$alpha) di " " di `alpha1' "% " "$D1_8" di "n1 = " $n1 ", n2 = " $n2 ", xbar1 = " $xbar1 ", xbar2 = " $xbar2 ", s1^2 = " $s12 ", s2^2 = " $s22 local s2p=(($n1-1)*$s12+($n2-1)*$s22)/($n1+$n2-2) local tas=invt($n1+$n2-2,1-$alpha)*sqrt(`s2p'*((1/$n1)+(1/$n2))) local ll=($xbar1-$xbar2)-`tas' local lu=($xbar1-$xbar2)+`tas'} if `case'==9 { if $n1 < 1 | $n2 < 1 { sstopbox stop "n1 and n2 must be at least 1" exit} if $xbar1==0 | $xbar2==0 { sstopbox stop "you must specify xbar1 and xbar2" exit} if $s12<=0 | $s22<=0 { sstopbox stop "s1^2 and s2^2 must be positive" exit} local alpha1: display %6.3f 100*(1-$alpha) di " " di `alpha1' "% " "$D1_9" local dfn=(($s12/$n1)+($s22/$n2))^2 local dfd=(($s12/$n1)^2/($n1-1))+(($s22/$n2)^2/($n2-1)) local df=int((`dfn'/`dfd')+.5) di "n1 = " $n1 ", n2 = " $n2 ", xbar1 = " $xbar1 ", xbar2 = " $xbar2 ", s1^2 = " $s12 ", s2^2 = " $s22 ", df = " `df' local s2p=(($n1-1)*$s12+($n2-1)*$s22)/($n1+$n2-2) local tas=invt(`df',1-$alpha)*sqrt(($s12/$n1)+($s22/$n2)) local ll=($xbar1-$xbar2)-`tas' local lu=($xbar1-$xbar2)+`tas'} if `case'==10 { if $n < 1 { sstopbox stop "n must be at least 1" exit} if $s2 <= 0 { sstopbox stop "s^2 must be positive" exit} if $xbar==0 { sstopbox stop "you must give xbar" exit} local alpha1: display %6.3f 100*(1-$alpha) di " " di `alpha1' "% " "$D1_10" di "n = " $n ", s^2 = " $s2 ", xbar = " $xbar local tas=invt($n-1,1-$alpha)*sqrt($s2/$n) local ll=$xbar-`tas' local lu=$xbar+`tas'} if `case'==11 { if $n1 < 1 | $n2 < 1{ sstopbox stop "n1 and n2 must be at least 1" exit} if $p1 <= 0 | $p1 >= 1 | $p2 <= 0 | $p2 >= 1 { sstopbox stop "p1 and p2 must both be between 0 and 1" exit} local alpha1: display %6.3f 100*(1-$alpha) di " " di `alpha1' "% " "$D1_11" di "n1 = " $n1 ", n2 = " $n2 ", p1 = " $p1 ", p2 = " $p2 local zas=invnorm(1-$alpha/2)*sqrt(($p1*(1-$p1)/$n1)+($p2*(1-$p2)/$n2)) local ll=($p1-$p2) - `zas' local lu=($p1-$p2)+`zas'} * local ll1: display %10.4f `ll' * local lu1: display %10.4f `lu' di "Lower Limit = " `ll' " di "Upper Limit = " `lu' di " " end exit