{smcl} {com}{sf}{ul off}{txt}{.-} name: {res} {txt}log: {res}/Users/eric/Work/MB/ATCR/200/Labs/lab 4.smcl {txt}log type: {res}smcl {txt}opened on: {res}20 Sep 2018, 11:29:51 {txt} {com}. . /* In this lab, we first show how to use various "immediate" commands in Stata, > which are useful for running hypothesis tests using summary data (e.g., sample > sizes, means, standard deviations, counts or proportions). Then we will show > how to run these tests using baseline data from the 2763 participants in the > HERS RCT of hormone therapy as secondary prevention for coronary heart disease. > > ******************************************************************************** > Tests using immediate commands > > For the population of middle-aged men who later develop diabetes, baseline BMI > has unknown mean and standard deviation(SD). In a sample of 58 men selected > from this population, mean BMI is 25.0 kg/m2, with SD 2.7. > > First, calculate a 95% confidence interval for the mean. Begin by checking the > help for the cii command. */ . . help cii {txt} {com}. . /* We have to specify the means option. The arguments, in order, are the sample > size, the mean, and the SD. */ . . cii means 58 25 2.7 {txt} Variable {c |} Obs Mean Std. Err. [95% Conf. Interval] {hline 13}{c +}{hline 63} {c |}{col 16}{res} 58{col 29} 25{col 41} .3545274{col 57} 24.29007{col 69} 25.70993{txt} {com}. . /* Now test the null hypothesis that the mean in this population is 24.0 kg/m2, > the known mean of the population of men who do not develop diabetes. The > immediate commands are restricted to parametric tests, so we are implicitly > assuming the BMI is reasonably normal, which is of course impossible to check > from the summary data. */ . . help ttesti {txt} {com}. . /* We need the 1-sample t-test, comparing the observed sample mean to a known value. The last argument for the command is the null value of the mean. */ . . ttesti 58 25 2.7 24 {txt}One-sample t test {hline 9}{c TT}{hline 68} {col 10}{c |}{col 16}Obs{col 27}Mean{col 35}Std. Err.{col 47}Std. Dev.{col 59}[95% Conf. Interval] {hline 9}{c +}{hline 68} x {c |}{res}{col 12} 58{col 22} 25{col 34} .3545274{col 46} 2.7{col 58} 24.29007{col 70} 25.70993 {txt}{hline 9}{c BT}{hline 68} mean = mean({res}x{txt}) t = {res} 2.8207 {txt}Ho: mean = {res}24 {txt}degrees of freedom = {res} 57 {txt}Ha: mean < {res}24 {txt}Ha: mean != {res}24 {txt}Ha: mean > {res}24 {txt}Pr(T < t) = {res}0.9967 {txt}Pr(|T| > |t|) = {res}0.0066 {txt}Pr(T > t) = {res}0.0033 {txt} {com}. . /* So reasonably strong evidence that mean BMI among men who go on to develop > diabetes is higher than the population mean among men who do not. > > ********** > > In a study investigating the effect of seatbelt use on morbidity and mortality > among pediatric victims of motor vehicles accidents, two random samples were > selected, one of children wearing seat belts at the time of the accident > (N=123), and the other of children who were not (N=290). In the first sample, > 3 children died, while in the second, 13 did. Is there evidence that these > two proportions are different? > > We can do this using the prtesti command. */ . . help prtesti {txt} {com}. . /* We need the immediate two-sample test of proportions with the count option. */ . . prtesti 123 3 290 13, count {txt}Two-sample test of proportions {res}x{txt}: Number of obs = {res} 123 y{txt}: Number of obs = {res} 290 {txt}{hline 13}{c TT}{hline 64} {col 14}{c |}{col 22}Mean{col 29}Std. Err.{col 44}z{col 49}P>|z|{col 59}[95% Conf. Interval] {hline 13}{c +}{hline 64} x {c |}{res}{col 17} .0243902{col 28} .0139089{col 58}-.0028707{col 70} .0516512 {txt}y {c |}{res}{col 17} .0448276{col 28} .0121511{col 58} .0210119{col 70} .0686432 {txt}{hline 13}{c +}{hline 64} diff {c |}{res}{col 17}-.0204373{col 28} .0184691{col 58}-.0566361{col 70} .0157614 {txt}{col 14}{c |}{col 17}under Ho:{res}{col 28} .0207648{col 38} -0.98{col 49}0.325 {txt}{hline 13}{c BT}{hline 64} diff = prop({res}x{txt}) - prop({res}y{txt}) z = {res} -0.9842 {txt} Ho: diff = 0 Ha: diff < 0 Ha: diff != 0 Ha: diff > 0 Pr(Z < z) = {res}0.1625 {txt}Pr(|Z| > |z|) = {res}0.3250 {txt}Pr(Z > z) = {res}0.8375 {txt} {com}. . /* We could also use csi command, which has the advantage of providing exact > tests, which could be needed, since the number of deaths among children wearing > seat belts was <5. It also provides confidence intervals for the risk difference > and risk ratio. In this case, the required input is the number of cases and > non-cases, rather than the number of cases and sample size. We have set this > up to treat seat belt use as exposure. */ . . help csi {txt} {com}. . csi 3 13 120 277, exact {txt}{col 18}{c |} Exposed Unexposed {c |} Total {hline 17}{c +}{hline 24}{c +}{hline 12} Cases {c |} {res} 3 13{txt} {c |} {res} 16 {txt}Noncases {c |} {res} 120 277{txt} {c |} {res} 397 {txt}{hline 17}{c +}{hline 24}{c +}{hline 12} {col 12}Total {c |} {res} 123 290{txt} {c |} {res} 413 {txt}{col 18}{c |}{col 43}{c |} Risk {c |} {res} .0243902 .0448276{txt} {c |} {res} .0387409 {txt}{col 18}{c |}{col 43}{c |} {col 18}{c |} Point estimate {c |} [95% Conf. Interval] {col 18}{c LT}{hline 24}{c +}{hline 24} Risk difference {c |} {res}{col 27}-.0204373{txt}{col 43}{c |} {res}-.0566361 .0157614{txt} Risk ratio {c |} {res}{col 27} .5440901{txt}{col 43}{c |} {res} .1578389 1.875545{txt} Prev. frac. ex. {c |} {res}{col 27} .4559099{txt}{col 43}{c |} {res}-.8755455 .8421611{txt} Prev. frac. pop {c |} {res}{col 27} .1357795{txt}{col 43}{c |} {col 18}{c BLC}{hline 24}{c BT}{hline 24} {col 35}1-sided Fisher's exact P ={res} 0.2468 {txt}{col 35}2-sided Fisher's exact P ={res} 0.4126 {txt} {com}. . /* At least in this case, the chi-square and exact tests give qualitatively > similar results. The difference may be NS, but the CIs for the risk difference > and risk ratio are wide. A puzzing result -- are seatbelts ineffective for > young children, or was the sample size too small? > > *********** > > Sixty-three adult males with coronary artery disease were stress-tested riding > a stationary bicycle until the onset of chest pain. After resting, participants > rode again until the repeat onset of angina, and the percent decrease in time > to onset of pain was recorded. This procedure was carried out twice, first with > clean air, and then, on a subsequent visit, when carbon monoxide had been mixed > in the air. The sample size was 63 and the mean decreases in time to second > onset were 3.35% and 9.63% at the first and second visits, and the standard > deviation of the difference, 9.63-3.35=6.28%, was 20.3%. The research question > is whether carbon monoxide affected the decrease in time to onset of chest > pain on the second trial. > > We can test the difference using a paired t-test. */ . . help ttesti {txt} {com}. . /* We need the immediate for of the one sample test, with the null hypothesis > (the last argument to the command) of zero. */ . . ttesti 63 6.28 20.3 0 {txt}One-sample t test {hline 9}{c TT}{hline 68} {col 10}{c |}{col 16}Obs{col 27}Mean{col 35}Std. Err.{col 47}Std. Dev.{col 59}[95% Conf. Interval] {hline 9}{c +}{hline 68} x {c |}{res}{col 12} 63{col 22} 6.28{col 34} 2.55756{col 46} 20.3{col 58} 1.167511{col 70} 11.39249 {txt}{hline 9}{c BT}{hline 68} mean = mean({res}x{txt}) t = {res} 2.4555 {txt}Ho: mean = {res}0 {txt}degrees of freedom = {res} 62 {txt}Ha: mean < {res}0 {txt}Ha: mean != {res}0 {txt}Ha: mean > {res}0 {txt}Pr(T < t) = {res}0.9916 {txt}Pr(|T| > |t|) = {res}0.0169 {txt}Pr(T > t) = {res}0.0084 {txt} {com}. . /******************************************************************************** > Tests using actual data > > Now we will run analogous tests using actual rather than summarized data. > Begin by reading in the HERS data. */ . . use hers.dta, clear {txt} {com}. . describe {txt}Contains data from {res}hers.dta {txt} obs:{res} 2,763 {txt} vars:{res} 46 23 Jul 2018 10:25 {txt} size:{res} 237,618 {txt}{hline} storage display value variable name type format label variable label {hline} {p 0 48}{res}{bind:ptid }{txt}{bind: int }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}anonymized participant identifier{p_end} {p 0 48}{bind:acei }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}use of ace-inhibitors{p_end} {p 0 48}{bind:age }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}age (years){p_end} {p 0 48}{bind:anyllm }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}use of any lipid-lowering agent{p_end} {p 0 48}{bind:aspirin }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}use of aspirin{p_end} {p 0 48}{bind:betab }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}use of beta-blockers{p_end} {p 0 48}{bind:bmi }{txt}{bind: float }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}bmi (kg/m^2){p_end} {p 0 48}{bind:ccb }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}use of calcium channel blockers{p_end} {p 0 48}{bind:crcl }{txt}{bind: float }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}creatinine clearance (ml/min){p_end} {p 0 48}{bind:creat }{txt}{bind: float }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}creatinine (mg/dl) {p_end} {p 0 48}{bind:dbp }{txt}{bind: int }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}diastolic blood pressure{p_end} {p 0 48}{bind:diabetes }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}diabetes{p_end} {p 0 48}{bind:digitali }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}use of digitalis{p_end} {p 0 48}{bind:dmpills }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}oral dm medication by self-report{p_end} {p 0 48}{bind:drinkany }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}any current alcohol consumption{p_end} {p 0 48}{bind:drnkspwk }{txt}{bind: float }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}average drinks per week{p_end} {p 0 48}{bind:educyrs }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}years of education{p_end} {p 0 48}{bind:exercise }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}exercise at least 3 times per week{p_end} {p 0 48}{bind:globrat }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:globrat }{bind: }{res}{res}self-reported health{p_end} {p 0 48}{bind:glucose }{txt}{bind: int }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}fasting glucose (mg/dl) {p_end} {p 0 48}{bind:hdl0 }{txt}{bind: int }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}baseline hdl cholesterol (mg/dl){p_end} {p 0 48}{bind:hdl1 }{txt}{bind: int }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}year 1 hdl cholesterol (mg/dl){p_end} {p 0 48}{bind:ht }{txt}{bind: byte }{bind:{txt}%15.0g }{space 1}{bind:ht }{bind: }{res}{res}random assignment to hormone therapy{p_end} {p 0 48}{bind:htnmeds }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}anti-hypertensive use{p_end} {p 0 48}{bind:insulin }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}insulin use by self-report{p_end} {p 0 48}{bind:ldl0 }{txt}{bind: float }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}baseline ldl cholesterol (mg/dl){p_end} {p 0 48}{bind:ldl1 }{txt}{bind: float }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}year 1 ldl cholesterol (mg/dl){p_end} {p 0 48}{bind:lpa0 }{txt}{bind: float }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}baseline Lp(a) (mg/dl){p_end} {p 0 48}{bind:lpa1 }{txt}{bind: float }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}year 1 Lp(a) (mg/dl){p_end} {p 0 48}{bind:medcond }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}other serious conditions by self-report{p_end} {p 0 48}{bind:nonwhite }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}nonwhite race/ethnicity{p_end} {p 0 48}{bind:pcabg }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}pre-randomization CABG{p_end} {p 0 48}{bind:physact }{txt}{bind: byte }{bind:{txt}%20.0g }{space 1}{bind:physact }{bind: }{res}{res}comparative physical activity{p_end} {p 0 48}{bind:pmi }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}pre-randomization MI{p_end} {p 0 48}{bind:poorfair }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}poor/fair self-reported health{p_end} {p 0 48}{bind:pptca }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}pre-randomization PTCA{p_end} {p 0 48}{bind:raceth }{txt}{bind: byte }{bind:{txt}%20.0g }{space 1}{bind:raceth }{bind: }{res}{res}race/ethnicity{p_end} {p 0 48}{bind:sbp }{txt}{bind: int }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}systolic blood pressure{p_end} {p 0 48}{bind:smoking }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}current smoker{p_end} {p 0 48}{bind:statins }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:noyes }{bind: }{res}{res}use of statins{p_end} {p 0 48}{bind:tchol0 }{txt}{bind: int }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}baseline total cholesterol (mg/dl){p_end} {p 0 48}{bind:tchol1 }{txt}{bind: int }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}year 1 total cholesterol (mg/dl){p_end} {p 0 48}{bind:tgl0 }{txt}{bind: int }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}baseline triglycerides (mg/dl){p_end} {p 0 48}{bind:tgl1 }{txt}{bind: int }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}year 1 triglycerides (mg/dl){p_end} {p 0 48}{bind:weight }{txt}{bind: float }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}weight (kg){p_end} {p 0 48}{bind:whr }{txt}{bind: float }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}waist/hip ratio{p_end} {txt}{hline} Sorted by: {com}. sum {txt} Variable {c |} Obs Mean Std. Dev. Min Max {hline 13}{c +}{hline 57} {space 8}ptid {c |}{res} 2,763 1382 797.7537 1 2763 {txt}{space 8}acei {c |}{res} 2,763 .1758958 .3808004 0 1 {txt}{space 9}age {c |}{res} 2,763 66.64857 6.653081 44 79 {txt}{space 6}anyllm {c |}{res} 2,763 .4828085 .4997948 0 1 {txt}{space 5}aspirin {c |}{res} 2,763 .7915309 .4062874 0 1 {txt}{hline 13}{c +}{hline 57} {space 7}betab {c |}{res} 2,763 .3260948 .4688673 0 1 {txt}{space 9}bmi {c |}{res} 2,758 28.57925 5.517783 15.21 54.13 {txt}{space 9}ccb {c |}{res} 2,763 .5479551 .4977851 0 1 {txt}{space 8}crcl {c |}{res} 2,760 61.30613 19.60505 6.18408 167.5208 {txt}{space 7}creat {c |}{res} 2,762 1.084432 .3163941 .4 9.3 {txt}{hline 13}{c +}{hline 57} {space 9}dbp {c |}{res} 2,762 73.1517 9.705057 45 102 {txt}{space 4}diabetes {c |}{res} 2,763 .2645675 .4411825 0 1 {txt}{space 4}digitali {c |}{res} 2,763 .0998914 .2999095 0 1 {txt}{space 5}dmpills {c |}{res} 2,763 .0962722 .2950175 0 1 {txt}{space 4}drinkany {c |}{res} 2,761 .3915248 .4881797 0 1 {txt}{hline 13}{c +}{hline 57} {space 4}drnkspwk {c |}{res} 2,763 1.355169 3.652089 0 49.5 {txt}{space 5}educyrs {c |}{res} 2,761 12.66932 2.645689 1 20 {txt}{space 4}exercise {c |}{res} 2,763 .3865364 .487044 0 1 {txt}{space 5}globrat {c |}{res} 2,760 3.063406 .842833 1 5 {txt}{space 5}glucose {c |}{res} 2,763 112.1516 36.84941 29 298 {txt}{hline 13}{c +}{hline 57} {space 8}hdl0 {c |}{res} 2,752 50.26199 13.21566 14 130 {txt}{space 8}hdl1 {c |}{res} 2,608 51.78183 13.87166 14 124 {txt}{space 10}ht {c |}{res} 2,763 .4994571 .5000902 0 1 {txt}{space 5}htnmeds {c |}{res} 2,763 .8215708 .382943 0 1 {txt}{space 5}insulin {c |}{res} 2,763 .0988056 .2984549 0 1 {txt}{hline 13}{c +}{hline 57} {space 8}ldl0 {c |}{res} 2,752 145.0385 37.80322 36.8 393.4 {txt}{space 8}ldl1 {c |}{res} 2,608 132.3915 39.02262 -20 450.2 {txt}{space 8}lpa0 {c |}{res} 2,759 33.71443 32.61081 0 236 {txt}{space 8}lpa1 {c |}{res} 2,612 30.95115 33.28073 0 201.9 {txt}{space 5}medcond {c |}{res} 2,763 .3720594 .4834416 0 1 {txt}{hline 13}{c +}{hline 57} {space 4}nonwhite {c |}{res} 2,763 .1129207 .3165532 0 1 {txt}{space 7}pcabg {c |}{res} 2,763 .4096996 .4918673 0 1 {txt}{space 5}physact {c |}{res} 2,763 3.200145 1.083468 1 5 {txt}{space 9}pmi {c |}{res} 2,763 .5099529 .4999914 0 1 {txt}{space 4}poorfair {c |}{res} 2,760 .240942 .4277327 0 1 {txt}{hline 13}{c +}{hline 57} {space 7}pptca {c |}{res} 2,763 .4303294 .4952118 0 1 {txt}{space 6}raceth {c |}{res} 2,763 1.146942 .439843 1 3 {txt}{space 9}sbp {c |}{res} 2,763 135.0695 19.02781 83 224 {txt}{space 5}smoking {c |}{res} 2,763 .1302932 .3366866 0 1 {txt}{space 5}statins {c |}{res} 2,763 .3731451 .4837277 0 1 {txt}{hline 13}{c +}{hline 57} {space 6}tchol0 {c |}{res} 2,759 228.5799 41.01411 110 465 {txt}{space 6}tchol1 {c |}{res} 2,613 219.2346 41.10315 92 535 {txt}{space 8}tgl0 {c |}{res} 2,759 166.1493 63.51077 31 476 {txt}{space 8}tgl1 {c |}{res} 2,613 175.7976 84.45064 31 1016 {txt}{space 6}weight {c |}{res} 2,761 72.7305 14.70306 37.5 131.6 {txt}{hline 13}{c +}{hline 57} {space 9}whr {c |}{res} 2,760 .869979 .0795729 .624 1.218 {txt} {com}. . /* First compare baseline LDL values in smokers and non-smokers using the > t-test. */ . . ttest ldl0, by(smoking) {txt}Two-sample t test with equal variances {hline 9}{c TT}{hline 68} Variable{col 10}{c |}{col 16}Obs{col 27}Mean{col 35}Std. Err.{col 47}Std. Dev.{col 59}[95% Conf. Interval] {hline 9}{c +}{hline 68} no {c |}{res}{col 12} 2,397{col 22} 144.3985{col 34} .7639244{col 46} 37.4011{col 58} 142.9005{col 70} 145.8965 {txt}yes {c |}{res}{col 12} 355{col 22} 149.36{col 34} 2.133767{col 46} 40.20324{col 58} 145.1635{col 70} 153.5565 {txt}{hline 9}{c +}{hline 68} combined {c |}{res}{col 12} 2,752{col 22} 145.0385{col 34} .7206171{col 46} 37.80322{col 58} 143.6255{col 70} 146.4515 {txt}{hline 9}{c +}{hline 68} diff {c |}{res}{col 22}-4.961502{col 34} 2.148142{col 58}-9.173636{col 70}-.7493675 {txt}{hline 9}{c BT}{hline 68} diff = mean({res}no{txt}) - mean({res}yes{txt}) t = {res} -2.3097 {txt}Ho: diff = 0 degrees of freedom = {res} 2750 {txt}Ha: diff < 0 Ha: diff != 0 Ha: diff > 0 Pr(T < t) = {res}0.0105 {txt}Pr(|T| > |t|) = {res}0.0210 {txt}Pr(T > t) = {res}0.9895 {txt} {com}. . /* We can check whether the results are sensitive to allowing for unequal > variance in smoker and non-smokers. */ . . ttest ldl0, by(smoking) unequal {txt}Two-sample t test with unequal variances {hline 9}{c TT}{hline 68} Variable{col 10}{c |}{col 16}Obs{col 27}Mean{col 35}Std. Err.{col 47}Std. Dev.{col 59}[95% Conf. Interval] {hline 9}{c +}{hline 68} no {c |}{res}{col 12} 2,397{col 22} 144.3985{col 34} .7639244{col 46} 37.4011{col 58} 142.9005{col 70} 145.8965 {txt}yes {c |}{res}{col 12} 355{col 22} 149.36{col 34} 2.133767{col 46} 40.20324{col 58} 145.1635{col 70} 153.5565 {txt}{hline 9}{c +}{hline 68} combined {c |}{res}{col 12} 2,752{col 22} 145.0385{col 34} .7206171{col 46} 37.80322{col 58} 143.6255{col 70} 146.4515 {txt}{hline 9}{c +}{hline 68} diff {c |}{res}{col 22}-4.961502{col 34} 2.266394{col 58}-9.415545{col 70}-.5074582 {txt}{hline 9}{c BT}{hline 68} diff = mean({res}no{txt}) - mean({res}yes{txt}) t = {res} -2.1892 {txt}Ho: diff = 0 Satterthwaite's degrees of freedom = {res} 449.474 {txt}Ha: diff < 0 Ha: diff != 0 Ha: diff > 0 Pr(T < t) = {res}0.0145 {txt}Pr(|T| > |t|) = {res}0.0291 {txt}Pr(T > t) = {res}0.9855 {txt} {com}. . /* Clearly the SDs do differ somewhat, and allowing for this inequality using > the unequal option increases the p-value a bit. > > We can also use a paired t-test to compare the LDL values measured at baseline > to the year 1 value: */ . . ttest ldl0 == ldl1 {txt}Paired t test {hline 9}{c TT}{hline 68} Variable{col 10}{c |}{col 16}Obs{col 27}Mean{col 35}Std. Err.{col 47}Std. Dev.{col 59}[95% Conf. Interval] {hline 9}{c +}{hline 68} ldl0 {c |}{res}{col 12} 2,597{col 22} 144.758{col 34} .7421193{col 46} 37.81897{col 58} 143.3028{col 70} 146.2132 {txt}ldl1 {c |}{res}{col 12} 2,597{col 22} 132.3248{col 34} .7661903{col 46} 39.04565{col 58} 130.8224{col 70} 133.8272 {txt}{hline 9}{c +}{hline 68} diff {c |}{res}{col 12} 2,597{col 22} 12.43327{col 34} .681349{col 46} 34.72207{col 58} 11.09723{col 70} 13.76931 {txt}{hline 9}{c BT}{hline 68} mean(diff) = mean({res}ldl0{txt} - {res}ldl1{txt}) t = {res} 18.2480 {txt} Ho: mean(diff) = 0 degrees of freedom = {res} 2596 {txt}Ha: mean(diff) < 0 Ha: mean(diff) != 0 Ha: mean(diff) > 0 Pr(T < t) = {res}1.0000 {txt}Pr(|T| > |t|) = {res}0.0000 {txt}Pr(T > t) = {res}0.0000 {txt} {com}. . /* Note that the sample size goes down. Why? > > We could also use a non-parametric Wilcoxon ranksum test to compare baseline > LDL levels by smoking status; this method essentially operates on the ranks > of LDL, rather than directly on the measured LDL values. For within-person > comparisons of baseline and year 1 LDL, we can use the signrank test. */ . . ranksum ldl0, by(smoking) {txt}Two-sample Wilcoxon rank-sum (Mann-Whitney) test smoking {c |} obs rank sum expected {hline 13}{c +}{hline 33} no {c |}{res}{col 17} 2397{col 26} 3265492{col 38} 3299470.5 {txt}yes {c |}{res}{col 17} 355{col 26} 522636{col 38} 488657.5 {txt}{hline 13}{c +}{hline 33} combined {c |}{res}{col 17} 2752{col 26} 3788128{col 38} 3788128 {txt}unadjusted variance{col 22}{res} 1.952e+08 {txt}adjustment for ties{col 22}{res} -966.3953 {txt}{col 22}{hline 10} adjusted variance{col 22}{res} 1.952e+08 {txt}Ho: ldl0(smoking==no) = ldl0(smoking==yes) {col 14}z = {res} -2.432 {txt}{col 5}Prob > |z| = {res} 0.0150 {txt} {com}. signrank ldl0 = ldl1 {txt}Wilcoxon signed-rank test sign {c |} obs sum ranks expected {hline 13}{c +}{hline 33} positive {c |}{res}{col 17} 1714{col 26} 2399964.5{col 38} 1686741 {txt}negative {c |}{res}{col 17} 877{col 26} 973517.5{col 38} 1686741 {txt}zero {c |}{res}{col 17} 6{col 26} 21{col 38} 21 {txt}{hline 13}{c +}{hline 33} all {c |}{res}{col 17} 2597{col 26} 3373503{col 38} 3373503 {txt}unadjusted variance{col 22}{res} 1.460e+09 {txt}adjustment for ties{col 22}{res} -2366.5 {txt}adjustment for zeros{col 22}{res} -22.75 {txt}{col 22}{hline 10} adjusted variance{col 22}{res} 1.460e+09 {txt}Ho: ldl0 = ldl1 {col 14}z = {res} 18.663 {txt}{col 5}Prob > |z| = {res} 0.0000 {txt} {com}. . /* In both cases, the results are similar to the t-test results. Another > non-parametric approach is to compare the proportions that are greater than > the overall median, using a chi-square test. */ . . median ldl0, by(smoking) {txt}Median test Greater {c |} than the {c |} current smoker median {c |} no yes {c |} Total {hline 11}{c +}{hline 22}{c +}{hline 10} no {c |}{res} 1,222 157 {txt}{c |}{res} 1,379 {txt} yes {c |}{res} 1,175 198 {txt}{c |}{res} 1,373 {txt}{hline 11}{c +}{hline 22}{c +}{hline 10} Total {c |}{res} 2,397 355 {txt}{c |}{res} 2,752 {txt} Pearson chi2({res}1{txt}) = {res} 5.6437 {txt} Pr = {res}0.018 {txt} Continuity corrected: Pearson chi2({res}1{txt}) = {res} 5.3768{txt} Pr = {res}0.020 {txt} {com}. . /* This command has options for how ties at the median are handled; check the > help to learn about this. */ . . help median {txt} {com}. . /* For multi-category predictors, parametric and nonparametric alternatives > include ANOVA and Kruskal-Wallis test respectively. */ . . anova lpa0 raceth {txt}Number of obs = {res} 2,759 {txt}R-squared ={res} 0.0470 {txt}Root MSE = {res} 31.8468 {txt}Adj R-squared ={res} 0.0463 {txt}Source {c |} Partial SS df MS F Prob>F {hline 11}{c +}{hline 52} Model {c |} {res} 137855.61 2 68927.804 67.96 0.0000 {txt}{c |} raceth {c |} {res} 137855.61 2 68927.804 67.96 0.0000 {txt}{c |} Residual {c |} {res} 2795180.5 2,756 1014.2164 {txt}{hline 11}{c +}{hline 52} Total {c |} {res} 2933036.1 2,758 1063.4649 {txt} {com}. kwallis lpa0, by(raceth) {txt}Kruskal-Wallis equality-of-populations rank test {c TLC}{hline 22}{c TT}{hline 7}{c TT}{hline 11}{c TRC} {c |} {res} raceth {txt}{c |} {res} Obs {txt}{c |} {res} Rank Sum {txt}{c |} {c LT}{hline 22}{c +}{hline 7}{c +}{hline 11}{c RT} {c |} {res} White {txt}{c |} {res}2,447 {txt}{c |} {res} 3.28e+06 {txt}{c |} {c |} {res} African American {txt}{c |} {res} 218 {txt}{c |} {res}417774.50 {txt}{c |} {c |} {res}Latina, Asian, Other {txt}{c |} {res} 94 {txt}{c |} {res}114079.00 {txt}{c |} {c BLC}{hline 22}{c BT}{hline 7}{c BT}{hline 11}{c BRC} chi-squared = {res} 109.553{txt} with {res}2{txt} d.f. probability = {res} 0.0001 {txt}chi-squared with ties = {res} 109.653{txt} with {res}2{txt} d.f. probability = {res} 0.0001 {txt} {com}. . /* In this case, the two tests gives qualitatively identical assessments of > the statistical significance of differences in Lp(a) by race/ethnicity. Next > week, we will look at the distribution of the these outcomes as well as sample > size to help decide whether the parametric or non-parametric test is more > appropriate. */ . . log close {txt}name: {res} {txt}log: {res}/Users/eric/Work/MB/ATCR/200/Labs/lab 4.smcl {txt}log type: {res}smcl {txt}closed on: {res}20 Sep 2018, 11:29:52 {txt}{.-} {smcl} {txt}{sf}{ul off}