Download presentation

Presentation is loading. Please wait.

Published byElvis Stott Modified over 2 years ago

1
Chapter 9 Analysis of Two-Way Tables

2
Two-way (i.e. contingency) tables: to classify & analyze categorical data: Binomial counts: success vs. failure Proportions: binomial count divided by total sample size

3
Well later see that inference via two-way tables is an alternativewith advantages & disadvantagesto the z-test for comparing two sample proportions:. prtest hsci, by(white)

4
An advantage of two-way tables is that they can examine more than two variables. A disadvantage of two-way tables is that they can only do two-sided hypothesis tests.

5
Heres a two-way table:.tab hsci white, cell Nonwhite WhiteTotal not hsci % 51.5%76.5% hsci % 21.0%23.5% Total % 72.5%100.0%

6
Nonwhite White Total not hsci % 51.5%76.5% hsci % 21.0%23.5% Total % 72.5%100.0% The row variable: hsci vs. not hsci. The column variable: white vs. nonwhite.

7
Nonwhite WhiteTotal not hsci % 51.5%76.5% hsci % 21.0%23.5% Total % 72.5%100.0% Cells: each combination of values for the two variables (50, 103, 5, 42).

8
Nonwhite White Total not hsci % 51.5% 76.5% hsci % 21.0% 23.5% Total % 72.5%100.0% Joint distributions: Each cells percentage of the total sample (50/200=.250; 103/200=.515; 5/200=.025; 42/200=.210).

9
Nonwhite WhiteTotal not hsci % 51.5%76.5% hsci % 21.0%23.5% Total % 72.5%100.0% The marginal frequencies: the row totals (153, 47) & the column totals (55, 145).

10
Nonwhite WhiteTotal not hsci % 51.5% 76.5% hsci % 21.0% 23.5% Total % 72.5% 100.0% The marginal distributions: each row total/sample total (76.5%, 23.5%). Each column total/sample total (27.5%, 72.5%).

11
Here are the same data displayed as column conditional probabilities:.tab hsci white, col nofreq nonwhite white Total no 90.91% 71.03% 76.5% yes 9.09% 28.97% 23.5% Total 100.0% 100.% % The conditional distributions (i.e conditional probabilities): Columndivide each column cell count by its column total count.

12
Here are the same data displayed as row conditional probabilities:.tab hsci white, row nofreq nonwhite white Total not hsci 32.68% 67.32% 100.0% hsci 10.64% 89.36% 100.0% Total 27.5% 72.5% % The conditional distributions (i.e conditional probabilities): Rowdivide each row cell count by its row total count.

13
Tip: Its usually best to compute conditional distributions (i.e. probabilities) across the categories of the explanatory variable. E.g., tab hsci white, col: computes the conditional distributions across the categories of the explanatory variable race- ethnicity (i.e. white vs. nonwhite). Alternatively, you may want to compare joint distributions (i.e. cell counts/total sample): tab hsci white, cell

14
Weve discussed the following: row variables column variables cells: each combination of values for the two variables. joint distributions: each cells percentage of the total sample.

15
marginal frequencies marginal distributions: each marginal frequency/total sample size column conditional distributions: divide each column cell count by its column total count row conditional distributions: divide each row cell count by its row total count.

16
And weve said that typically its best to compute the conditional distributions (i.e. probabilities) across the categories of the explanatory variable. Or that it may be preferable to compare joint distributions (i.e. compare the cell probabilities).

17
Lets next consider conceptual problems of two- way tables.

18
Simpsons Paradox An NSF study found that the median salary of newly graduated female engineers & scientists was just 73% of the median salary for males. Here are womens median salaries in the 16 fields as a percentage of male salaries: 94% 96% 98% 95% 85% 85% 84% 100% 103% 100% 107% 93% 104% 93% 106% 100% How can it be that, on average, the women earn just 73% of the median salary for males, since no listed % falls below 84%?

19
Because women are disproportionately located in the lower-paying fields of engineering & science. That is, field of science & engineering is a lurking variable (i.e. an unmeasured confounded variable) that influences the observed association between gender & salary.

20
Simpsons Paradox: the reversal of a bivariate relationship due to the influence of a lurking variable. Aggregating data has the effect of ignoring one or more lurking variables. Another example: comparing hospital mortality rates. Yet another: comparing airline on-time rates.

21
Conclusion from Simpsons Paradox Always be on the lookout for lurking variables with aggregated data!! A bivariate relationship may change direction when a third, control variable is introduced.

22
Whats a control variable? Holding a variable constant makes it a control variable: doing so removes the part of the bivariate relationship that was caused by the control variable. That is, controlling for a variable neutralizes its influence on the observed relationship. E.g., controlling for field of science & engineering. E.g., controlling for race/ethnicity.

23
To repeat, holding a variable constant removes its statistical effects from the bivariate association being examined. Doing so ensures (more or less) that a bivariate relationship is assessed apart from the influence of the controlled variable: e.g., the relationship between a Montessori school program & student IQ scores, holding constant social class.

24
Whats better: statistical control or experimental control? The answer returns us to the matter of observational study versus experimental study (see Moore/McCabe, chapter 3).

25
Good experimental design controls for all possible lurking variables. Why? But statistical control cannot do so. Why not? Moreover, statistical control is weakened by the imprecision of measurement of variables. But we cant experiment on everything.

26
Lets consider the following variant on Simpsons Paradox:

27
A bivariate association may not appear until a third, control variable is introduced. The apparent absence of the bivariate relationship is called spurious non-association. E.g., no association between years of education & level of income in post-WW II data, until controlling for age of respondents.

28
Conclusion from Spurious Non-Association Explore not just bivariate relationships but also multivariate relationships among all the variables of potential practical or theoretical relevance.

29
Heres how to add a control variable to a two-way table in Stata: bys female: tab hsci white, cell chi2

30
male nonwhite white Total % 45.05% 68.13% % 29.67% 31.87% Total % 74.73% % Pearson chi2(1) = Pr = female nonwhite white Total % 56.88% 83.49% % 13.76% 16.51% Total % 70.64% % Pearson chi2(1) = Pr = 0.196

31
This example introduces a test of statistical significance for two- way tables. The test is based on the Chi- square statistic.

32
male nonwhite white Total % 45.05% 68.13% % 29.67% 31.87% Total % 74.73% % Pearson chi2(1) = Pr = female nonwhite white Total % 56.88% 83.49% % 13.76% 16.51% Total % 70.64% % Pearson chi2(1) = Pr = 0.196

33
Note in the example that the two-way table for male tests insignificant. How do two-way tables & their test of significance evaluate the data? They do so by comparing expected & observed cell counts in terms of proportional distributions.

34
Back to the two-way table without the control variable: :.tab hsci white, cell Nonwhite WhiteTotal not hsci % 51.5%76.5% hsci % 21.0%23.5% Total % 72.5% 100.0%

35
Describing Relations in Two-Way Tables The original data must be counts. Inference for two-way tables: compare the observed cell counts to the expected cell counts; then compute the Chi-square significance test.

36
We begin by computing the expected cell counts: row total times column total, divided by total sample size. Premise: the null hypothesis of statistical independence (i.e. no association between the variables) characterizes the data.

37
Expected cell counts: row total times column total, divided by total sample size. nonwhite white Total no yes Total

38
nonwhite white Total no yes Total di (153*55)/200= di (153*145)/200= di (47*55)/200= di (47*145)/200= How do the expected cell counts compare to the observed cell counts: Do the conditional probabilities appear to be equal for nonwhites & whites across no-hsci & yes hsci?

39
Expected count for each cell: its row total times its column total, divided by the total sample size. Each expected cell count is based on the proportion of the total sample accounted for by its entire row & by its entire column. The Chi-square test assumes independence (i.e. no association) between the conditional distributions of nonwhites & whites in honors science.

40
That is, each expected cell count reflects the null hypothesis of statistical independence (i.e. no association): that the proportion of non-white honors science students is simply the proportion of non-white students in the population. that the proportion of white honors science students is simply the proportion of white students in the population. Whats the alternative hypothesis?

41
Chi-Square Test Assumptions Random sample Two categorical variables Count data At least 5 observations in 80% of the cells & no less than 1 observation in any cell (best if theres at least 5 observations in all cells)

42
If the assumptions are fulfilled, use the Chi-square test: tab hsci white, chi2 If the numbers of observations per cell dont meet the assumptions, use Fishers exact test (a non- parametric test, which may be very slow): tab hsci white, exact

43
Chi-square statistic: measures how much the observed cell counts in a two-way table diverge from the expected cell counts. Its therefore a test of independence: Ho: the variables are independent from each other Ha: they are not independent from each other

44
Step 1: Chi-square = summation for all cells of (observed cell count – expected cell count)squared, divided by the cells expected count Step 2: df = (# row vars –1) (# column vars – 1) Step 3: Chi-square significance test=Chi-square/df

45
Chi-square/df statistic: positive values only Has a distinct distribution for each degree of freedom (see Moore/McCabe) Two-sided hypothesis test only

46
Chi-square Test: To Repeat… Chi-square statistic: measures how much the observed cell counts in a two- way table diverge from the expected cell counts. That is, it compares the sample distribution with a hypothesized distribution. Its a test of statistical independence (Ho: no association; Ha: association).

47
Step 1: Chi-square = summation for all cells of (observed cell count – expected cell count)squared, divided by the cells expected count Step 2: df = (# row vars –1) (# column vars – 1) Step 3: Chi-square significance test=Chi-square/df

48
Hypothesis Test Ho: hsci whites = hsci nonwhites Ha: hsci whites ~= hsci nonwhites (i.e. two-sided alternative) Chi-square test: two-sided alternative hypothesis only.

49
.tab hsci white, cell chi2 nonwhite white Total no % 51.5% 76.5% yes % 21.0% 23.5% Total % 72.5% 100.0% Pearson chi2(1) = Pr = Conclusion: Reject the null hypothesis.

50
Lets repeat the earlier example to see what happens when we add a control variable to the two-way table: bys female: tab hsci nonwhite, col chi2

51
female = male nonwhite white Total % 45.05% 68.13% % 29.67% 31.87% Total % 74.73% % Pearson chi2(1) = Pr = female = female nonwhite white Total % 56.88% 83.49% % 13.76% 16.51% Total % 70.64% % Pearson chi2(1) = Pr = 0.196

52
But when adding a control variable, beware of the consequences for sub-sample sizes. If the sub-samples are too small, it may be hard to obtain statistical significance. So always check the size of sub-samples.

53
Remember: cell counts should be >=5, & for at least 80% of the cells must be this large.

54
We can compare two population proportions either by the chi-square test or by the two- sample z-testwhich give exactly the same resultbecause the chi-square test is equal to the square of the z-test. Chi-square test advantage: can compare more than two populations (e.g., SES by race- ethnicity in hsb2.dta); but the original data must be counts. z-test advantage: can test either one-sided or two-sided alternatives; the original data may be counts or proportions.

55
. prtest hsci, by(white) Two-sample test of proportion nonwhite: Number of obs = 55 white: Number of obs = Variable | Mean Std. Err. z P>|z| [95% Conf. Interval] nonwhite | white | diff | | under Ho: Ho: proportion(nonwhite) - proportion(white) = diff = 0 Ha: diff 0 z = z = z = P |z| = P > z =

56
. tab hsci white, cell chi2 nonwhite white Total no % 51.50% 76.50% yes % 21.0% 23.50% Total % 72.50% 100.0% Pearson chi2(1) = Pr = pr=.003 for Chi-square test & for z-test.

57
Other Useful Stata Commands findit tabchi: displays observed & expected frequencies, various types of residuals (raw, pearson, adjusted), & various tests of significance. findit tabout: to make publication-style contingency & other tables See the following class documents: Making contingency tables in Stata; Making working & publication-style tables in Stata.

58
For greater depth concerning contingency tables & their various significance tests, see Agresti & Finlay, Statistical Methods for the Social Sciences, chap. 8.

59
Summary: Two-Way Tables Two-way tables: categorical data binomial counts (success vs. failure) or proportions (binomial counts divided by the total sample size); but the data must be counts Row variables? Column variables? Cells?

60
Marginal frequencies? Marginal distributions? Joint distributions? Row & column conditional distributions?

61
How to compute expected cell frequencies? What do they represent? Null hypothesis? Alternative hypothesis? How to compute the Chi-square test? How to compute its degrees of freedom? Chi-square assumptions?

62
Advantages/disadvantages of inference via two-ways tables versus inference via z-test for two sample proportions? Chi-square test of significance: equals the square of the z-test for comparing sample proportions, but the Chi-square test requires the original data to be counts.

63
Simpsons Paradox: aggregating the data ignores lurking variables. Moral of the story: beware of the relations portrayed in aggregated data (i.e. look out for lurking variables)!

64
Spurious non-association: a bivariate association appears only when a third, control variable is introduced. Moral of this story: the same as for Simpsons Paradox.

65
Finally, when should we use contingency tables & the Chi-square test? As part of bivariate exploratory data analysis, including in preparation for regression analysis Or when we dont have enough observations to do regression analysis (i.e. perhaps categorize the data and do cross-tabs).

66
Heres how to do the tables for Moore/McCabe, problem 9.1:

67
. tabulate educ age [freq=years], chi2 a1a2a3 Total e1 5,3259,15216,035 30,512 e2 14,06124,07018,320 56,451 e3 11,65919,926 9,662 41,247 e4 10,34219,878 8,005 38,225 Total 41,38773,02652, ,435 Pearson chi2(6)= 9.6e+03Pr = 0.000

68
. tabulate educ age [freq=years], cell chi2 a1 a2a3Total e e e e Total Pearson chi2(6) = 9.6e+03Pr = The row or col options may be preferable to use.

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google