CLRES 2020/Biostatistics 2041

/ Course instructors:
Biostatistics: Statistical Approaches in Clinical Research
Lab 4, Created by Fiona Callaghan
GSCC 126, Monday 1-5pm, August 2, 2004 / Joyce C. H. Chang, PhD
Maria K. Mor, PhD
Doris M. Rubio, PhD
Mark S. Roberts, MD, MPP

Teaching Assistants:

Fiona Callaghan MS

Bill Clark

David Corcoran

Vinay Mehta

Goals for Lab 4

1.  One-sample test for the sample variance.

2.  Two-sample test for the sample variance.

3.  Critical Value Method.

4.  Two-sample t-test for sample mean.

5.  Paired sample t-test for sample mean.

6.  Sample Size and Power.

Whenever you see a check-mark that means that you are required to perform some action. Whenever some words are in this font it means that these

are commands that you should type in the command window of STATA. And whenever you see an > it refers to going to a series of drop-down windows, as in

“All Programs>Mathematics>STATA”. There are generally two ways to do most things in STATA: using commands that you type in the command window, or using drop-down menus, as in SPSS. Whenever possible, we will give you both ways of doing things in STATA, but you are only required to do it the way you feel most comfortable. On the back of this handout is some space for you to answer questions about the lab material.

The questions that you have to answer to get credit for this lab are enclosed in a box like this.

You will answer these questions as you go through the lab and hand them in at the end for credit, so remember to write your name on them! If you experience trouble at any time, just raise your hand to let a TA or an instructor know that your need help. Let’s get started!

Getting Started

First we will log on to the computer. To do this you will need your University of Pittsburgh user id and your password.

ü  You should see a space on the screen to enter your user id. Type it in and press return.

ü  Now enter your password and press return. You should now be logged on to the computer.

We will open a folder in which to save our work, and then we will open STATA and enter our data sets into STATA.

ü  Right-click somewhere on the desktop and select “New Directory”. Name your folder “Lab4”. We will save all our work in this folder.

ü  Go to the web page: http://www.pitt.edu/~changj/CLRES2020/main.html

ü  Scroll down to find the data sets and right-click on “heart.dta” and select “Save Link As…”.

ü  We want to save the file in “/scratch/username/Desktop/Lab4”. The “username” is your University of Pittsburgh email id (the part of your University of Pittsburgh email address that comes before the “@” e.g. “fmc2” is the id from the email address ), so on my computer I would save it in “/scratch/fmc2/Desktop/Lab4”. To do this, double click on “Desktop” and then “Lab4” in the main window (you should only have to do this once; the computer will remember where you are saving your files later on). Click “Save”.

ü  Save the data set calcium.dta, also.

ü  Your data sets should now be in your “Lab4” folder on the Desktop. Open up your “Lab4” folder to check that it is there, by double clicking on the “Lab4” icon on your desktop. If things do not look right, contact a TA.

Now we will open STATA.

ü  To open STATA, click on the icon in the bottom left of your screen (this is the “Start Applications” menu) and go up to “Mathematics” and then move the mouse right onto “STATA” to highlight it. Click on STATA and it should open.

ü  We wish to tell the STATA to save anything we do from now on in our “Lab4” file. To do this, in the command window type: cd “/scratch/username/Desktop/Lab4”

ü  Now open the log file. Type log using log4.log or you could go to File>Log>Begin… . You will have to give the log file a name, so type in “log4”. Next we have to make sure that STATA saves it as a “.log” file and not a “.smcl” file; go to the drop down menu next to “Save as type: Stata SMCL Document (*.smcl)” and select “Stata log (*.log)”. Then save in your Lab4 folder (you may have to double click on Desktop to find the Lab4 folder).

ü  Type use heart in the command window of STATA, and press return. You can also enter your data using a drop down window. Go to “File>Open…” and select the heart.dta data set and click “Open”. Your data set should now be in STATA.

ü  You should see some words in the “Variables” window -- “flow”, “type”, “valve” and “pulse”. Click on the Data Editor button (or type edit in the command window). You should see 4 columns of numbers and some labels at the top of those columns. Click on the red button with the white cross at the top right of the screen to get rid of the Data Editor window. If your data does not look right, ask a TA for help.

About the Data

Datafile Name: Heart Valves

Datafile Subjects: Medical

Story Names: Artificial Heart Valves

Reference: Anderson, V. L. and Robert A. McLean. (1974). Design of experiments. New York: M. Dekker.

Authorization: contact authors

Description: Artificial heart valves were tested in a mechanical apparatus that measured and controlled the pulse rate and the blood pressure. The purpose of the experiment was to determine the best valve type out of the four studied for all pulse rates or for particular rates. A maximum flow gradient was measured (in mm Hg) for each trial.

Number of cases: 48

Variable Names:

  1. Flow: Maximum flow gradient (in mm Hg)
  2. Type: Type of artificial heart
  3. Valve: Valve ID within Type
  4. Pulse: A pulse rate

For now, we will only be using the variables “Flow” and “Type”.

One-sample test of variance (s2)

So far, we have performed one-sample t-tests on the sample mean, to see if it is significantly greater than/less than/different to some baseline value. It is less common, but you can do the same thing with the sample variance. The basic format of the test is the same as for sample means but we use the c2n-1 distribution. We still assume that the data is normally distributed. We will not go into the calculation details here: we will get STATA to do the calculations for us, but we still need to be able to interpret the results!

Suppose that when measuring blood flow for artificial hearts, maintaining a steady flow (no wild fluctuations of pressure) is very important. So we could have situation where, on average, two artificial hearts both maintain a desirable flow rate but the first one does so by creating very high and then very low pressure, whilst the second one is more consistent, and therefore better. Suppose that a standard deviation of greater than 3 mm Hg is considered too variable.

Example 1

Does the flow rate, for all of the types of heart combined, have a standard deviation significantly greater than 3? Use α = 0.05

From the question:

Ho: σ ≤ 3, Ha: σ 3

Our σo = 3.

To get STATA to do the calculations for us:

ü  Type sdtest flow==3, level(95)

Note that this gives us a 95% confidence interval for the sample standard deviation, as well as the t-test.

You should get the following:

. sdtest flow==3, level(95)

One-sample test of variance

------

Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]

------+------

flow | 48 5.958333 .3247453 2.249901 5.30503 6.611637

------

Ho: sd(flow) = 3

chi2(47) = 26.435

Ha: sd(flow) < 3 Ha: sd(flow) != 3 Ha: sd(flow) > 3

P < chi2 = 0.0067 2*(P < chi2) = 0.0134 P > chi2 = 0.9933


Conclusions:

One-tailed test

Ho: σ ≤ 3, Ha: σ 3

df = 47, c247 = 26.435, α = 0.05

P(c2 26.435) = 0.9933 = p

p > 0.10 so we fail to reject Ho.

Conclusion: σ is less than or equal to 3

Example 2

Does the flow rate for the type 1 artificial heart have a standard deviation significantly less than 3? Use α = 0.05.

Answer:

Ho: σ1 ≥ 3, Ha: σ1 3

ü  bysort type : sdtest flow == 3, level(95)

. bysort type : sdtest flow==3, level(95)

______

-> type = 1

One-sample test of variance

------

Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]

------+------

flow | 12 4.916667 .4993683 1.729862 3.817564 6.015769

------

Ho: sd(flow) = 3

chi2(11) = 3.657

Ha: sd(flow) < 3 Ha: sd(flow) != 3 Ha: sd(flow) > 3

P < chi2 = 0.0211 2*(P < chi2) = 0.0422 P > chi2 = 0.9789


Conclusion:

One-tailed test

Ho: σ1 ≥ 3, Ha: σ1 3

df = 11, c211 = 3.657, α = 0.05

P(c2 3.657) = 0.0211 = p

p < 0.05 so we reject Ho.

Conclusion: σ is less than or equal to 3

Example 3

Does the flow rate for the type 1 artificial heart have a standard deviation significantly different to 3? Use α = 0.05.

Answer:

Ho: σ1 = 3, Ha: σ1 ≠ 3

ü  bysort type : sdtest flow == 3, level(95)

. bysort type : sdtest flow==3, level(95)

______

-> type = 1

One-sample test of variance

------

Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]

------+------

flow | 12 4.916667 .4993683 1.729862 3.817564 6.015769

------

Ho: sd(flow) = 3

chi2(11) = 3.657

Ha: sd(flow) < 3 Ha: sd(flow) != 3 Ha: sd(flow) > 3

P < chi2 = 0.0211 2*(P < chi2) = 0.0422 P > chi2 = 0.9789


Conclusion:

Two-tailed test

Ho: σ1 = 3, Ha: σ1 ≠ 3

df = 11, c211 = 3.657, α = 0.05

2P(c2 3.657) = 2×0.0211 = 0.0422 = p

p < 0.05 so we reject Ho.

Conclusion: σ is not equal to 3

Critical value method

You could also do these tests (or any t-tests) using the critical value method. This means that you compare you t-statistic (or F or c2 statistic) that you got from your data, directly with a critical t-value (or critical F or critical c2 value). Which critical value you need depends on you alternative hypothesis, df and alpha value.

Table 1: Critical values for sd test, alpha=0.05, n=12

Ha: s > 3 / Ha: s < 3 / Ha: s ≠ 3
Critical value(s):
Decision Rule:
STATA command to get critical value: / c2n-1,1-α
Reject Ho if:
3.657 > c2n-1,1-α
display invchi2(11,.95) / c2n-1,α
Reject Ho if:
3.657 < c2n-1,α
display invchi2(11,0.05) / c2n-1,1-α/2
c2n-1,α/2
Reject Ho if:
3.657 < c2n-1,α/2
or
3.657 > c2n-1,1-α/2
display invchi2(11,0.025)
display invchi2(11,0.975)

We can do a similar thing for one-sample t-tests of the means. Suppose had a Ho: μ = 5, testing whether the flow of the artificial hearts was significantly less/greater/different to 5 Hg mm. The output from STATA would be:

. ttest flow==5

One-sample t test

------

Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]

------+------

flow | 48 5.958333 .3247453 2.249901 5.30503 6.611637

------

Degrees of freedom: 47

Ho: mean(flow) = 5

Ha: mean < 5 Ha: mean != 5 Ha: mean > 5

t = 2.9510 t = 2.9510 t = 2.9510

P < t = 0.9975 P > |t| = 0.0049 P > t = 0.0025

Table 2: Critical values for one-sample t-test of means, alpha =0.05, n=48

Ha: μ > 5 / Ha: μ < 5 / Ha: μ ≠ 5
Critical value(s):
Decision Rule:
STATA command to get critical value / tn-1,1-α
Reject Ho if:
2.951 > tn-1,1-α
display invttail(47,0.05) / tn-1,α
Reject Ho if:
2.951 < tn-1,α
display invttail(47, 0.95) / tn-1,1-α/2
tn-1,α/2
Reject Ho if:
2.951 < tn-1,α/2
or
2.951 > tn-1,1-α/2
display invttail(47,0.975)
display invttail(47, 0.025)

Question 1: Perform a test to answer the following question: Is the standard deviation for type 4 heart significantly less than 3? Use α = 0.05.

Question 2: Sketch the p-value and the critical value on a graph.

Question 3: Would you recommend using this heart?

We will now use the calcium.dta data set. (You must download this data set from the web site if you haven’t already.)

ü  Type clear to remove the previous data set.

ü  Type use calcium

About the Data

Does increasing calcium intake reduce blood pressure? Observational studies suggest that there is a link, and that it is strongest in African-American men. Twenty-one African-American men participated in an experiment to test this hypothesis. Ten of the men took a calcium supplement for 12 weeks while the remaining 11 men received a placebo. Researchers measured the blood pressure of each subject before and after the 12-week period. The experiment was double-blind.

Datafile Name: Calcium

Reference: Moore, David S., and George P. McCabe (1989). Introduction to the Practice of Statistics. Original source: Lyle, Roseann M., et al., "Blood pressure and metabolic effects of calcium supplementation in normotensive white and black men," JAMA, 257(1987), pp. 1772-1776,

Authorization: contact authors

Description: Results of a randomized comparative experiment to investigate the effect of calcium on blood pressure in African-American men. A treatment group of 10 men received a calcium supplement for 12 weeks, and a control group of 11 men received a placebo during the same period. All subjects had their blood pressure tested before and after the 12-week period.

Number of cases: 21