/* Some student found it helpful to work from a do file */ *You will need to change the following working directory: cd "/Users/xxx/2018 Fall/Regression Models Biostats 210/Homework/Homework 1" capture log close quietly log using biostat210_2018_Assignment1_TeresaKortz.smcl, replace /*** #Biostat 210: Homework 1 --- #Instructions DUE October 1, 2019 (by 10:30am) to the TA mailbox near photocopy room near conference room 2600, Mission Hall. Contact: zara.Izadi@ucsf.edu for questions or issues --- ***/ /*** ### 0. Background This assignment will give you the opportunity to compare a series of analyses for a simple dataset. The purpose is to give you practice in contrasting analyses and considering their: (1) validity (unbiasedness of estimates, size of tests, coverage of confidence intervals), (2) efficiency (standard error of point estimates, power of tests, and width of confidence intervals) and (3) robustness (how methods perform when their key assumptions are incorrect). The data setting is based on a clinical trial of corneal ulcers. All 500 patients are given antibiotic therapy and half are randomized to placebo drops and half are randomized to steriod drops. The primary outcome is the log minimum angle of refraction (logMAR) which is a measure of visual acuity. Patients have their logMAR measure at enrollment and at week 12. ***/ /*** ### 1. Download Download the fake dataset scut.dta from the course website. ***/ /*** ### 2. The Model The mean log is equal in the two groups at baseline (as expected in a clinical trial) and value is set to be α. The mean logMAR is the placebo group at week 12 is α + β 0 in the placebo group and is α + β 0 + β 1 in the steroid group at week 12. The change in logMAR in the placebo group from baseline to week 12 is then given by (α + β 0 ) = β 0. The mean difference in logMAR at week 12 between steroid and placebo is given by (α + β 0 + β 1 )-(α + β 0 ) = β 1. . This is the difference that the study is designed to detect. -- the difference in average logMAR scores between the two groups at week 12. One other aspect of this data which we need to consider is the correlation structure. We will see an important aspect of analyzing such data is the magnitude of the correlation, rho, in the data. ***/ /*** ### 3. Analysis We will examine three different ways of estimating this difference 1. A simple t-test (compares mean logMAR at week 12 between the two groups) 2. A change score t-test (this analysis calculates the change score from baseline to week 12 and then compares those scores between the two groups) 3. A mixed model which treats logMAR values as repeated measures data and models how logMAR scores change with time, treatment and a time-by-treatment interaction. The data was simulated in a way which ensures that all of these should all estimate the same quantity -- β 1. __Q1: Among the 3 analyses, which would seem to be the most different in spirit from the other 3? Which, for you, seems to be simplest one to explain?__ _Answer: _ ***/ /*** Read in the data The dataset has variables id: Participant ID # logmar1: The Global Deficit Score at baseline logmar2: The Global Deficit Score at week 12 rx: Study Treatment (0=Placebo, 1 = Steroid) You can quickly get the means in the 2 groups at the two timepoints using the table command You can also get a sense of the data using boxplots ***/ clear use scut.dta table rx, c(mean logmar1 mean logmar2) graph box logmar1 logmar2, over(rx) scheme(s1color) img /*** ### Analysis 1: t-test __Q2: What is the mean difference given by the t-test, can you identify it as a difference between two cells in the table of means? What is the two-sided p-value for the t-test?__ _Answer: _ ***/ ttest logmar2, by(rx) /*** ### Analysis 2: t-test on change score First, we create variable diff we create a variable Then, tabulate the mean change __Q3: What is the mean change in logMAR from baseline to week 12 in each group?__ _Answer: _ ***/ gen diff=logmar2-logmar1 table rx, c(mean diff) ttest diff, by(rx) /*** __Q4: What is the mean difference given by the t-test on differences? How does it differ from the one you got from the t-test under analysis 1? Why do they differ? What is the two-sided p-value for the test?__ _Answer: _ ***/ /*** ### Analysis 3: Mixed Effects Model A final approach is to use all the outcome data by creating a longitudinal model. In such a case, the desired treatment effect is a treatment by time interaction. First switch the data from “wide” to “long” timepoint will be coded to 0=baseline, 1=week 12. The interaction term is: gen inter = timepoint*rx and the mixed effects command is: xtmixed logmar rx timepoint inter || id:, __Q5: How do you interpret the results? How do they compare with the other models?__ _Answer: _ ***/ reshape long logmar , i(id) xtset id gen timepoint=_j-1 gen inter = timepoint*rx xtmixed logmar rx timepoint inter || id:, /*** ### 4. Simulation It will be helpful to examine how these 4 analyses compare over many similar datasets. This will give us a sense of the bias, efficiency and power of the techniques. Download the file: hw1-sim.do from the course website. In Stata, go to Window, Do file editor, open new do file Then Open the File in the do file editor The simulation allows the following to vary nsim nobs rho mu1 mu2 sigma1 sigma2 beta: the number of simulations to be performed the number of people in the trial (1/2 placebo, 1/2 steroid) the correlation between logmars at baseline and wk 12 the mean logmar at baseline the mean logmar at week 12 (placebo group) the SD of logmars at baseline the SD of logmars at week 12 the effect of steroid at week 12 (mean difference in logMAR betw' steroid and placebo) The default values create a dataset which will resemble the one you have analyzed. Run the simulation using the default values. The simulation return the following for each simulated dataset ttest:treatment effect (estimate of beta) given by t-test in analysis 1 ptest: two-sided p-value given by t-test in analysis 1 power-ttest:1=if ptest < 0.05, 0 otherwise paired: treatment effect given by t-test in change score given in analysis 2 ppaired: two-sided p-value given by t-test in analysis 2 power-paired: 1=if ppaired < 0.05, 0 otherwise mxt: treatment effect from mixed model in analysis 4 pmxt: two-sided p-value given by mixed model in analysis 4 power-mxt: 1=if pmixed < 0.05, 0 otherwise __Q7: Are all the method unbiased for estimating the coefficient beta (=-0.15)? What are the relative efficiency compared with the mixed model? Do any of the methods appear to given an identical estimate of the treatment effect?__ _Answer: _ ***/ /*** __Q7: Which method is the most powerful? Which is the least?__ _Answer: _ ***/ /*** __Q8: Modify the simulations so rho=0.50. How do your answers in Q7 and Q8 change?__ _Answer: _ ***/ /*** __Q9: Modify the simulations so rho=0.0. How do your answers in Q7 and Q8 change?__ _Answer: _ ***/ qui log close //create MarkDoc markdoc biostat210_2018_Assignment1, replace statax export(pdf)