program define onebw version 4.0 preserve clear quietly { set obs 600 gen x = . gen y = .} global sig=1 global D_sm12 " This lab illustrates how the F test for comparing means depends on how much variation there is between the samples and how much there is within the samples." wdctl static D_sm12 5 5 300 16 global D_sm13 " The lab repeatedly gets four samples for two situations: 1) True means 17, 22, 17, and 22 and 2) True means 20, 20, 20, 20. You specify two things: 1) n=individual sample sizes, 2) sigma=standard deviations of the populations (sigma assumed the same for all populations). For a sample, the lab plots the data points and box plots and then finds the F statistics and p-values." wdctl static D_sm13 5 25 300 48 global D_sm14 " Things to note: 1) As sigma increases, the F test has trouble telling that the unequal means are in fact different (you can see this both graphically as the variability within samples gets bigger than the variability between samples and by the p-values which tend to get larger), 2) Increasing n allows the F test to tell the top means are different." wdctl static D_sm14 5 70 300 48 wdctl button "Sample" 60 120 30 12 HJN_B0 wdctl button "sigma +" 95 120 30 12 HJN_B1 wdctl button "sigma -" 130 120 30 12 HJN_B2 wdctl button "Help" 165 120 30 12 HJN_B5 wdctl button "Close" 200 120 30 12 HJN_B6 global D_sm1 "n" global HJN_V1=10 wdctl static D_sm1 5 120 15 10 wdctl edit HJN_V1 25 120 15 10 global HJN_B0 "onebwdr 0" global HJN_B1 "onebwdr 1" global HJN_B2 "onebwdr -1" global HJN_B5 "whelp onebw" global HJN_B6 "exit 1234" onebwdr 0 * noi wdlg "Between and Within Variation" 5 5 75 150 cap noi wdlg "Between and Within Variation" 5 105 310 150 restore end program define onebwdr version 4.0 local arg=`1' if `arg'==1 { global sig = min(6,$sig+1)} if `arg'==-1 { global sig = max(1,$sig-1)} gph open gph pen 1 * drbox1 0 0 32000 13000 * drbox1 0 15000 32000 23000 local n=$HJN_V1 * gph text 1000 16000 0 0 `n' if `n' < 2 | `n' > 100 { sstopbox stop "Sample size must be between 2 and 100" exit} local n4=4*`n' replace x=. replace y=. replace x=5*uniform() in 1/`n4' replace y=40*uniform() * graph y x,xlab ylab s(i) yline graph y x,xlab(0,1,2,3,4) ylab s(i) l1(" ") l2(" ") b1(" ") b2(" ") bbox(2000,2000,11500,16000,850,400,0) gphconv replace x=int((_n-1)/`n')+1 in 1/`n4' replace y=. local n1=1 local n2=`n' replace y=17+$sig*invnorm(uniform()) in `n1'/`n2' local n1=`n1'+`n' local n2=`n2'+`n' replace y=22+$sig*invnorm(uniform()) in `n1'/`n2' local n1=`n1'+`n' local n2=`n2'+`n' replace y=17+$sig*invnorm(uniform()) in `n1'/`n2' local n1=`n1'+`n' local n2=`n2'+`n' replace y=22+$sig*invnorm(uniform()) in `n1'/`n2' points x y gph pen 3 drline .75 17 1.25 17 drline 1.75 22 2.25 22 drline 2.75 17 3.25 17 drline 3.75 22 4.25 22 gph pen 2 oneway y x local f1: display %5.2f _result(6) local nd1=_result(3) local nd2=_result(6) local pv1: display %5.3f fprob(`nd1',`nd2',`f1') gph font 600 300 gph text 1000 16000 0 0 True Means Are 17 22 17 22, n=`n', sigma=$sig, F=`f1', p-value=`pv1' graph y, ylab(0,10,20,30,40) box by(x) l1(" ") l2(" ") b1(" ") b2(" ") bbox(2000,18000,11500,32000,850,400,0) replace y=40*uniform() graph y x,xlab(0,1,2,3,4) ylab s(i) l1(" ") l2(" ") b1(" ") b2(" ") bbox(13500,2000,23000,16000,850,400,0) gphconv replace y=20+$sig*invnorm(uniform()) in 1/`n4' points x y graph y, ylab(0,10,20,30,40) box by(x) l1(" ") l2(" ") b1(" ") b2(" ") bbox(13500,18000,23000,32000,850,400,0) oneway y x local f2: display %5.2f _result(6) local pv2: display %5.3f fprob(`nd1',`nd2',`f2') gph font 600 300 gph text 12500 16000 0 0 True Means Are 20 20 20 20, n=`n', sigma=$sig, F=`f2', p-value=`pv2' gph close end exit