CLRES 2020, Lab 4
CLRES 2020/Biostatistics 2041 |Course instructors: | |
|Biostatistics: Statistical Approaches in Clinical Research |Joyce C. H. Chang, PhD |
|Lab 4, Created by Fiona Callaghan |Maria K. Mor, PhD |
|GSCC 126, Monday 1-5pm, August 2, 2004 |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 [pic] 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:
✓ 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 fmc2@pitt.edu), 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 [pic] 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 (2n-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, (247 = 26.435, α = 0.05
P((2 > 26.435) = 0.9933 = p
p > 0.10 so we fail to reject Ho.
Conclusion: σ is less than or equal to 3
[pic]
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, (211 = 3.657, α = 0.05
P((2 < 3.657) = 0.0211 = p
p < 0.05 so we reject Ho.
Conclusion: σ is less than or equal to 3
[pic]
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, (211 = 3.657, α = 0.05
2P((2 < 3.657) = 2×0.0211 = 0.0422 = p
p < 0.05 so we reject Ho.
Conclusion: σ is not equal to 3
[pic]
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 (2 statistic) that you got from your data, directly with a critical t-value (or critical F or critical (2 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): |(2n-1,1-α |(2n-1,α |(2n-1,1-α/2 |
| | | |(2n-1,α/2 |
| | | | |
|Decision Rule: |Reject Ho if: |Reject Ho if: |Reject Ho if: |
| |3.657 > (2n-1,1-α |3.657 < (2n-1,α |3.657 < (2n-1,α/2 |
| | | |or |
| | | |3.657 > (2n-1,1-α/2 |
| | | | |
| | | |display invchi2(11,0.025) |
| |display invchi2(11,.95) |display invchi2(11,0.05) |display invchi2(11,0.975) |
|STATA command to get critical| | | |
|value: | | | |
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): |tn-1,1-α |tn-1,α |tn-1,1-α/2 |
| | | |tn-1,α/2 |
| | | | |
|Decision Rule: |Reject Ho if: |Reject Ho if: |Reject Ho if: |
| |2.951 > tn-1,1-α |2.951 < tn-1,α |2.951 < tn-1,α/2 |
| | | |or |
| | | |2.951 > tn-1,1-α/2 |
| | | | |
| | | |display invttail(47,0.975) |
|STATA command to get critical|display invttail(47,0.05) |display invttail(47, 0.95) |display invttail(47, 0.025) |
|value | | | |
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
Variable Names:
1. Treatment: Whether subject received calcium or placebo
2. Begin: seated systolic blood pressure before treatment
3. End: seated systolic blood pressure after treatment
4. Decrease: Decrease in blood pressure (Begin - End)
Two-sample test of variance
We may want to compare the variances from two-samples to see if they are the same. One of the assumption when we t-test two sample means, is that both samples were drawn from populations with the same population variance. One way to check this is to do a two-sample test of the variance using the F-distribution. We always do a two-sided test. To why this is so, think about the F-statistic F=s21/s22. Whether we choose s21/s22 or s22/s21 is arbitrary, so we want to check if F is really small or really big.
Example 1
Test whether the variance is different for the Begin values for the Calcium group compared to the Placebo group. Use α = 0.05.
✓ Type sdtest begin, by(treatment) You could also go to Statistics>Summaries, tables, & tests>Classical tests of hypotheses>Group variance comparison test. The “variable name” is begin and the “Group variable name” is treatment.
✓ To get the critical values type display invFtail(9,10,0.975) and display invFtail(9,10,0.025)
Our Ho: σ21 = σ22 and Ha: σ21 ≠ σ22 . We get that the p-value = 0.5840 so we fail to reject Ho. Also our F statistic is 1.442 which is between our critical values 0.25 and 3.78, so we fail to reject Ho.
Question 4: Perform the appropriate test to test whether there is a difference between the variances of Calcium and Placebo for the End blood pressure. Use α = 0.05
If you are just given the sample variances, but not the original data that it came from, you can use one of the STATA test calculators.
Example 2
Test whether the variances of the following 2 groups are different:
s21 = 10.7, s22 = 12.3, n1 = 25, n2 = 45, sample mean 1= 3, sample mean 2 = 5.4
✓ STATA only takes sd rather than variance to do the test so we must find the sd’s. Taking the square root we have, s1 = √10.7 = 3.27, s2 = √12.3 = 3.51. To see this, type display sqrt(10.7) and display sqrt(12.3)
✓ Type sdtesti 25 . 3.27 45 . 3.51 (You could also type sdtesti 25 3 3.27 45 5.4 3.51 but it doesn’t change the results, it just makes the output look nicer, plus you get confidence intervals for the means).
✓ Another way you could do this would be Statistics>Summaries, tables, & tests>Classical tests of hypotheses> Two-sample variance comparison calculator.
The p-value is 0.6956 so we fail to reject Ho.
Question 5: Perform the appropriate test to test whether there is a difference between the following variances: s21 = 99, s22 = 40, n1 = 100, n2 = 20
Two-sample t-test of means, assuming equal variance
We use a two-sample t-test when we have two samples and we wish to test whether the means of the two samples are equal/less than/greater than each other. Suppose we wanted to explore whether the means for “begin” blood pressure were different for the two treatment groups, placebo and calcium. First, we will find out what the means are for the two groups and get an idea of the variation. Then we test to see if the population variances are the same. If they seem to be (fail to reject the F-test) then we can perform a two-sample t-test assuming equal variance.
Note that if we have Ha: μc < μp this is saying that “Our alternative hypothesis is that the population mean for calcium is less than the population mean for placebo”. This is the same as saying Ha: μc – μp < 0.
Example 1
Is the mean for the starting blood pressure less for calcium that for treatment?
✓ Find the means and the standard deviations of the “Begin” blood pressure for the two treatment groups. Type bysort treatment : summarize begin and you should find the means are 114.9 and 113.3 (so not much difference).
✓ Type ttest begin, by(treatment) unpaired and you should get the following output:
. ttest begin, by(treatment) unpaired
Two-sample t test with equal variances
------------------------------------------------------------------------------
Group | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
Calcium | 10 114.9 3.426855 10.83667 107.1479 122.6521
Placebo | 11 113.2727 2.720598 9.023202 107.2109 119.3346
---------+--------------------------------------------------------------------
combined | 21 114.0476 2.118486 9.708121 109.6285 118.4667
---------+--------------------------------------------------------------------
diff | 1.627273 4.335936 -7.447946 10.70249
------------------------------------------------------------------------------
Degrees of freedom: 19
Ho: mean(Calcium) - mean(Placebo) = diff = 0
Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
t = 0.3753 t = 0.3753 t = 0.3753
P < t = 0.6442 P > |t| = 0.7116 P > t = 0.3558
✓ You can also go to Statistics>Summaries, tables, & tests>Classical tests of hypotheses>Group mean comparison test. Your “variable name” is begin and the “Group variable” is treatment.
✓ We can also find the critical value by typing display invttail(19,0.95)
Conclusion:
One-tailed test
Ho: μc – μp = 0, Ha: μc – μp < 0
df = 19, t = 0.3753, α = 0.05
P(t < 0.3753) = 0.6442 = p
tcrit = t19,α = t19,0.05 = -1.73
P-value method: p > 0.05 so we fail to reject Ho.
Critical value method: t > tcrit so we fail to reject Ho.
Conclusion: Means are the same.
Almost everything is just the same as the other t-tests that we have done. Some differences include:
o We have μo =0 most of the time because we are not comparing a mean to a benchmark figure anymore; we are comparing one sample mean to another sample mean.
o We have n-2 df rather than n-1 df.
Example 2
Is the mean for the starting blood pressure greater for calcium that for treatment?
✓ To get the critical value type display invttail(19,0.05)
We get the following conclusion:
One-tailed test
Ho: μc – μp = 0, Ha: μc – μp > 0
df = 19, t = 0.3753, α = 0.05
P(t > 0.3753) = 0.3558 = p
tcrit = t19,1-α = t19,0.95 = 1.73
P-value method: p > 0.05 so we fail to reject Ho.
Critical value method: t < tcrit so we fail to reject Ho.
Conclusion: Means are the same
Example 3
Is the mean for the starting blood pressure for calcium different to treatment?
To get the critical value:
✓ Type display invttail(19,0.025) and display invttail(19,0.975)
Conclusion:
Two-tailed test
Ho: μc – μp = 0, Ha: μc – μp ≠ 0
df = 19, t = 0.3753, α = 0.05
P(t > 0.3753)+P(t < -0.3753) = 0.7116 = p
tcrit = t19,0.975 = 2.09, tcrit = t19,0.025 = -2.09
P-value method: p > 0.05 so we fail to reject Ho.
Critical Value Method: -2.09Classical tests of hypotheses>Group mean comparison test. Your “variable name” is begin and the “Group variable” is treatment. Click on “Unequal variances”.
Conclusion:
Two-tailed test
Ho: μc – μp = 0, Ha: μc – μp ≠ 0
df = 19, t = 0.3719, α = 0.05
P(t > 0.3719)+P(t < -0.3719) = 0.7144 = p
tcrit = t19,0.975 = 2.09, tcrit = t19,0.025 = -2.09
P-value method: p > 0.05 so we fail to reject Ho.
Critical Value Method: -2.09Classical tests of hypotheses>Two sample mean comparison tests. Your first sample is “begin” and your second sample is “end”. You must also go to the “by/if/in” window and type “treatment” as the “by” variable. Do NOT click the “unpaired” box.
You should get the following output for placebo:
_______________________________________________________________________________
-> treatment = Placebo
Paired t test
------------------------------------------------------------------------------
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
begin | 11 113.2727 2.720598 9.023202 107.2109 119.3346
end | 11 113.9091 3.415086 11.32656 106.2998 121.5184
---------+--------------------------------------------------------------------
diff | 11 -.6363636 1.769811 5.869799 -4.579749 3.307021
------------------------------------------------------------------------------
Ho: mean(begin - end) = mean(diff) = 0
Ha: mean(diff) < 0 Ha: mean(diff) != 0 Ha: mean(diff) > 0
t = -0.3596 t = -0.3596 t = -0.3596
P < t = 0.3633 P > |t| = 0.7266 P > t = 0.6367
✓ We can also find the critical value by typing display invttail(10,0.95)
Conclusion:
One-tailed test
Ho: μb – μe = 0, Ha: μb – μe < 0
df = 10, t = -0.3596, α = 0.05
P(t < -0.3596) = 0.3633 = p
tcrit = t10,α = t10,0.05 = -1.81
P-value method: p > 0.05 so we fail to reject Ho.
Critical value method: t > tcrit so we fail to reject Ho.
Conclusion: Means are the same.
Example 2
Did the blood pressure decrease for the placebo group? (Use a paired t-test)
✓ We can find the critical value by typing display invttail(10,0.05)
Conclusion:
One-tailed test
Ho: μb – μe = 0, Ha: μb – μe > 0
df = 10, t = -0.3596, α = 0.05
P(t > -0.3596) = 0.6367 = p
tcrit = t10,1-α = t10,0.95 = 1.81
P-value method: p > 0.05 so we fail to reject Ho.
Critical value method: t < tcrit so we fail to reject Ho.
Conclusion: Means are the same.
Example 3
Did the blood pressure change for the placebo group? (Use a paired t-test)
✓ We can find the critical value by typing display invttail(10,0.025) and invttail(10,0.975)
Conclusion:
Two-tailed test
Ho: μb – μe = 0, Ha: μb – μe ≠ 0
df = 10, t = -0.3596, α = 0.05
P(t < -0.3596) + P(t > 0.3596) = 0.7266 = p
tcrit = t10,α/2 = t10,0.025 = -2.23
tcrit = t10,1-α/2 = t10,0.975 = 2.23
P-value method: p > 0.05 so we fail to reject Ho.
Critical value method: -2.23 < t < 2.23so we fail to reject Ho.
Conclusion: Means are the same.
Now it’s your turn! You will be asked to perform some paired t-tests on the before and after blood pressure for the calcium (treatment) group.
Question 11: Is there a difference between the beginning and ending blood pressures for the calcium group? Perform a paired t-test, use alpha = 0.05
Question 12: Do you think that the treatment had an effect?
Another way to do a paired t-test is to do a one-sample t-test on the difference with μo = 0. These two tests are equivalent.
✓ Type ttest decrease == 0 and then type ttest begin == end and check to see that you get the same result.
You may be thinking: What is the difference between “Statistics>Summaries, tables, & tests>Classical tests of hypotheses>Two sample mean comparison tests” and “Statistics>Summaries, tables, & tests>Classical tests of hypotheses>Group mean comparison test”? They perform the same types of two-sample tests, the difference is just in how your data is set out. If you have 2 groups you could label you data like this:
. list
+------------+
| x group |
|------------|
1. | 23 1 |
2. | 21 1 |
3. | 45 1 |
4. | 34 2 |
5. | 66 2 |
|------------|
6. | 12 2 |
+------------+
or like this:
. list
+---------+
| x1 x2 |
|---------|
1. | 23 34 |
2. | 21 66 |
3. | 45 12 |
+---------+
For the first type of layout, we would use ttest x, by(group) and “Statistics>Summaries, tables, & tests>Classical tests of hypotheses>Group mean comparison test”. For the second type we would use ttest x1==x2 and “Statistics>Summaries, tables, & tests>Classical tests of hypotheses>Two sample mean comparison tests”. You must remember to include the unpaired or unequal options as needed.
You can NOT use a t-test calculator to perform paired t-tests if you know the summary statistics but not the full data. STATA doesn’t have a calculator explicitly for this.
Power and Sample Size
We can get STATA to do some of the power and sample size calculations for us using the sampsi command. I could not find any drop down menus relating to power and sample size.
Example 1
Compute the sample size required for a one sample test with α = 0.05, μo = 5, μ1 = 7.2, σ = 4.17, power = 1-β = 0.85 for a two-sided test
✓ Type sampsi 5 7.2, sd(4.17) onesam power(0.85) alpha(0.05) and you should get the answer n=33.
Example 2
Compute the sample size required for a one sample test with α = 0.05, μo = 5, μ1 = 7.2, σ = 4.17, power = 1-β = 0.85 for a one-sided test
✓ Type sampsi 5 7.2, sd(4.17) onesam power(0.85) alpha(0.05) onesided and you should get the answer n=26.
Example 3
Compute the sample size n1 and n2 required for a two sample test with α = 0.05, μ1 = 5, μ2 = 7.2, σ1 = 4.17, σ2 = 8.7, power = 1-β = 0.85 for a two-sided test with n1=n2 (i.e. the ratio of n2/n1 = 1).
✓ Type sampsi 5 7.2, sd1(4.17) sd2(8.7) power(0.85) ratio(1) alpha(0.05) and you should get the answer n1 = 173 = n2 = 173.
Example 4
Compute the sample size n1 and n2 required for a two sample test with α = 0.05, μ1 = 5, μ2 = 7.2, σ1 = 4.17, σ2 = 8.7, power = 1-β = 0.85 for a one-sided test with 2n1=n2 (i.e. the ratio of n2/n1 = 2).
✓ Type sampsi 5 7.2, sd1(4.17) sd2(8.7) power(0.85) ratio(2) alpha(0.05) onesided and you should get the answer n1 = 83, n2 = 166.
Question 13: Calculate the sample size required for a two sample test with α = 0.01, μ1 = 110, μ2 = 120, σ1 = 3.54, σ2 = 2.2, power = 1-β = 0.90 for a one-sided test with the ratio of n2/n1 = 1.
If you know the difference between μo and μ1 is d i.e. |μ1 – μ2| = d, but you are not sure what the exact values of μo and μ1 are, then the best you can do is to guess approximate values for μo and μ1 that have a difference of d and enter those numbers into STATA. This will still come up with the correct sample size.
Example 5
Compute the sample size n1 and n2 required for a two sample test with α = 0.05, |μ1 – μ2| = 2, σ1 = 4.17, σ2 = 8.7, power = 1-β = 0.85 for a one-sided test with 2n1=n2 (i.e. the ratio of n2/n1 = 2).
✓ Type sampsi 0 2, sd1(4.17) sd2(8.7) power(0.85) ratio(2) alpha(0.05) onesided and you should get the answer n1 = 100, n2 = 200 (pure coincidence that these numbers happened to work out so nicely).
Question 14: Calculate the sample size required for a two sample test with α = 0.01, |μ1 - μ2 | = 10, σ1 = 3.54, σ2 = 2.2, power = 1-β = 0.90 for a one-sided test with the ratio of n2/n1 = 1.
If you want to calculate the power, then you use the same command but you do not specify the power and you do specify your sample size.
Example 6
Compute the power of a one sample test with α = 0.05, μo = 5, μ1 = 7.2, σ = 4.17, n = 25 for a two-sided test
✓ Type sampsi 5 7.2, sd(4.17) n(25) onesam alpha(0.05) and you should get the answer power =0.7511 .
Example 7
Compute the power of a one sample test with α = 0.05, μo = 5, μ1 = 7.2, σ = 4.17, n=25 for a one-sided test
✓ Type sampsi 5 7.2, sd(4.17) n(25) onesam alpha(0.05) onesided and you should get the answer 0.8397.
Example 8
Compute the power of a two sample test with α = 0.05, μ1 = 5, μ2 = 7.2, σ1 = 4.17, σ2 = 8.7, n1=24, n2=34 for a two-sided test.
✓ Type sampsi 5 7.2, sd1(4.17) sd2(8.7) n1(24) n2(34) alpha(0.05) and you should get the answer power = 0.2491
Example 9
Compute the power of a two sample test with α = 0.05, μ1 = 5, μ2 = 7.2, σ1 = 4.17, σ2 = 8.7, n1 = 234, n2=789 for a one-sided test.
✓ Type sampsi 5 7.2, sd1(4.17) sd2(8.7) n1(234) n2(789) alpha(0.05) onesided and you should get the answer power = 0.9999
Again, if you only know |μ1 – μ2| but not the actual values of μ1 and μ2, then you can substitute values for μ1 and μ2 that are distance d apart and you will get the correct answer.
Example 10
Compute the power of a two sample test with α = 0.05, |μ1 – μ2| = 1, σ1 = 4.17, σ2 = 8.7, n1 = 17, n2=22 for a one-sided test .
✓ Type sampsi 0 1, sd1(4.17) sd2(8.7) n1(17) n2(22) alpha(0.05) onesided and you should get the answer power = 0.1207
Question 15: Compute the power of a one sample test with α = 0.10, μo = 13.4, μ1 = 12.3, σ = 2.7, n = 50 for a two-sided test.
The End.
Saving the Lab
At the end of the session, follow the following procedure so that you can save any files you may want to review later on (e.g. your log file). These are the instructions if you are saving your files onto a floppy disk. If you have a zip disk, just do the same steps but with the "Zip" folder on the Desktop rather than the "Floppy" folder.
✓ Type log close and your log file is automatically saved and closed. You can also go to File>Log>Close.
✓ Insert floppy disk (or zip disk).
✓ Right click on the "Floppy" icon on the Desktop and select "Mount". We can now save files onto this disk. If you do not “Mount” the disk, then your files may not save properly.
✓ Close your "Lab4" folder if it is open. Click on the "Lab4" icon on the Desktop and drag the whole folder to the floppy disk icon on your Desktop. You should get a small menu giving you a choice to "Move" or "Copy" the documents. Click on "Copy". Your files should now be on your floppy disk.
✓ Double click on the floppy disk icon to check that there is now a "Lab4" folder on your floppy disk.
✓ Now close the floppy disk window, and right click on the floppy disk icon and select "Unmount". You must do this in order to take your disk out of these machines and still have your files saved.
✓ Now press the button on your computer to eject the floppy disk.
It is very important to save a backup on the university computer in case something happens to the disk.
✓ Click on the “Lab4” folder icon and drag the whole folder to the “AFS” folder on your desktop. You should get a small menu giving you a choice to "Move" or "Copy" the documents. Click on "Copy". Your files are now stored on the University of Pittsburgh computer system and can be accessed from any computer with an internet connection. See the instructions below on how to access these documents from your home computer.
✓ You have finished -- see you for the next lab!
Accessing the files from home from the University of Pittsburgh computer system
Here are some instructions FYI to help you access your backup copy in case there is some problem with your floppy disk or zip, when you get out of here. To access your backup copies from your home or office computer do the following steps:
✓ Open Netscape Navigator or Internet Explorer. Type and go to this destination. (eg. Using my username, I would type ).
✓ After a few seconds, Internet Explorer will ask you for your username and password. Enter these and press return.
✓ After the screen has loaded, you should see a list of files and one of them should be your “Lab4”. Just drag and click that file to wherever you want to put it on your home computer. Close Internet Explorer.
Answer Sheet – Lab4 CLRES 2020 Summer 04.
NAME and DATE:
Question 1,2 and 3:
|Ho | |
|Ha | |
|σo = | |
|df = n-1 = | |
| | |
|(2 = | |
|p = | |
| | |
|α = | |
| | |
|(2crit = | |
|Reject Ho? p-value method. | |
| | |
|Reject Ho? critical value method.| |
| | |
|Sketch of p-value | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
|Conclusion | |
| | |
| | |
| | |
| | |
Question 4:
|Ho | |
|Ha | |
|df = | |
| | |
|F= | |
|p = | |
| | |
|α = | |
| | |
|Fcrit = | |
|Reject Ho? p-value method. | |
| | |
|Reject Ho? critical value method.| |
| | |
|Sketch of p-value | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
|Conclusion | |
| | |
| | |
| | |
| | |
Question 5:
|Ho | |
|Ha | |
|df = | |
| | |
|F= | |
|p = | |
| | |
|α = | |
| | |
|Fcrit = | |
|Reject Ho? p-value method. | |
| | |
|Reject Ho? critical value method.| |
| | |
|Sketch of p-value | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
|Conclusion | |
| | |
| | |
| | |
| | |
Question 6:
| |Calcium |Placebo |
|Mean End | | |
|sd End | | |
Does it look like there is any difference?
Question 7,8:
|Ho | |
|Ha | |
|df = | |
|t = | |
|p = | |
| | |
|α = | |
| | |
|tcrit = | |
|Reject Ho? p-value method. | |
| | |
|Reject Ho? critical value method.| |
| | |
|Sketch of p-value | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
|Conclusion | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
Question 9:
|Ho | |
|Ha | |
|df = | |
|t = | |
|p = | |
| | |
|α = | |
| | |
|tcrit = | |
|Reject Ho? p-value method. | |
| | |
|Reject Ho? critical value method.| |
| | |
|Sketch of p-value | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
|Conclusion | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
Question 10:
|Ho | |
|Ha | |
|df = | |
|t = | |
|p = | |
| | |
|α = | |
| | |
|tcrit = | |
|Reject Ho? p-value method. | |
| | |
|Reject Ho? critical value method.| |
| | |
|Sketch of p-value | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
|Conclusion | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
Question 11, 12:
|Ho | |
|Ha | |
|df = | |
|t = | |
|p = | |
| | |
|α = | |
| | |
|tcrit = | |
|Reject Ho? p-value method. | |
| | |
|Reject Ho? critical value method.| |
| | |
|Sketch of p-value | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
|Conclusion | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
Question 13:
Question 14:
Question 15
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.