Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 5 Hypothesis testing and Confidence Interval.

Similar presentations


Presentation on theme: "Lab 5 Hypothesis testing and Confidence Interval."— Presentation transcript:

1

2 Lab 5 Hypothesis testing and Confidence Interval

3 Outline One sample t-test Two sample t-test Paired t-test

4 Lab 5 One-sample t-test

5 One sample t-test The hypotheses : One sided Two sided

6 One sample t-test Test statistics

7 One sample t-test Conclusion Compare the test statistics with the critical value … Compare the p-value with the level of significance α (e.g. 0.05, 0.1) Reject H 0 if p-value < α (enough evidence) Cannot reject H 0 if p-value > α (not enough evidence)

8 Example Download the biotest.txt data file Read into R using function read.table() Extract the 1 st column and store as ‘X1’ Store the 2 nd column as ‘X2’

9 Example > X1 = read.table(“biotest.txt”) [,1] > X2 = read.table(“biotest.txt”) [,2]

10 Example Take ‘X1’ as the sample in this case, Test H 0 : μ = 115 against H 1 : μ ≠ 115 at significant level α = 0.05

11 [R] command t.test() Syntax: t.test(x=“data”, alternative = “less / greater / two.sided”, mu=“μ 0 ” )

12 Example 1 > t.test(X1, alternative = “two.sided”, mu=115) One Sample t-test data: X1 t = 0.1841, df = 9, p-value = 0.858 alternative hypothesis: true mean is not equal to 115 95 percent confidence interval: 108.2257 122.9743 sample estimates: mean of x 115.6

13 Example 1 > t.test(X1, alternative = “two.sided”, mu=115) One Sample t-test data: X1 t = 0.1841, df = 9, p-value = 0.858 alternative hypothesis: true mean is not equal to 115 95 percent confidence interval: 108.2257 122.9743 sample estimates: mean of x 115.6

14 Example 1 > t.test(X1, alternative = “two.sided”, mu=115) One Sample t-test data: X1 t = 0.1841, df = 9, p-value = 0.858 alternative hypothesis: true mean is not equal to 115 95 percent confidence interval: 108.2257 122.9743 sample estimates: mean of x 115.6 larger than 0.05 Cannot reject H 0 at 0.05 level of significance

15 Example 1 > t.test(X1, alternative = “two.sided”, mu=115) One Sample t-test data: X1 t = 0.1841, df = 9, p-value = 0.858 alternative hypothesis: true mean is not equal to 115 95 percent confidence interval: 108.2257 122.9743 sample estimates: mean of x 115.6 μ 0 inside the 95% CI

16 Example 2 Test H 0 : μ ≤ 108 against H 1 : μ > 108 at significant level α = 0.05

17 Example 2 > t.test(X1, alternative = “greater”, mu=108) One Sample t-test data: X1 t = 2.3314, df = 9, p-value = 0.02232 alternative hypothesis: true mean is greater than 108 95 percent confidence interval: 109.6243 Inf sample estimates: mean of x 115.6

18 Example 2 > t.test(X1, alternative = “greater”, mu=108) One Sample t-test data: X1 t = 2.3314, df = 9, p-value = 0.02232 alternative hypothesis: true mean is greater than 108 95 percent confidence interval: 109.6243 Inf sample estimates: mean of x 115.6 smaller than 0.05 Reject H 0 at 0.05 level of significance

19 Example 2 Conclude that the population mean is significantly greater than 108

20 Example 2 > t.test(X1, alternative = “greater”, mu=108) One Sample t-test data: X1 t = 2.3314, df = 9, p-value = 0.02232 alternative hypothesis: true mean is greater than 108 95 percent confidence interval: 109.6243 Inf sample estimates: mean of x 115.6 Statistical significance vs. Practical significance

21 Confidence Interval By default, the function t.test() includes a 95% confidence interval Question: Can we change the confidence level?

22 Confidence Interval e.g. want a 99% confidence interval > t.test(x1, alternative=“greater”, mu=108, conf.level = 0.99)

23 Lab 5 Two-sample t-test

24 Testing the population mean of two independent samples

25 Two-sample t-test Two-sided One-sided

26 Example 3 Consider the two sample X1 and X2 Want to test if there is there is a significant difference between the mean of X1 and mean of X2.

27 Example 3 Two sided test H 0 : μ 1 = μ 2 against H 1 : μ 1 ≠ μ 2 at 0.05 level of significance Assuming equal variance

28 Example 3 > t.test(X1, X2, alternative = “two.sided”, var.equal = TRUE) Two Sample t-test data: X1 and X2 t = -0.9052, df = 18, p-value = 0.3773 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -15.940831 6.340831 sample estimates: mean of x mean of y 115.6 120.4

29 Example 3 > t.test(X1, X2, alternative = “two.sided”, var.equal = TRUE) Two Sample t-test data: X1 and X2 t = -0.9052, df = 18, p-value = 0.3773 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -15.940831 6.340831 sample estimates: mean of x mean of y 115.6 120.4

30 Example 3 Not assuming equal variance? > t.test(X1, X2, alternative = “two.sided”, var.equal = FALSE)

31 Lab 5 Paired t-test

32 Two samples problem But they are no longer independent Example: Measurement taken twice at different time point from the same group of subjects Blood pressure before and after some treatment Want to test the difference of the means

33 Paired t-test If we take the difference of the measurements of each subject. Reduce to a one sample problem The rest is the same as a one sample t-test X1 X2 X3 X4 y1 y2 y3 y4 -= d1 d2 d3 d4

34 Example 4 Consider again the dataset X1 and X2, and assume they are pairwise observations Test the equality of the means i.e. test if difference in mean = 0 H 0 : μ 1 = μ 2 against H 1 : μ 1 ≠ μ 2 at 0.05 level of significance

35 Example 4 > t.test(X1, X2, alternative = “two.sided”, paired = TRUE) Paired t-test data: X1 and X2 t = -3.3247, df = 9, p-value = 0.008874 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -8.066013 -1.533987 sample estimates: mean of the differences -4.8

36 Example 4 > t.test(X1, X2, alternative = “two.sided”, paired = TRUE) Paired t-test data: X1 and X2 t = -3.3247, df = 9, p-value = 0.008874 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -8.066013 -1.533987 sample estimates: mean of the differences -4.8

37 Alternatively… > t.test(X1-X2, alternative = “two.sided”) One Sample t-test data: X1 - X2 t = -3.3247, df = 9, p-value = 0.008874 alternative hypothesis: true mean is not equal to 0 95 percent confidence interval: -8.066013 -1.533987 sample estimates: mean of x -4.8

38 Alternatively… > t.test(X1-X2, alternative = “two.sided”) One Sample t-test data: X1 - X2 t = -3.3247, df = 9, p-value = 0.008874 alternative hypothesis: true mean is not equal to 0 95 percent confidence interval: -8.066013 -1.533987 sample estimates: mean of x -4.8 EXACTLY THE SAME RESULT!!

39 Final Remarks Notice that the conclusion from the two sample t-test and the paired t-test are different even if we are looking at the same data set. Should check if the two sample are independent or not

40 Final Remarks Using the wrong test either lead to loss of sensitivity or invalid analysis.


Download ppt "Lab 5 Hypothesis testing and Confidence Interval."

Similar presentations


Ads by Google