Two sample Hypothesis tests in R.

Similar documents
Independent Samples t tests. Background for Independent Samples t test

An Analysis of College Algebra Exam Scores December 14, James D Jones Math Section 01

Sampling Distributions: Central Limit Theorem

Chapter 7 Comparison of two independent samples

CIVL /8904 T R A F F I C F L O W T H E O R Y L E C T U R E - 8

Epidemiology Principles of Biostatistics Chapter 10 - Inferences about two populations. John Koval

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

Chapter 26: Comparing Counts (Chi Square)

T-tests for 2 Independent Means

T-tests for 2 Independent Means

Chapter 20 Comparing Groups

Chapter 9. Inferences from Two Samples. Objective. Notation. Section 9.2. Definition. Notation. q = 1 p. Inferences About Two Proportions

Hypothesis testing: Steps

# of 6s # of times Test the null hypthesis that the dice are fair at α =.01 significance

The Difference in Proportions Test

We d like to know the equation of the line shown (the so called best fit or regression line).

Two sided, two sample t-tests. a) IQ = 100 b) Average height for men = c) Average number of white blood cells per cubic millimeter is 7,000.

Introduction to Business Statistics QM 220 Chapter 12

Confidence intervals

Module 03 Lecture 14 Inferential Statistics ANOVA and TOI

Hypothesis testing: Steps

AMS7: WEEK 7. CLASS 1. More on Hypothesis Testing Monday May 11th, 2015

Soci Data Analysis in Sociological Research. Homework 4 Computer Handout. Chapter 19 Confidence Intervals for Proportions

One sided tests. An example of a two sided alternative is what we ve been using for our two sample tests:

HYPOTHESIS TESTING. Hypothesis Testing

The One-Way Independent-Samples ANOVA. (For Between-Subjects Designs)

16.400/453J Human Factors Engineering. Design of Experiments II

HYPOTHESIS TESTING SAMPLING DISTRIBUTION

STATISTICS ASSIGNMENT 2

Power. January 12, 2019

Psych 230. Psychological Measurement and Statistics

Advanced Experimental Design

Inferences Based on Two Samples

Confidence Intervals with σ unknown

Lab #12: Exam 3 Review Key

STAT 350 Final (new Material) Review Problems Key Spring 2016

Exam 2 (KEY) July 20, 2009

INTRODUCTION TO ANALYSIS OF VARIANCE

The t-test: A z-score for a sample mean tells us where in the distribution the particular mean lies

Population 1 Population 2

An Introduction to Path Analysis

Hypothesis testing I. - In particular, we are talking about statistical hypotheses. [get everyone s finger length!] n =

ANOVA - analysis of variance - used to compare the means of several populations.

Note that we are looking at the true mean, μ, not y. The problem for us is that we need to find the endpoints of our interval (a, b).

Binary Logistic Regression

STA 4504/5503 Sample Exam 1 Spring 2011 Categorical Data Analysis. 1. Indicate whether each of the following is true (T) or false (F).

MATH Notebook 3 Spring 2018

An inferential procedure to use sample data to understand a population Procedures

CBA4 is live in practice mode this week exam mode from Saturday!

Section 9.4. Notation. Requirements. Definition. Inferences About Two Means (Matched Pairs) Examples

where Female = 0 for males, = 1 for females Age is measured in years (22, 23, ) GPA is measured in units on a four-point scale (0, 1.22, 3.45, etc.

Inferences About the Difference Between Two Means

Simple Linear Regression: One Qualitative IV

9/28/2013. PSY 511: Advanced Statistics for Psychological and Behavioral Research 1

STA 4504/5503 Sample Exam 1 Spring 2011 Categorical Data Analysis. 1. Indicate whether each of the following is true (T) or false (F).

Chapter 19: Logistic regression

Sociology 593 Exam 2 Answer Key March 28, 2002

Confidence Intervals. - simply, an interval for which we have a certain confidence.

Categorical Data Analysis. The data are often just counts of how many things each category has.

Problem Set 4 - Solutions

Hypothesis testing. Data to decisions

Is there a connection between gender, maths grade, hair colour and eye colour? Contents

Power and sample size calculations

Lecture 26: Chapter 10, Section 2 Inference for Quantitative Variable Confidence Interval with t

Area1 Scaled Score (NAPLEX) .535 ** **.000 N. Sig. (2-tailed)

Contingency Tables. Safety equipment in use Fatal Non-fatal Total. None 1, , ,128 Seat belt , ,878

22s:152 Applied Linear Regression

Statistics Primer. ORC Staff: Jayme Palka Peter Boedeker Marcus Fagan Trey Dejong

Department of Economics. Business Statistics. Chapter 12 Chi-square test of independence & Analysis of Variance ECON 509. Dr.

Chapter 22. Comparing Two Proportions 1 /29

The t-statistic. Student s t Test

Non-Inferiority Tests for the Ratio of Two Proportions in a Cluster- Randomized Design

Originality in the Arts and Sciences: Lecture 2: Probability and Statistics

Testing a Claim about the Difference in 2 Population Means Independent Samples. (there is no difference in Population Means µ 1 µ 2 = 0) against

P-values and statistical tests 3. t-test

INTERVAL ESTIMATION OF THE DIFFERENCE BETWEEN TWO POPULATION PARAMETERS

Week 14 Comparing k(> 2) Populations

Chapter 7. Practice Exam Questions and Solutions for Final Exam, Spring 2009 Statistics 301, Professor Wardrop

COMPARING SEVERAL MEANS: ANOVA

Department of Mathematics & Statistics STAT 2593 Final Examination 17 April, 2000

Chapter 10: STATISTICAL INFERENCE FOR TWO SAMPLES. Part 1: Hypothesis tests on a µ 1 µ 2 for independent groups

Business Analytics and Data Mining Modeling Using R Prof. Gaurav Dixit Department of Management Studies Indian Institute of Technology, Roorkee

Chapter 5: HYPOTHESIS TESTING

Note that we are looking at the true mean, μ, not y. The problem for us is that we need to find the endpoints of our interval (a, b).

Chapter 23. Inferences About Means. Monday, May 6, 13. Copyright 2009 Pearson Education, Inc.

Chapter 22. Comparing Two Proportions 1 /30

Statistics: revision

STP 226 EXAMPLE EXAM #3 INSTRUCTOR:

First we look at some terms to be used in this section.

Sampling distribution of t. 2. Sampling distribution of t. 3. Example: Gas mileage investigation. II. Inferential Statistics (8) t =

Review. One-way ANOVA, I. What s coming up. Multiple comparisons

Contrasts (in general)

Chapter 8 Student Lecture Notes 8-1. Department of Economics. Business Statistics. Chapter 12 Chi-square test of independence & Analysis of Variance

Statistical Inference for Means

T-Test QUESTION T-TEST GROUPS = sex(1 2) /MISSING = ANALYSIS /VARIABLES = quiz1 quiz2 quiz3 quiz4 quiz5 final total /CRITERIA = CI(.95).

Multiple Regression Analysis

Descriptive Statistics-I. Dr Mahmoud Alhussami

hypotheses. P-value Test for a 2 Sample z-test (Large Independent Samples) n > 30 P-value Test for a 2 Sample t-test (Small Samples) n < 30 Identify α

Class 24. Daniel B. Rowe, Ph.D. Department of Mathematics, Statistics, and Computer Science. Marquette University MATH 1700

Chapter 7: Correlation

Transcription:

Example. (Dependent samples) Two sample Hypothesis tests in R. A Calculus professor gives their students a 10 question algebra pretest on the first day of class, and a similar test towards the end of the course. The idea is that while taking Calculus, maybe the students would remember some long forgotten things from algebra. The results are below. Student pretest posttest 1 1 2 2 8 9 3 9 8 4 5 6 5 7 8 6 3 5 7 10 10 Determine whether the students performed significantly better on the posttest, using.05. Assume differences in scores would be normally distributed, and the only plausible alternate hypothesis of interest is an improvement on the posttest (a semester of Calculus surely won t make students worse at doing algebra!). Solution 1. > # create a dataframe with pretest and posttest data > pretest = c(1,8,9,5,7,3,10) > posttest = c(2,9,8,6,8,5,10) > Calculus = data.frame(pretest, posttest) > Calculus pretest posttest 1 1 2 2 8 9 3 9 8 4 5 6 5 7 8 6 3 5 7 10 10 > # Compute differences between the pretest and posttest > d = posttest pretest > d [1] 1 1 1 1 1 2 0 > # Test whether d tends to be positive, against the null that d = 0 > t.test(d, alternative = 'greater', mu = 0, conf.level =.95) One Sample t test

data: d t = 1.9868, df = 6, p value = 0.04707 alternative hypothesis: true mean is greater than 0 0.01568146 Inf mean of x 0.7142857 Since the p value is less than the chosen alpha, we reject the null hypothesis (that there is no difference between the pre and post tests) and conclude that overall the students did significantly better on the post test at the 5% level. Solution 2. This can be done a bit more efficiently. > t.test(calculus$posttest, Calculus$pretest, alternative='greater', conf.level=.95, paired=true) Paired t test data: Calculus$posttest and Calculus$pretest t = 1.9868, df = 6, p value = 0.04707 alternative hypothesis: true difference in means is greater than 0 0.01568146 Inf mean of the differences 0.7142857 The general syntax is t.test(dataset1, dataset2, alternative, conf.level, paired). The first two (ordered) arguments are the sets of data to be used (here two vectors of the data frame we ve named Calculus). Setting alternative = greater specifies that the alternate hypothesis is that the mean of dataset1 is greater than the mean of dataset2. Putting paired = TRUE tells R that we are directly comparing (sideby side if you will) each pair of data points in the two chosen vectors.

On the other hand, sometimes a side by side comparison of data in this manner would be nonsensical or impossible. Example. Dr. Smith is teaching two sections of statistics, with 15 and 19 students respectively. The grades on an exam are as follows. Section 1: 100,95,90,90,90,90,85,83,80,79,71,71,70,66,48 Section 2: 100,100,100,100,98,98,98,93,93,90,86,83,81,79,79,76,61,48,41 One of the classes asks if they did significantly better or worse on the exam than the other class. Using.10, what should Smith tell them? Doing some calculation (I ll omit the R code which creates the necessary vectors) > numsummary(section1) mean sd 0% 25% 50% 75% 100% n 80.53333 13.46353 48 71 83 90 100 15 > numsummary(section2) mean sd 0% 25% 50% 75% 100% n 84.42105 17.65193 41 79 90 98 100 19 The question is now whether this roughly 4 point difference in mean score between the two classes is any big deal statistically. However, a side by side comparison of the exam scores would make no sense in this situation (these are two independent samples of data!). > t.test(section1, section2, alternative="two.sided", paired=false, var.equal=false) Welch Two Sample t test data: section1 and section2 t = 0.7284, df = 31.977, p value = 0.4716 alternative hypothesis: true difference in means is not equal to 0 14.759210 6.983771 mean of x mean of y 80.53333 84.42105 We use a two sided test since there was no initial inclination that section 1 was superior (or inferior) to section 2. We set paired=false since we do not want a side by side comparison of the data (in fact, R will inform you that this makes no damn sense if you ask it for the paired test). var.equal = FALSE means we do not assume that the two sets of data have the same variance (same standard deviation). This is a technical issue in calculating the t statistic; many textbooks would call this assumption not pooling the data. In any event, since the p value is not less than alpha, we do not reject the null and conclude there s no significant difference between the exam results in the two classes.

About using the t.test In the previous example, > t.test(section1,section2,paired=false) gives the output Welch Two Sample t test data: section1 and section2 t = 0.7284, df = 31.977, p value = 0.4716 alternative hypothesis: true difference in means is not equal to 0 14.759210 6.983771 mean of x mean of y 80.53333 84.42105 Note that not specifying an alternate hypothesis defaults to a two tailed test, and var.equal automatically defaults to FALSE, as these are the most conservative assumptions. Example. Comparing proportions in two different samples the artificially simple example. A drug company has manufactured a topical compound which is meant to cure certain skin infections. 200 patients with infections are given the treatment and it is found that in 145 of them, the condition had vanished within six days of the treatment. 200 patients with the infection are given a placebo, and 158 of them see the condition vanish within six days. Test whether the cure rate with the treatment is significantly different than with the placebo, using.01. > prop.test(c(145,158), c(200,200), alternative="two.sided", conf.level=.99) 2 sample test for equality of proportions with continuity correction data: c(145, 158) out of c(200, 200) X squared = 1.9598, df = 1, p value = 0.1615 alternative hypothesis: two.sided 99 percent confidence interval: 0.18008092 0.05008092 prop 1 prop 2 0.725 0.790 Because of the high p value, we do not reject the null; this sample does not convince us that the treatment is significantly different from the placebo at the 1% significance level.

Example. Comparing proportions in two different samples a more real example. Here, I ve created a data frame called Success. The idea is that a group of 20 students took a course, and the gender of each student was noted, as was whether or not they passed the course. The question is whether there is a significant difference in the pass rate between males and females. > Success gender passed 1 M Y 2 M N 3 M N 4 F Y 5 F N 6 F Y 7 F Y 8 F N 9 M Y 10 M N 11 F Y 12 F Y 13 F N 14 M N 15 F N 16 F N 17 M Y 18 F N 19 F Y 20 F Y Given a data frame with non numeric entries, the table command will create a 2x2 table summarizing the relationships between two of the variables in the data frame. The syntax is intuitive, so I won t comment further on that. > table(success$gender, Success$passed) N Y F 6 7 M 4 3 You can see that there were 13 females, of which 7 passed, and there were 7 males, of which 3 passed. Here, it should be apparent that the sample sizes are far too small to make any conclusions, but let s proceed anyway.

> prop.test(table(success$gender, Success$passed), correct=false) Warning in prop.test(table(success$gender, Success$passed), correct = FALSE) : Chi squared approximation may be incorrect 2 sample test for equality of proportions without continuity correction data: table(success$gender, Success$passed) X squared = 0.2198, df = 1, p value = 0.6392 alternative hypothesis: two.sided 0.5657762 0.3459960 prop 1 prop 2 0.4615385 0.5714286 In case it wasn t obvious (the difference in pass rate between men and women is only 11% in a sample of size twenty!), the high p value tells us that on the basis of this sample, we cannot conclude that there is any significant difference in pass rate between men and women. Note that correct=false means we used no continuity correction, but since many of the cell sizes were small in our tabled data, R warns us that not using the continuity correction is probably a bad idea (in fact the p value is probably even higher than.6392).