EXST SAS Lab Lab #9: Two-sample t-tests

Similar documents
Lesson 1: Comparison of Population Means Part c: Comparison of Two- Means

THE FIRST SET OF EXAMPLES USE SUMMARY DATA... EXAMPLE 7.2, PAGE 227 DESCRIBES A PROBLEM AND A HYPOTHESIS TEST IS PERFORMED IN EXAMPLE 7.

Part 3. Comparing Groups. Chapter 7 Comparing Paired Groups 189. Chapter 8 Comparing Two Independent Groups 217

How To Test For Significance On A Data Set

2 Sample t-test (unequal sample sizes and unequal variances)

An Introduction to Statistical Tests for the SAS Programmer Sara Beck, Fred Hutchinson Cancer Research Center, Seattle, WA

LAB 4 INSTRUCTIONS CONFIDENCE INTERVALS AND HYPOTHESIS TESTING

Basic Statistical and Modeling Procedures Using SAS

Comparing Means in Two Populations

INTERPRETING THE ONE-WAY ANALYSIS OF VARIANCE (ANOVA)

Good luck! BUSINESS STATISTICS FINAL EXAM INSTRUCTIONS. Name:

How To Compare Birds To Other Birds

HYPOTHESIS TESTING: CONFIDENCE INTERVALS, T-TESTS, ANOVAS, AND REGRESSION

EXST SAS Lab Lab #4: Data input and dataset modifications

7. Comparing Means Using t-tests.

1. What is the critical value for this 95% confidence interval? CV = z.025 = invnorm(0.025) = 1.96

Experimental Design for Influential Factors of Rates on Massive Open Online Courses

Two Related Samples t Test

Data Analysis Tools. Tools for Summarizing Data

Chapter 7 Section 1 Homework Set A

Two-Sample T-Tests Allowing Unequal Variance (Enter Difference)

Nonparametric Two-Sample Tests. Nonparametric Tests. Sign Test

t Tests in Excel The Excel Statistical Master By Mark Harmon Copyright 2011 Mark Harmon

How Does My TI-84 Do That

Chapter 2 Probability Topics SPSS T tests

Recall this chart that showed how most of our course would be organized:

Introduction. Hypothesis Testing. Hypothesis Testing. Significance Testing

Confidence Intervals for the Difference Between Two Means

12: Analysis of Variance. Introduction

NCSS Statistical Software

KSTAT MINI-MANUAL. Decision Sciences 434 Kellogg Graduate School of Management

Class 19: Two Way Tables, Conditional Distributions, Chi-Square (Text: Sections 2.5; 9.1)

General Method: Difference of Means. 3. Calculate df: either Welch-Satterthwaite formula or simpler df = min(n 1, n 2 ) 1.

Examining Differences (Comparing Groups) using SPSS Inferential statistics (Part I) Dwayne Devonish

Chapter 9. Two-Sample Tests. Effect Sizes and Power Paired t Test Calculation

UNDERSTANDING THE INDEPENDENT-SAMPLES t TEST

Chapter 7 Section 7.1: Inference for the Mean of a Population

HYPOTHESIS TESTING WITH SPSS:

Tutorial for proteome data analysis using the Perseus software platform

Two-Sample T-Tests Assuming Equal Variance (Enter Means)

An Introduction to Statistics Course (ECOE 1302) Spring Semester 2011 Chapter 10- TWO-SAMPLE TESTS

One-Way Analysis of Variance

Using Stata for One Sample Tests

SIMPLE LINEAR CORRELATION. r can range from -1 to 1, and is independent of units of measurement. Correlation can be done on two dependent variables.

Difference of Means and ANOVA Problems

Two-sample t-tests. - Independent samples - Pooled standard devation - The equal variance assumption

Chapter 5 Analysis of variance SPSS Analysis of variance

4 Other useful features on the course web page. 5 Accessing SAS

Testing for differences I exercises with SPSS

Linear Models in STATA and ANOVA

MULTIPLE REGRESSION EXAMPLE

Multiple-Comparison Procedures

SCHOOL OF HEALTH AND HUMAN SCIENCES DON T FORGET TO RECODE YOUR MISSING VALUES

UNDERSTANDING THE DEPENDENT-SAMPLES t TEST

Final Exam Practice Problem Answers

ABSORBENCY OF PAPER TOWELS

Chapter 7. Comparing Means in SPSS (t-tests) Compare Means analyses. Specifically, we demonstrate procedures for running Dependent-Sample (or

NCSS Statistical Software

Odds ratio, Odds ratio test for independence, chi-squared statistic.

Inference for two Population Means

Independent t- Test (Comparing Two Means)

Hypothesis testing - Steps

How Far is too Far? Statistical Outlier Detection

Testing Group Differences using T-tests, ANOVA, and Nonparametric Measures

Using Excel for inferential statistics

An SPSS companion book. Basic Practice of Statistics

Regression step-by-step using Microsoft Excel

Analysis of Variance ANOVA

Multiple Linear Regression

Outline. Definitions Descriptive vs. Inferential Statistics The t-test - One-sample t-test

Normality Testing in Excel

Simple Regression Theory II 2010 Samuel L. Baker

SPSS/Excel Workshop 3 Summer Semester, 2010

Two Correlated Proportions (McNemar Test)

Using R for Linear Regression

Once saved, if the file was zipped you will need to unzip it. For the files that I will be posting you need to change the preferences.

Regression Analysis: A Complete Example

Two-sample hypothesis testing, II /16/2004

Estimation of σ 2, the variance of ɛ

Unit 31 A Hypothesis Test about Correlation and Slope in a Simple Linear Regression

Chapter 8 Hypothesis Testing Chapter 8 Hypothesis Testing 8-1 Overview 8-2 Basics of Hypothesis Testing

Guide to Microsoft Excel for calculations, statistics, and plotting data

Tutorial 5: Hypothesis Testing

Unit 26 Estimation with Confidence Intervals

Chapter 2. Hypothesis testing in one population

Data Mining Techniques Chapter 5: The Lure of Statistics: Data Mining Using Familiar Tools

Comparing Multiple Proportions, Test of Independence and Goodness of Fit

Using SAS Mapping functionality to measure and present the Veracity of Location Data

3.4 Statistical inference for 2 populations based on two samples

Outline. Topic 4 - Analysis of Variance Approach to Regression. Partitioning Sums of Squares. Total Sum of Squares. Partitioning sums of squares

Module 5: Multiple Regression Analysis

13: Additional ANOVA Topics. Post hoc Comparisons

Projects Involving Statistics (& SPSS)

Chapter 7: Simple linear regression Learning Objectives

Predictor Coef StDev T P Constant X S = R-Sq = 0.0% R-Sq(adj) = 0.

This can dilute the significance of a departure from the null hypothesis. We can focus the test on departures of a particular form.

Paired 2 Sample t-test

Section 13, Part 1 ANOVA. Analysis Of Variance

Transcription:

EXST700X Lab Spring 014 EXST SAS Lab Lab #9: Two-sample t-tests Objectives 1. Input a CSV file (data set #1) and do a one-tailed two-sample t-test. Input a TXT file (data set #) and do a two-tailed two-sample t-test 3. Test the two classes in data set # for normality and obtain confidence intervals for each 4. Produce BOXPLOTS for the second data set In this week s assignment, working from a current folder and naming the HTML output data file are optional; good practices, but optional. Also, you will not have to deal with multiple observations on an input line. The example program does have multiple observations on a line, and two SAS work files will be created from one input file in order to compare the two-sample test to the one-sample test. However, this is not required as part of the assignment program. Recall that you can get the current folder by opening a SAS file from that directory. If you want to change the directory then double click on the directory (i.e. folder) name on the right side of the bottom bar of the SAS window and you can change it to whatever you want. The examples All examples and datasets for this assignment were drawn from Chapter 5 of Freund, Rudolph J. and William J. Wilson. 003. Statistical Methods, Academic Press, N.Y. The first data set in the example is a CSV file. This file has been used before (Exercise 5.3, Table 5.13) for the paired t-test. It is two areas of a city that were sampled simultaneously and were, therefore, paired. Now they will be analyzed as if they were not sampled simultaneously, but rather as if each area was sampled on different, randomly-selected date. You do not have to do this Obs AreaA AreaB diff 1.9 1.84 1.08 1.88 0.95 0.93 3 5.35 4.6 1.09 4 3.81 3.18 0.63 5 4.69 3.44 1.5 6 4.86 3.69 1.17 7 5.81 4.95 0.86 8 5.55 4.47 1.08 for the assignment; it is being done just to compare the previous paired t-test result to the two-sample t-test result. In the assignment you will only need to do two-sample t-tests. The Exercise 5.3 dataset had two separate columns for the two areas in order to calculate a difference for the paired t-test. I also output a second data set with a class (categorical or group) variable in order to do the two-sample t-test. This is from a previous lab exercise. data Multi (keep=areaa AreaB diff) Pollution (keep=area index); INFILE 'datatab_5_13b.csv' dlm=',' dsd missover firstobs=; input AreaA AreaB; diff = AreaA - AreaB; output multi; Area = 'A'; Index = AreaA; Output Pollution; Area = 'B'; Index = AreaB; Output Pollution; datalines; run; ; run; Page 1

EXST700X Lab Spring 014 Both tests were done as one-tailed tests with PROC TTEST as follows. Note that in your assignment you only need to run a t-test test similar to the second one below. PROC ttest data=multi sides=u; title 'Pollution example done as a paired t-test with Proc TTEST'; TITLE3 'One-tailed hypothesis'; VAR diff; RUN; PROC ttest data=pollution sides=u; title 'Pollution example done as a tw0-sample t-test with Proc TTEST'; TITLE3 'One-tailed hypothesis'; CLASS area; VAR Index; If you examine the values in the dataset above, it is pretty clear that the data is actually paired. When one area has a high index value, the other area is also relatively high. The two areas tend to go up and down together. The paired t-test (below) should have much less variance because it is the variance of the difference within a pair, not the variance based on the greater variation between individual observations. The resulting paired t-test standard error was 0.0698 and the t-value (14.49 with 7 d.f.) resulted in a rejection of the hypothesis of no difference (P<0.0001). The TTEST Procedure Variable: diff N Mean Std Dev Std Err Minimum Maximum 8 1.0113 0.1974 0.0698 0.6300 1.500 Mean 95% CL Mean Std Dev 95% CL Std Dev 1.0113 0.8790 Infty 0.1974 0.1305 0.4017 DF t Value Pr > t 7 14.49 <.0001 When the same data was tested as a two-sample t-test (below), the difference between the means was exactly the same (1.0113) but the standard error of the difference was 0.6843, almost 10 times larger. This difference is not calculated on the basis of the literal pairwise difference (e.g. di YA YB) like the paired t-test. The variance for the two-sample t-test is based on the linear combination of the variances for two separate groups, with or without a pooled variance (e.g. 1 1 p n1 n versus 1 ). The n1 n bottom line is that if the data is actually paired, a paired t-test should be better because it has a smaller variance and greater power. If, however, pairing is not justified, the variance will not be smaller but you will lose degrees of freedom in the t-test resulting in an overall loss of power. When PROC TTEST is used to do a two-sample t-test the first part provides some simple summary statistics. Area N Mean Std Dev Std Err Minimum Maximum A 8 4.3588 1.388 0.4889 1.88 5.81 B 8 3.3475 1.3541 0.4787 0.95 4.95 Diff (1 ) 1.0113 1.3685 0.6843 The second part provides means, standard deviations and confidence intervals for those statistics. Note that the calculations on the differences are not tests of the variable DIFF that we calculated in the data step. Page

EXST700X Lab Spring 014 These differences are done on the two variables to be tested by the TTEST procedure. The SAS program does not try to determine if the variances are equal or not, partly because it does not know what level of you wish to use to make that decision. Instead, it simply calculates both options. In this case the difference in the variances (or standard deviations) for the two categories is very small, so the Satterthwaite calculation produces results are almost identical to the results for pooled variance version. Area Method Mean 95% CL Mean Std Dev 95% CL Std Dev A 4.3588 3.07 5.5148 1.388 0.914.8143 B 3.3475.154 4.4796 1.3541 0.8953.756 Diff (1 ) Pooled 1.0113 0.1939 Infinity 1.3685 1.0019.1583 Diff (1 ) Satterthwaite 1.0113 0.194 Infinity Likewise, in doing the t-test calculations, SAS does not know if you want to call the variances equal or not, so it does the calculations both ways. There are two different solutions for each two-sample t-test. One for pooled variances, 1 1 p n1 n, and the other for separate variances, 1. The decision n1 n on pooling variances depends on the test of the equality of variances ( H0 : 1 ) which the PROC TTEST provides in the last lines of the analysis. You would use this F test of the equality of variances to determine which of the two t-test solutions is appropriate. In this case the results are nearly identical because the variances for the two areas are nearly identical. Method Variances DF t Value Pr > t Pooled Equal 14 1.48 0.0808 Satterthwaite Unequal 13.994 1.48 0.0808 Equality of Variances Method Num DF Den DF F Value Pr > F Folded F 7 7 1.04 0.9574 This particular test of the equality of variances ( H0 : 1 ) is a two-tailed F test, which SAS refers to as a Folded F test. The vast majority of F tests that are done in SAS, and elsewhere, for analysis of variance and regression analyses are one-tailed F tests. Example The second example (5_17 from your textbook) is new. It has to do with the life expectancy of light bulbs. A person has to buy a large shipment of bulbs. She first buys 40 of each brand and subjects them to an accelerated life test to determine which last longer. This is a two-tailed test because before the test we have no particular expectation of which brand might be better. The input is relatively simple and straight forward. However, remember, when inputting an external file with INFILE, a CSV file needs the options DLM=, and DSD. A TXT file does not need either of these options and won t work properly if they are present. Pay attention to which type of file you are inputting. Class variables are sometimes called categorical, group or dummy variables. A variable that is going to represent classes can be either a numeric or a character variable. Either one will become a class variable when placed in a SAS CLASS statement. When dealing with class variables, it is not unusual that they will be character variables and will need that $ sign in INPUT and LENGTH statements. Page 3

EXST700X Lab Spring 014 data bulbs; INFILE 'datatab_5_17.txt' missover firstobs=; input brand $ life; datalines; run; ; run; Once the data was input the two-tailed t-test is relatively straight forward. PROC ttest data=bulbs; CLASS brand; VAR life; title "The two-sample t-test"; TITLE3 'Two-tailed hypothesis'; RUN; The results of the FOLDED F test indicated a highly significant difference in the variances ( H1: 1, P<0.0001). The variances were therefore not pooled. The resulting test of the means, using a Satterthwaite adjustment due to unequal variances, indicated a significant difference between the means ( H0 : 1, P=0.004). Note that when the Satterthwaite adjustment is used the degrees of freedom are not usually round integer values. Method Variances DF t Value Pr > t Pooled Equal 78.41 0.0184 Satterthwaite Unequal 4.88.41 0.004 Equality of Variances Method Num DF Den DF F Value Pr > F Folded F 39 39 0.05 <.0001 Finally, I requested a univariate analysis of the sorted data. Here, my objectives were to obtain confidence intervals and tests of normality. Since there are two datasets, and the variances are not equal, we will need to examine each separately for normality, hence the BY statement. proc sort data=bulbs; by brand; run; PROC UNIVARIATE data=bulbs normal plots CIBASIC; by brand; VAR life; ods exclude BasicMeasures ExtremeObs Quantiles Modes ExtremeValues MissingValues TestsForLocation; RUN; When the PROC UNIVARIATE is run with a BY statement, the procedure provides side-by-side box plots for comparison. It is clear that one of the two samples has what appears to have a larger variance and a possible outlier (i.e. an excessively large or small observation). The results of the confidence interval request and test of normality for the first dataset are given below. Basic Confidence Limits Assuming Normality Parameter Estimate 95% Confidence Limits Mean 153 1416 1648 Std Deviation 36.7884 97.18198 465.8398 Variance 131615 88317 17000 Schematic Plots 800+ 0 600+ 400+ 00+ 000+ 1800+ +-----+ 1600+ + *-----* +-----+ 1400+ *--+--* +-----+ +-----+ 100+ 1000+ 800+ -----+-----------+-- brand a b Page 4

EXST700X Lab Spring 014 Tests for Normality Test --Statistic--- -----p Value------ Shapiro-Wilk W 0.950104 Pr < W 0.0765 Kolmogorov-Smirnov D 0.10359 Pr > D >0.1500 Cramer-von Mises W-Sq 0.06043 Pr > W-Sq >0.500 Anderson-Darling A-Sq 0.419408 Pr > A-Sq >0.500 Both the first and second data set showed similar results for normality (not rejected) but an apparently smaller level of variability in the second data set. Basic Confidence Limits Assuming Normality Parameter Estimate 95% Confidence Limits Mean 1390 1365 1416 Std Deviation 81.0301 66.37679 104.04566 Variance 6566 4406 1086 Tests for Normality Test --Statistic--- -----p Value------ Shapiro-Wilk W 0.95697 Pr < W 0.150 Kolmogorov-Smirnov D 0.13837 Pr > D 0.0517 Cramer-von Mises W-Sq 0.0789 Pr > W-Sq >0.500 Anderson-Darling A-Sq 0.473393 Pr > A-Sq 0.358 Based on the graphics, the observations range from about 100 to 1500 in data set b and from about 900 to 700 in data set a, but only one value in the second data set is much over 000. Recall that the t-test for these two data sets showed a significantly difference variance (P<0.0001) and a significant difference in the means (P=0.004). I was curious if the large variance and significant difference could be caused entirely by the single potential outlier. I removed the outlier by including in the data step the statement. if life gt 500 then delete; This will remove any observation with a value of LIFE greater than 500, but of course only one value that is that large; the suspected outlier. The conditional options that can be used in an IF statement are the following (GT for greater than, LT for less than, GE for greater than or equal, LE for less than or equal, EQ or equal and NE or not equal). After removing the potential outlier the results were as follows: Method Variances DF t Value Pr > t Pooled Equal 77.18 0.030 Satterthwaite Unequal 43.056.16 0.0364 Equality of Variances Method Num DF Den DF F Value Pr > F Folded F 38 39 14.60 <.0001 The overall results actually did not change. The hypotheses of equal variances and equal means are still rejected. The variances are somewhat closer and the F test statistic has fallen from 0 to 14, but the resulting test indicates that the variances are still highly significantly different ( H :, P<0.0001). 1 1 Page 5

EXST700X Lab Spring 014 Assignment 9 The first dataset for the assignment (Exercise 5.1, Table 5.1 from Freund, Rudolph J., William J. Wilson and Donna L. Mohr. 010. Statistical Methods. Academic Press (ELSIVIER), N.Y.) is data for a statistics class with two sections that were each taught with different methods. We want to test the hypothesis that the test scores for the first method (a) are higher than the second (b). You do not need to output two datasets or arrange a univariate type data set, the data already comes that way. Answer all questions about hypothesis tests by stating the outcome (REJECT the null hypothesis or FAIL to reject the null hypothesis) and Give a P-value where a relevant P-value is available. Turn in your log and the list output or results viewer output. You may write answers to questions on the log, or on a separate page. Task 1: Run a one-tailed two-sample t-test against the upper tail of stat teaching method a versus stat teaching method b (e.g. H : 1 a b or H 1 : a b 0). Note that by default SAS will subtract the second name in alphabetical order from the first (e.g. meana meanb)... (1 point) Question 1: If there is not a statistically significant difference between the variances then they can be pooled. Should the variances be pooled for this analysis?... (1 point) Question : Is there a significant difference between the means?... (1 point) Task : Your second dataset (Exercise 5.13, Table 5.19) examines the half-life of a two drugs of the class Aminoglycosides, Amikacin and Gentamicin, coded as A and G respectively. This will be a two-tailed t-test. In addition to testing the means for equality we will check the assumption of normality. Task : Do a two sample t-test of the differences between the drugs.... (1 point) Question 1: If there is not a statistically significant difference between the variances then they can be pooled. Should the variances be pooled for this analysis?... (1 point) Question : Is there a significant difference between the means?... (1 point) Task 3: Finally, using the dataset from Exercise 5.13, Table 5.19, sort by the two drugs and run a PROC UNIVARIATE analysis BY the drug variable producing two outputs, one for each drug. Include in the univariate analysis the confidence intervals, plots and test of normality.... (1 point) Question 5: Is the hypothesis of normality rejected for either of the two samples?... (1 point) Question 6: Do the bounds on the confidence interval for the standard deviation appear to be just the square root of the bounds on the confidence interval limits of the variance or is some other calculation involved?... (1 point) Task 4: Prepare a PROC BOXPLOT for the two classes of the second data set.... (1 point) Page 6