Upcoming SlideShare
×

# Statr session 21 and 22

507 views
280 views

Published on

Praxis Weekend Analytics Program

Published in: Education
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
507
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
13
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Statr session 21 and 22

1. 1. Learning Objectives • Understand the 2 goodness-of-fit test and how to use it. • Analyze data using the 2 test of independence. • Recognize the advantages and disadvantages of nonparametric statistics. • Understand how to use the runs test to test for randomness. • Know when and how to use the Mann-Whitney U test, the Wilcoxon matched-pairs signed rank test, the Kruskal-Wallis test, and the Friedman test. • Learn when and how to measure correlation using Spearman’s rank correlation measurement.
2. 2. 𝜒 2 Goodness-of-Fit Test • The Chi-square 𝜒 2 goodness-of-fit test compares expected (theoretical) frequencies of categories from a population distribution to the observed (actual) frequencies from a distribution to determine whether there is a difference between what was expected and what was observed. • Chi-square goodness-of-fit test is used to analyze probabilities of multinomial distribution trials along a single dimension.
3. 3. 𝜒 2 Goodness-of-Fit Test The formula which is used to compute the test statistic for a chi-square goodness-of-fit test is given below.
4. 4. 𝜒 2 Goodness-of-Fit Test • The formula compares the frequency of observed values to the frequency of the expected values across the distribution. – Test loses one degree of freedom because the total number of expected frequencies must equal the number of observed frequencies • The chi-square distribution is the sum of the squares of k independent random variables. – Can never be less than zero; it extends indefinitely in the positive direction
5. 5. Milk Sales Data for Demonstration Problem 16.1 Dairies would like to know whether the sales of milk are distributed uniformly over a year so they can plan for milk production and storage. A uniform distribution means that the frequencies are the same in all categories. In this situation, the producers are attempting to determine whether the amounts of milk sold are the same for each month of the year. They ascertain the number of gallons of milk sold by sampling one large supermarket each month during a year, obtaining the following data. Use .01 to test whether the data fit a uniform distribution.
6. 6. Milk Sales Data for Demonstration Problem 16.1 Month January February March April May June July August September October November December Gallons 1,610 1,585 1,649 1,590 1,540 1,397 1,410 1,350 1,495 1,564 1,602 1,655 18,447
7. 7. Hypotheses and Decision Rules for Demonstration Problem 16.1 Ho : The monthly figures for milk sales are uniformly distribute d Ha : The monthly figures for milk sales are not uniformly distribute d  .01 df  k  1  c  12  1  0  11  2 .01,11  24.725 If If   2 Cal 2 Cal  24.725, reject Ho.  24.725, do not reject Ho.
8. 8. Calculations for Demonstration Problem 16.1 Month January February March April May June July August September October November December fo fe (fo - fe)2/fe 1,610 1,537.25 3.44 1,585 1,537.25 1.48 1,649 1,537.25 8.12 1,590 1,537.25 1.81 1,540 1,537.25 0.00 1,397 1,537.25 12.80 1,410 1,537.25 10.53 1,350 1,537.25 22.81 1,495 1,537.25 1.16 1,564 1,537.25 0.47 1,602 1,537.25 2.73 1,655 1,537.25 9.02 18,447 18,447.00 74.38
9. 9. Calculations for Demonstration Problem 16.1 • The observed chi-square value of 74.37 is greater than the critical value of 24.725. • The decision is to reject the null hypothesis. The data provides enough evidence to indicate that the distribution of milk sales is not uniform.
10. 10. Calculations for Demonstration Problem 16.1
11. 11. 𝜒 2 Test of Independence • Chi-square goodness-of-fit test – is used to analyze the distribution of frequencies for categories of one variable to determine whether the distribution of these frequencies is the same as some hypothesized or expected distribution. • The goodness-of-fit test cannot be used to analyze two variables simultaneously. • Chi-square test of independence – is used to analyze the frequencies of two variables with multiple categories to determine whether the two variables are independent.
12. 12. 𝜒 2 Test of Independence • Different chi-square test, the chi-square test of independence, can be used to analyze the frequencies of two variables with multiple categories to determine whether the two variables are independent. • Used to analyze the frequencies of two variables with multiple categories to determine whether the two variables are independent • Two random variables x and y are called independent if the probability distribution of one variable is not affected by the presence of another.
13. 13. 𝜒 2 Test of Independence Assume fij is the observed frequency count of events belonging to both i-th category of x and j-th category of y. Also assume eij to be the corresponding expected count if x and y are independent. The null hypothesis of the independence assumption is to be rejected if the p-value of the following Chi-square test statistics is less than a given significance level α. (𝑓 𝑖𝑗 −𝑒 𝑖𝑗 )2 𝑒 𝑖𝑗 𝜒2 = 𝑖,𝑗
14. 14. 𝜒 2 Test of Independence: Gasoline Preference Versus Income Category Suppose a business researcher wants to determine whether type of gasoline preferred is independent of a person’s income. She takes a random survey of gasoline purchasers, asking them one question about gasoline preference and a second question about income. The respondent checks which gasoline he or she prefers: (1) regular, (2) premium, or (3) extra premium. The respondent also is to check his or her income brackets as being (1) < \$30,000, (2) \$30,000 to \$49,999, (3) \$50,000 to \$99,999, or (4) > \$100,000.
15. 15. 𝜒 2 Test of Independence: Type of Gasoline Versus Income Category Hypotheses: Using α = .01, she uses the chi-square test of independence to determine whether type of gasoline preferred is independent of income level.
16. 16. 𝜒 2 Test of Independence: Type of Gasoline Versus Income Category r=4 Income Less than \$30,000 \$30,000 to \$49,999 \$50,000 to \$99,000 At least \$100,000 Type of Gasoline c=3 Regular Premium Extra Premium
17. 17. Gasoline preference Versus Income Category: Observed Frequencies Type of Gasoline Income Less than \$30,000 \$30,000 to \$49,999 \$50,000 to \$99,000 At least \$100,000 Regular Premium 85 16 102 27 36 22 15 23 238 88 Extra Premium 6 13 15 25 59 107 142 73 63 385
18. 18. Gasoline preference Versus Income Category: Observed Frequencies e n n   i ij  11 e e 12 N 107 238  107 88  385  24 .46  13 e j 385  66 .15  107 59  385  16 .40 Type of Gasoline Income Less than \$30,000 \$30,000 to \$49,999 \$50,000 to \$99,000 At least \$100,000 Regular Premium (66.15) (24.46) 85 16 (87.78) (32.46) 102 27 (45.13) (16.69) 36 22 (38.95) (14.40) 15 23 238 88 Extra Premium (16.40) 6 (21.76) 13 (11.19) 15 (9.65) 25 59 107 142 73 63 385
19. 19. Gasoline preference Versus Income Category: 𝜒 2 calculation f o  f e    2  2 f 88  66.15  e  16  24.46   27  32.46 2 66.15 102  87.78 87 .78 2 36  4513 . 45.13  70.78 38.95 24 .46 6 16.40   13  21.76  32 .46  15 1119  .   23 14.40  2 16.69  25  9.65 14 .40 2 2 22 16.69  2 15  38.95  2 2 2  16.40 21.76 1119 . 9.65 2  2  2
20. 20. Gasoline preference Versus Income Category • The observed chi-square value of 70.78 is greater than the critical value of 16.8119. • The decision is to reject the null hypothesis. The data does provide enough evidence to indicate that the type of gasoline preferred is not independent of income.
21. 21. Gasoline preference Versus Income Category: 𝜒 2 calculation
22. 22. Parametric versus Nonparametric Statistics • Parametric Statistics are statistical techniques based on assumptions about the population from which the sample data are collected.   • Assumption that data being analyzed are randomly selected from a normally distributed population. Requires quantitative measurement that yield interval or ratio level data. Nonparametric Statistics are based on fewer assumptions about the population and the parameters.  Sometimes called “distribution-free” statistics.  A variety of nonparametric statistics are available for use with nominal or ordinal data.
23. 23. Advantages of Nonparametric Techniques • Sometimes there is no parametric alternative to the use of nonparametric statistics. • Certain nonparametric test can be used to analyze nominal data. • Certain nonparametric test can be used to analyze ordinal data. • The computations on nonparametric statistics are usually less complicated than those for parametric statistics, particularly for small samples. • Probability statements obtained from most nonparametric tests are exact probabilities.
24. 24. Disadvantages of Nonparametric Statistics • Nonparametric tests can be wasteful of data if parametric tests are available for use with the data. • Nonparametric tests are usually not as widely available and well known as parametric tests. • For large samples, the calculations for many nonparametric statistics can be tedious.
25. 25. Runs Test • Test for randomness - Is the order or sequence of observations in a sample random or not? • Each sample item possesses one of two possible characteristics • Run – defined as a succession of observations which possess the same characteristic • Example with two runs: F, F, F, F, F, F, F, F, M, M, M, M, M, M, M • Example with fifteen runs: F, M, F, M, F, M, F, M, F, M, F, M, F, M, F
26. 26. Runs Test: Sample Size Consideration • Sample size: n • Number of sample member possessing the first characteristic: n1 • Number of sample members possessing the second characteristic: n2 • n = n1 + n2 • If both n1 and n2 are  20, the small sample runs test is appropriate.
27. 27. Runs Test: Small Sample Example Suppose 26 cola drinkers are sampled randomly to determine whether they prefer regular cola or diet cola. The random sample contains 18 regular cola drinkers and 8 diet cola drinkers. Let C denote regular cola drinkers and D denote diet cola drinkers. Suppose the sequence of sampled cola drinkers is CCCCCDCCDCCCCDCDCCCDDDCCC. Does this sequence of cola drinkers evidence that the sample is not random?
28. 28. Runs Test: Small Sample Example H0: The observations in the sample are randomly generated. Ha: The observations in the sample are not randomly generated.  = .05 n1 = 18 n2 = 8 If 7  R  17, do not reject H0 Otherwise, reject H0. 1 2 3 4 5 6 7 8 9 10 11 12 D CCCCC D CC D CCCC D C D CCC DDD CCC R = 12 Since 7  R = 12  17, do not reject H0
29. 29. Runs Test: Small Sample Example in R X = as.factor(c("c","c","c","d","d","d")) > runs.test(x) > Runs Test data: Standard Normal = -1.8257, p-value = 0.06789 alternative hypothesis: two.sided
30. 30. Runs Test: Large Sample Consider the following manufacturing example. A machine produces parts that are occasionally flawed. When the machine is working in adjustment, flaws still occur but seem to happen randomly. A quality-control person randomly selects 50 of the parts produced by the machine today and examines them one at a time in the order that they were made. The result is 40 parts with no flaws and 10 parts with flaws. The sequence of no flaws (denoted by N) and flaws (denoted by F ) is shown on an upcoming slide. Using an alpha of .05, the quality controller tests to determine whether the machine is producing randomly (the flaws are occurring randomly)
31. 31. Runs Test: Large Sample If either n1 or n2 is > 20, the sampling distribution of R is approximately normal.
32. 32. Runs Test: Large Sample Example -1.96  Z = -1.81  1.96, do not reject H0
33. 33. Runs Test: Large Sample Example H0: The observations in the sample are randomly generated. Ha: The observations in the sample are not randomly generated.  = .05 n1 = 40 n2 = 10 If -1.96  Z  1.96, do not reject H0 Otherwise, reject H0. 1 1 2 3 4 5 6 7 8 9 0 11 NNN F NNNNNNN F NN FF NNNNNN F NNNN F NNNNN 12 13 FFFF NNNNNNNNNNNN R = 13
34. 34. Mann-Whitney U Test • Mann-Whitney U test - a nonparametric counterpart of the t test used to compare the means of two independent populations. • Nonparametric counterpart of the t test for independent samples • Does not require normally distributed populations • May be applied to ordinal data • Assumptions   Independent Samples At Least Ordinal Data
35. 35. Mann-Whitney U Test: Sample Size Consideration • Size of sample one: n1 • Size of sample two: n2 • If both n1 and n2 are ≤ 10, the small sample procedure is appropriate. • If either n1 or n2 is greater than 10, the large sample procedure is appropriate.
36. 36. Mann-Whitney U Test: Small Sample Example - Demonstration Problem 17.1 • H0: The health service population is identical to the educational service population on employee compensation • Ha: The health service population is not identical to the educational service population on employee compensation Health Service 20.10 19.80 22.36 18.75 21.90 22.96 20.75 Educational Service 26.19 23.88 25.50 21.64 24.85 25.30 24.12 23.45
37. 37. Mann-Whitney U Test: Small Sample Example - Demonstration Problem 17.1 U 1  n1 n2 n (n  1)   1 1 W1 2 (7)(8)  (7)(8)   31 2  53 U n n 2 1 2 n (n  2 2 2  1) W 2 (8)(9)  (7)(8) n1 n2   89 2 3 • Since U2 < U1, U = 3. • p-value = .0011*2 (for a two-tailed test) = .022 < .05, reject H0.
38. 38. Mann-Whitney U Test: Formulas for Large Sample Case
39. 39. Incomes of PBS and Non-PBS Viewers The Mann-Whitney U test can be used to determine whether there is a difference in the average income of families who view PBS television and families who do not view PBS television. Suppose a sample of 14 families that have identified themselves as PBS television viewers and a sample of 13 families that have identified themselves as non-PBS television viewers are selected randomly.
40. 40. Incomes of PBS and Non-PBS Viewers Ho: The incomes for PBS viewers and non-PBS viewers are identical Ha: The incomes for PBS viewers and non-PBS viewers are not identical n1 = 14 n2 = 13 PBS 24,500 39,400 36,800 44,300 57,960 32,000 61,000 34,000 43,500 55,000 39,000 62,500 61,400 53,000 Non-PBS 41,000 32,500 33,000 21,000 40,500 32,400 16,000 21,500 39,500 27,600 43,500 51,900 27,800
41. 41. Ranks of Income from Combined Groups of PBS and Non-PBS Viewers Income Rank Group 16,000 1 Non-PBS 21,000 2 Non-PBS 21,500 3 Non-PBS 24,500 4 PBS 27,600 5 Non-PBS 27,800 6 Non-PBS 32,000 7 PBS 32,400 8 Non-PBS 32,500 9 Non-PBS 33,000 10 Non-PBS 34,000 11 PBS 36,800 12 PBS 39,000 13 PBS 39,400 14 PBS Income 39,500 40,500 41,000 43,000 43,500 43,500 51,900 53,000 55,000 57,960 61,000 61,400 62,500 Rank 15 16 17 18 19.5 19.5 21 22 23 24 25 26 27 Group Non-PBS Non-PBS Non-PBS PBS PBS Non-PBS Non-PBS PBS PBS PBS PBS PBS PBS
42. 42. PBS and Non-PBS Viewers: Calculation of U
43. 43. PBS and Non-PBS Viewers: Conclusion
44. 44. Wilcoxon Matched-Pairs Signed Rank Test • Mann-Whitney U test is a nonparametric alternative to the t test for two independent samples. If the two samples are related, the U test is not applicable.  Handle related data  Serves as a nonparametric alternative to the t test for two related samples  A nonparametric alternative to the t test for related samples • Before and After studies • Studies in which measures are taken on the same person or object under different conditions • Studies of twins or other relatives
45. 45. Wilcoxon Matched-Pairs Signed Rank Test • Differences of the scores of the two matched samples • Differences are ranked, ignoring the sign • Ranks are given the sign of the difference • Positive ranks are summed • Negative ranks are summed • T is the smaller sum of ranks
46. 46. Wilcoxon Matched-Pairs Signed Rank Test: Sample Size Consideration • n is the number of matched pairs • If n > 15, T is approximately normally distributed, and a Z test is used. • If n ≤ 15, a special “small sample” procedure is followed.  The paired data are randomly selected.  The underlying distributions are symmetric.
47. 47. Wilcoxon Matched-Pairs Signed Rank Test: Small Sample Example Consider the survey by American Demographics that estimated the average annual household spending on healthcare. The U.S. metropolitan average was \$1,800. Suppose six families in Pittsburgh, Pennsylvania, are matched demographically with six families in Oakland, California, and their amounts of household spending on healthcare for last year are obtained.
48. 48. Wilcoxon Matched-Pairs Signed Rank Test: Small Sample Example H0: Md = 0 Ha: Md  0 n=6  =0.05 If Tobserved  1, reject H0. Family Pair 1 2 3 4 5 6 Pittsburgh 1,950 1,840 2,015 1,580 1,790 1,925 Oakland 1,760 1,870 1,810 1,660 1,340 1,765
49. 49. Wilcoxon Matched-Pairs Signed Rank Test: Small Sample Example Family Pair 1 2 3 4 5 6 Pittsburgh 1,950 1,840 2,015 1,580 1,790 1,925 T = minimum(T+, T-) T+ = 4 + 5 + 6 + 3= 18 T- = 1 + 2 = 3 T=3 Oakland 1,760 1,870 1,810 1,660 1,340 1,765 d 190 -30 205 -80 450 160 Rank +4 -1 +5 -2 +6 +3 T = 3 > Tcrit = 1, do not reject H0.
50. 50. Wilcoxon Matched-Pairs Signed Rank Test: Large Sample Formulas For large samples, the T statistic is approximately normally distributed and a z score can be used as the test statistic. This technique can be applied to the airline industry, where an analyst might want to determine whether there is a difference in the cost per mile of airfares in the United States between 1979 and 2011 for various cities. The data in the next slide represent the costs per mile of airline tickets for a sample of 17 cities for both 1979 and 2011.
51. 51. Wilcoxon Matched-Pairs Signed Rank Test: Large Sample Formulas
52. 52. Wilcoxon Matched-Pairs Signed Rank Test: Large Sample Formulas
53. 53. Airline Cost Data for 17 Cities, 1979 and 2009 H0: Md = 0 Ha: Md  0 City 1979 2011 1 20.3 22.8 2 19.5 12.7 3 18.6 14.1 4 20.9 16.1 5 19.9 25.2 6 18.6 20.2 7 19.6 14.9 8 23.2 21.3 9 21.8 18.7 d Rank -2.5 -8 6.8 17 4.5 13 4.8 15 -5.3 -16 -1.6 -4 4.7 14 1.9 6.5 3.1 10 City 1979 2011 10 20.3 20.9 11 19.2 22.6 12 19.5 16.9 13 18.7 20.6 14 17.7 18.5 15 21.6 23.4 16 22.4 21.3 17 20.8 17.4 d Rank -0.6 -1 -3.4 -11.5 2.6 9 -1.9 -6.5 -0.8 -2 -1.8 -5 1.1 3 3.4 11.5
54. 54. Airline Cost Data: T Calculation
55. 55. Airline Cost Data: Conclusion
56. 56. Kruskal-Wallis Test • Kruskal-Wallis Test - A nonparametric alternative to one-way analysis of variance • May be used to analyze ordinal data • No assumed population shape • Assumes that the Treatment (C) groups are independent • Assumes random selection of individual items
57. 57. Kruskal-Wallis K Statistic
58. 58. Number of Patients per Day per Physician in Three Organizational Categories Suppose a researcher wants to determine whether the number of physicians in an office produces significant differences in the number of office patients seen by each physician per day. She takes a random sample of physicians from practices in which (1) there are only two partners, (2) there are three or more partners, or (3) the office is a health maintenance organization (HMO).
59. 59. Number of Patients per Day per Physician in Three Organizational Categories Ho: The three populations are identical Ha: At least one of the three populations is different Three or Two More Partners Partners HMO 13 24 26 15 16 22 20 19 31 18 22 27 23 25 28 14 33 17
60. 60. Patients per Day Data: Kruskal-Wallis Test Preliminary Calculations Three or Two More Partners Partners HMO Patients Rank Patients Rank Patients Rank 13 1 24 12 26 14 15 3 16 4 22 9.5 20 8 19 7 31 17 6 18 22 9.5 27 15 23 11 25 13 28 16 14 2 33 18 5 17 T1 = 29 T2 = 52.5 T3 = 89.5 n1 = 5 n2 = 7 n3 = 6 n = n1 + n2 + n3 = 5 + 7 + 6 = 18
61. 61. Patients per Day Data: Kruskal-Wallis Test Calculations and Conclusion
62. 62. Friedman Test • Friedman Test - A nonparametric alternative to the randomized block design • Assumptions  The blocks are independent.  There is no interaction between blocks and treatments.  Observations within each block can be ranked. • Hypotheses  Ho: The treatment populations are equal  Ha: At least one treatment population yields larger values than at least one other treatment population
63. 63. Friedman Test
64. 64. Friedman Test: Tensile Strength of Plastic Housings A manufacturing company assembles microcircuits that contain a plastic housing. Managers are concerned about an unacceptably high number of the products that sustained housing damage during shipment. The housing component is made by four different suppliers. Managers have decided to conduct a study of the plastic housing by randomly selecting five housings made by each of the four suppliers. One housing is selected for each day of the week. That is, for each supplier, a housing made on Monday is selected, one made on Tuesday is selected, and so on. In analyzing the data, the treatment variable is supplier and the treatment levels are the four suppliers. The blocking effect is day of the week with each day representing a block level. The quality control team wants to determine whether there is any significant difference in the tensile strength of the plastic housing by supplier.
65. 65. Friedman Test: Tensile Strength of Plastic Housings Ho: The supplier populations are equal Ha: At least one supplier population yields larger values than at least one other supplier population Monday Tuesday Wednesday Thursday Friday Supplier 1 62 63 61 62 64 Supplier 2 63 61 62 60 63 Supplier 3 57 59 56 57 58 Supplier 4 61 65 63 64 66
66. 66. Friedman Test: Tensile Strength of Plastic Housings Supplier 1 Supplier 2 Supplier 3 Supplier 4 Monday 3 4 1 2 Tuesday 3 2 1 4 Wednesday 2 3 1 4 Thursday 3 2 1 4 Friday 3 2 1 4 14 13 5 18 196 169 25 324 R R j 2 j
67. 67. Friedman Test: Tensile Strength of Plastic Housings
68. 68. Friedman Test: Tensile Strength of Plastic Housings
69. 69. Spearman’s Rank Correlation • Spearman’s Rank Correlation - Analyze the degree of association of two variables • Applicable to ordinal level data (ranks)
70. 70. Spearman’s Rank Correlation: Example Listed below are the average prices in dollars per 100 pounds for choice spring lambs and choice heifers over a 10-year period. The data were published by the National Agricultural Statistics Service of the U.S. Department of Agriculture. Suppose the researcher want to determine the strength of association of the prices between these two commodities by using Spearman’s rank correlation.
71. 71. Spearman’s Rank Correlation Test for Heifer and Lamb Prices
72. 72. Spearman’s Rank Correlation Test for Heifer and Lamb Prices
73. 73. Spearman’s Rank Correlation Test for Heifer and Lamb Prices • The lamb prices are ranked and the heifer prices are ranked. • The difference in ranks is computed for each year. • The differences are squared and summed, producing ∑d2 = 108. • The number of pairs, n, is 10. • The value of rs = 0.345 indicates that there is a very modest if not poor positive correlation between lamb and heifer prices.