program define crit version 4.0 preserve /* Save all the current stata stuff */ clear /* Clear everything so no conflicts */ quietly{ set obs 501 gen x=. gen y=. gen x1=. gen y1=. gen zer=0} global D_sm11 " This lab graphically illustrates the idea of critical value(s) for confidence intervals and tests of hypotheses using the Z, t, chi-square, and F distributions." wdctl static D_sm11 5 5 290 15 global D_sm12 " You specify 1) which distribution to study, 2) what type of test to study (two-sided, left-sided, or right-sided), 3) which of four alpha's to use, and 4) what degrees of freedom to use (for t and chi-square) or numerator and denominator degrees of freedom to use (for F). When you then click on Run, the graph of the chosen distribution is placed on the screen with areas under the curve specified by alpha shaded in and the critical value(s) written next to the shaded areas." wdctl static D_sm12 5 25 290 50 global D_sm13 " Suggestions: 1) run the lab several times varying only alpha and note what happens to the shaded areas and critical values, 2) run the lab for the t, increasing the degrees of freedom each time." wdctl static D_sm13 5 75 290 35 global D_sm1 "df_1" global HJN_V1=20 wdctl static D_sm1 5 120 15 10 wdctl edit HJN_V1 25 120 20 10 global D_sm2 "df_2" global HJN_V2=20 wdctl static D_sm2 45 120 15 10 wdctl edit HJN_V2 65 120 20 10 global D_sm3 "Type" global D_sm4 "Right-Tailed Left-Tailed Two-Tailed" wdctl static D_sm3 120 110 20 10 global D_var3 "Two-Tailed" wdctl ssimple D_var3 D_sm4 120 120 60 40 global D_sm6 "alpha" global D_sm7 ".01 .025 .05 .10" wdctl static D_sm6 190 110 20 10 global D_var1 ".05" wdctl ssimple D_var1 D_sm7 190 120 30 48 global D_sm8 "Distribution" global D_sm9 "Z t Chi-square F" wdctl static D_sm8 230 110 45 10 global D_var2 "Z" wdctl ssimple D_var2 D_sm9 230 120 55 50 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 "critdr" global D_b2 "exit 1234" global D_b3 "whelp crit" cap noi wdlg "Critical Values" $D_dlgx $D_dlgy 300 240 restore end program define critdr version 4.0 gph open gph pen 1 local df1=$HJN_V1 local df2=$HJN_V2 local side = 0 if "$D_var3"=="Left-Tailed" {local side=-1} if "$D_var3"=="Right-Tailed" {local side=1} local alpha = $D_var1 if `alpha' <=0 | `alpha' >= 1 { sstopbox stop "alpha must be between 0 and 1" exit} if "$D_var2"=="Z" { local xmin=invnorm(.001) local xmax=invnorm(.999) replace x=`xmin' + (`xmax'-`xmin')*(_n-1)/500 replace y=exp(-(x^2)/2.)/sqrt(2.*_pi)} if "$D_var2"=="t" { if `df1' < 2 | `df1' > 1000 { sstopbox stop "df must be between 2 and 1000" exit} local xmin=-invt(`df1',.998) local xmax=-`xmin' replace x=`xmin' + (`xmax'-`xmin')*(_n-1)/500 pdf_t x y `df1'} if "$D_var2"=="Chi-square" { if `df1' < 2 | `df1' > 200 { sstopbox stop "df must be between 2 and 200" exit} local xmin=invnchi(`df1',0,.001) local xmax=invnchi(`df1',0,.999) replace x=`xmin' + (`xmax'-`xmin')*(_n-1)/500 pdf_chi2 x y `df1'} if "$D_var2"=="F" { if `df1' < 2 | `df1' > 1000 { sstopbox "numerator df must be between 2 and 1000" exit} if `df2' < 2 | `df2' > 1000 { sstopbox "denominator df must be between 2 and 1000" exit} local xmin=invfprob(`df1',`df2',.001) local xmin=0. local xmax=invfprob(`df1',`df2',.001) replace x=`xmin' + (`xmax'-`xmin')*(_n-1)/500 pdf_f x y `df1' `df2'} graph y x, c(l) s(.) xlab ylab pen(3) gphconv local alp = `alpha' if `side'==0 {local alp = `alpha'/2} if "$D_var2"=="Z" { gph text 500 16000 0 0 Z Distribution, alpha=`alpha' local critr=invnorm(1.-`alp') local critl=-`critr'} if "$D_var2"=="t" { gph text 500 16000 0 0 t Distribution with df=`df1', alpha=`alpha' local critr=invt(`df1',1.-2*`alp') local critl=-`critr'} if "$D_var2"=="Chi-square" { gph text 500 16000 0 0 Chi-square Distribution with df=`df1', alpha=`alpha' local critr=invnchi(`df1',0,1.-`alp') local critl=invnchi(`df1',0,`alp')} if "$D_var2"=="F" { gph text 500 16000 0 0 F Distribution with df=`df1',`df2', alpha=`alpha' local critr=invfprob(`df1',`df2',`alp') local critl=invfprob(`df1',`df2',1.-`alp')} local mcl: display %6.3f `critl' local mcr: display %6.3f `critr' gph pen 2 if `side'==0 | `side'==-1 { replace x1=. replace y1=. replace y1=y if x < `critl' replace x1=x if x < `critl' segments x1 zer x1 y1 drtext `critl' 0 -1 `mcl'} if `side'==0 | `side'==1 { replace x1=. replace y1=. replace y1=y if x > `critr' replace x1=x if x > `critr' segments x1 zer x1 y1 drtext `critr' 0 1 `mcr'} gph pen 3 lines x y * lines x zer * gph text 2000 16000 0 0 `mcl' `mcr' gph close end exit