* Biostat 200 Lab 4 cd "~/work/mb/atcr/200/labs" capture log close log using "lab 4", replace /* 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 /* 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 /* 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 /* 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 /* 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 /* We need the immediate two-sample test of proportions with the count option. */ prtesti 123 3 290 13, count /* 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 csi 3 13 120 277, exact /* 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 /* 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 /******************************************************************************** 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 describe sum /* First compare baseline LDL values in smokers and non-smokers using the t-test. */ ttest ldl0, by(smoking) /* We can check whether the results are sensitive to allowing for unequal variance in smoker and non-smokers. */ ttest ldl0, by(smoking) unequal /* 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 /* 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) signrank ldl0 = ldl1 /* 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) /* This command has options for how ties at the median are handled; check the help to learn about this. */ help median /* For multi-category predictors, parametric and nonparametric alternatives include ANOVA and Kruskal-Wallis test respectively. */ anova lpa0 raceth kwallis lpa0, by(raceth) /* 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