Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 7: Two Way Tables Graduate School Quantitative Research Methods Gwilym Pryce

Similar presentations


Presentation on theme: "1 Lecture 7: Two Way Tables Graduate School Quantitative Research Methods Gwilym Pryce"— Presentation transcript:

1 1 Lecture 7: Two Way Tables Graduate School Quantitative Research Methods Gwilym Pryce g.pryce@socsci.gla.ac.uk

2 2 Notices: n Register

3 3 Aims and Objectives: n Aim: –This session introduces methods of examining relationships between categorical variables n Objectives: –By the end of this session the reader should be able to: Understand how to examine relationships between categorical variables using: » 2 way tables »Chi square test for independence.

4 4 Plan: n 1. Independent events n 2. Contingent events n 3. Chi square test for independence n 4. Further Study

5 5 1. Probability of two Independent events occurring n If knowing that one event occurs does not affect the outcome of another event, we say those two outcomes are independent. n And if A and B are independent, and we know the probability of each of them occurring, we can calculate the probability of them both occurring

6 6 Example: You have a two sided die and a coin, find Pr(1 and H). n Answer: ½ x ½ = ¼ n Rule: P(A  B) = P(A) x P(B)

7 7 e.g. You have one coin which you toss twice: what’s the probability of getting two heads? n Suppose: A = 1st toss is a head B = 2nd toss is a head –what is the probability of A  B? n Answer: A and B are independent and are not disjoint. P(A) = 0.5 and P(B) = 0.5. P (A  B) = 0.5 x 0.5 = 0.25.

8 8 2. Probability of two contingent events occurring n If knowing that one event occurs does change the probability that the other occurs, then two events are not independent and are said to be contingent upon each other n If events are contingent then we can say that there is some kind of relationship between them n So testing for contingency is one way of testing for a relationship

9 9 Example of contingent events: n There is a 70% chance that a child will go to university if its parents are middle class, but only a 10% chance if its parents are working class. Given that there is a 60% chance of a child’s parents being working class: What are the chances that a child will be working class and go to University? What proportion of people at university will be from working working class backgrounds?

10 10 A tricky one...

11 11

12 12 6% of all children are both working class and end up going to University

13 13 % = as percent of all children Working classMiddle class Go to University 6%28% Do not go to University 54%12%

14 14 % at Uni from WC parents? n Of all children, only 32% end up at university (6% WC; 28% MC) n I.e 6 out of every 32 University students are from WC parents: n 6/32 = 18.75% of University students are WC

15 15 n Probability theory states that: –if x and y are independent, then the probability of events x and y simultaneously occurring is simply equal to the product of the two events occurring : –if x and y are not independent, then : Prob(x  y) = Prob(x)  Prob(y given that x has occurred)

16 16 Test for independence n We can use these two rules to test whether events are independent –Does the distribution of observations across possible outcomes resemble the random distribution we would get if events were independent? –I.e. if we assume independence and calculate the expected number of of cases in each category, do these figures correspond fairly closely to the actual distribution of outcomes found in our data?

17 17 Example 1: Is there a relationship between social class and education? We might test this by looking at categories in our data of WC, MC, University, no University. Suppose we have 300 observations distributed as follows: Working classMiddle class Go to University 1884 Do not go to University 16236

18 18 n To do the test for independence we need to compare expected with observed. n How do we calculate e i, the expected number of observations in category i? –I.e. number of cases expected in i assuming that the two categorical variables are independent –the formula for e i is the probability of an observation falling into category i multiplied simply by the total number of observations. I.e. No contingency

19 19 n So, if UNI Y or UNI N and WC or MC are independent (i.e. assuming H 0 ) then: Prob(UNI Y  WC) = Prob(UNI Y )  Prob(WC) –so the expected number of cases for each of the four mutually exclusive categories are as follows: Working classMiddle class Go to University P(UNI Y ) x P(WC) x nP(UNI Y ) x P(MC) x n Do not go to University P(UNI N ) x P(WC) x nP(UNI N ) x P(MC) x n

20 20 n But how do we work out: Prob(UNI Y ) and Prob(WC) which are needed to calcluate Prob(UNI Y  WC): Prob(UNI Y  WC) = Prob(UNI Y )  Prob(WC) n Answer: we assume independence and so estimate them from out data by simply dividing the total observations by the total number in the given category: E.g. Prob(UNI Y ) = Total no. cases UNI Y  All observations = (18 + 84) / 300 = 0.34

21 21 Working classMiddle class Go to University P(UNI Y ) x P(WC) x n = (no. at Uni / n) x (no. WC/n) x n P(UNI Y ) x P(MC) x n = (no. at Uni / n) x (no. MC/n) x n Do not go to University P(UNI N ) x P(WC) x n = (no.not Uni / n) x (no. WC/n) x n P(UNI N ) x P(MC) x n = (no. not Uni / n) x (no. MC/n) x n

22 22 Working classMiddle class Go to University 1884 102 Do not go to University 16236198 180120300

23 23 Working classMiddle class Go to University P(UNI Y ) x P(WC) x n = (102 / 300) x (180 /300) x 300 P(UNI Y ) x P(MC) x n = (102 / 300) x (120 /300) x 300 Do not go to University P(UNI N ) x P(WC) x n = (198 / 300) x (180 /300) x 300 P(UNI N ) x P(MC) x n = (198 / 300) x (120 /300) x 300

24 24 Expected count in each category: Working classMiddle class Go to University (102 / 300) x (180 /300) x 300 =.34 x.6 x 300 = 61.2 (102 / 300) x (120 /300) x 300 =.34 x.4 x 300 = 40.8 Do not go to University (198 / 300) x (180 /300) x 300 =.66 x.6 x 300 = 118.8 (198 / 300) x (120 /300) x 300 =.66 x.4 x 300 = 79.2

25 25 So we have the actual count (I.e. from our data set): Working classMiddle class Go to University 1884 Do not go to University 16236

26 26 And the expected count (I.e. the numbers we’d expect if we assume class & education to be independent of each other): Working classMiddle class Go to University 61.240.8 Do not go to University 118.879.2

27 27 What does this table tell you? Working classMiddle class Go to University Actual count 1884 Expected count 61.240.8 Do not go to University Actual count 16236 Expected count 118.879.2

28 28 n It tells you that if class and education were indeed independent of each other I.e. the outcome of one does not affect the chances of outcome of the other –Then you’d expect a lot more working class people in the data to have gone to university than actually recorded (61 people, rather than 18) –Conversely, you’d expect far fewer middle class people to have gone to university (half the number actually recorded).

29 29 But remember, all this is based on a sample, not the entire population… n Q/ Is this discrepancy due to sampling variation alone or does it indicate that we must reject the assumption of independence?

30 30 3. Chi-square test for independence (non-parametric -- I.e. no presuppositions re distribution of variables; sample size not relevant) (1) H 0 : expected = actual  x & y are independent » I.e. Prob(x) is not affected by whether or not y occurs; H 1 : expected  actual  there is some relationship »I.e. Prob(x) is affected by y occurring. (2)  = 0.05 k = no. of categories e i = expected (given H 0 ) no. of sample observations in the i th category o i = actual no. of sample observations in the i th category d = no. of parameters that have to be estimated from the sample data. r = no. of rows in table c = no. of colums “ “

31 31 Chi-square distribution changes shape for different df:

32 32 (3) Reject H 0 iff P <  (4) Calculate P: P = Prob(  2 >  2 c ) –N.B. Chi-square tests are always an upper tail test –  2 Tables: are usually set up like a t-table with df down the side, and the probabilities listed along the top row, with values of  2 c actually in the body of the table. So look up  2 c in the body of the table for the relevant df and then find the upper tail probability that heads that column. –SPSS: - CDF.CHISQ(  2 c,df) calculates Prob(  2 <  2 c ), so use the following syntax: »COMPUTE chi_prob = 1 - CDF.CHISQ(  2 c,df). »EXECUTE.

33 33 Do a chi-square test on the following table: Working classMiddle class Go to University Actual count 1884 Expected count 61.240.8 Do not go to University Actual count 16236 Expected count 118.879.2

34 34 (1)H 0 : expected = actual  class and Higher Education are independent H 1 : expected  actual  there is some relationship between class and Higher Education

35 35 (2) State the formula & calc  2 :  2 = ( (18 - 61.2) 2 / 61.2 +(84 - 40.8) 2 / 40.8 + (162-118.8) 2 / 118.8 +(36 - 79.2) 2 / 79.2 )

36 36  2 = ( (18 - 61.2) 2 / 61.2 + (84 - 40.8) 2 / 40.8 + (162-118.8) 2 /118.8 + (36 - 79.2) 2 / 79.2 ) = 30.49 + 45.74 + 15.71 + 23.56 = 115.51 df = (r-1)(c-1) = 1 Sig = P(  2 > 115.51) = 0

37 37 (3) Reject H 0 iff P <  (4) Calculate P: COMPUTE chi_prob = 1 - CDF.CHISQ(115.51,1). EXECUTE. Sig = P(  2 > 115.51) = 0  Reject H 0

38 38 Caveat: n As with the 2 proportions tests, the chi-square test is, “an approximate method that becomes more accurate as the counts in the cells of the table get larger” (Moore, Basic Practice of Statistics, 2000, p. 485) n Cell counts required for the Chi-square test: “You can safely use the chi-square test with critical values from the chi-square distribution when no more than 20% of the expected counts are less than 5 and all individual expected counts are 1 or greater. In particular, all four expected counts in a 2x2 table should be 5 or greater” (Moore, Basic Practice of Statistics, 2000, p. 485)

39 39 Example 2: Is there a relationship between whether a borrower is a first time buyer and whether they live in Durham or Cumberland? n Only real problem is how do we calculate e i the expected number of observations in category i? –(I.e. number of cases expected in i assuming that the variables are independent) n the formula for e i is the probability of an observation falling into category i multiplied by the total number of observations.

40 40 n Probability theory states that: –if x and y are independent, then the probability of events x and y simultaneously occurring is simply equal to the product of the two events occurring : –if x and y are not independent, then : Prob(x  y) = Prob(x)  Prob(y given that x has occurred)

41 41 n So, if FTB Y or N and County D or C are independent (i.e. assuming H 0 ) then: Prob(FTB Y  County D ) = Prob(FTB Y )  Prob(County D ) n so the expected number of cases for each of the four mutually exclusive categories are as follows:

42 42 Prob(FTB N ) = Total no. cases FTB N  All observations

43 43

44 44 This gives us the expected count: To obtain this table in SPSS, go to Analyse, Descriptive Statistics, Crosstabs, Cells, and choose expected count rather than observed

45 45

46 46 n What does this table tell you? –Does it suggest that the probability of being an FTB independent of location? –Or does it suggest that the two factors are contingent on each other in some way? –Can it tell you anything about the direction of causation? –What about sampling variation?

47 47

48 48 Summary of Hypothesis test: –(1) H 0 : FTB and County are independent H 1 : there is some relationship –(2)  = 0.05 –(3) Reject H 0 iff P <  –(4) Calculate P: P = Prob(  2 >  2 c ) = 0.29557Do not reject H 0 I.e. if we were to reject H 0, there would be a 1 in 3 chance of us rejecting it incorrectly, and so we cannot do so. In other words, FTB and County are independent.

49 49

50 50 Contingency Tables in SPSS:

51 51

52 52 n Click Cells button to select counts & %s n If you select all three (row, column and total), you will end up with:

53 53

54 54 n Click the Statistics button to choose which stats you want. n If you click Chi-square, the results of a range of tests will be listed…

55 55 We have been calculating the Pearson Chi-square:

56 56 4. For further study: n The Pearson Chi square test only tests for the existence of a relationship It tells you little about the strength of the relationship n SPSS includes a raft of measures that try to measure the level of association between categorical variables. Click on the name of one of the statistics and SPSS will give you a brief definition (see below) In the lab exercises, take a look at these statistics and copy and paste the definitions along side your answers –Right click on the definition and select Copy. Then open up a Word document and paste along with your output.

57 57 Nominal variables: n Contingency coefficient: “A measure of association based on chi-square. The value ranges between zero and 1, with zero indicating no association between the row and column variables and values close to 1 indicating a high degree of association between the variables. The maximum value possible depends on the number of rows and columns in a table.” n Phi and Cramer’s V: “Phi is a chi-square based measure of association that involves dividing the chi-square statistic by the sample size and taking the square root of the result. Cramer's V is a measure of association based on chi-square.” n Lambda: “A measure of association which reflects the proportional reduction in error when values of the independent variable are used to predict values of the dependent variable. A value of 1 means that the independent variable perfectly predicts the dependent variable. A value of 0 means that the independent variable is no help in predicting the dependent variable.” n Uncertainty coefficient: “A measure of association that indicates the proportional reduction in errror when values of one variable are used to predict values of the other variable. For example, a value of 0.83 indicates that knowledge of one variable reduces error in predicting values of the other variable by 83%. The program calculates both symmetric and asymmetric versions of the uncertainty coefficient.”

58 58 Ordinal Variables: n Gamma: A symmetric measure of association between two ordinal variables that ranges between negative 1 and 1. Values close to an absolute value of 1 indicate a strong relationship between the two variables. Values close to zero indicate little or no relationship. For 2-way tables, zero-order gammas are displayed. For 3-way to n-way tables, conditional gammas are displayed. n Somers’ d: “A measure of association between two ordinal variables that ranges from -1 to 1. Values close to an absolute value of 1 indicate a strong relationship between the two variables, and values close to 0 indicate little or no relationship between the variables. Somers' d is an asymmetric extension of gamma that differs only in the inclusion of the number of pairs not tied on the independent variable. A symmetric version of this statistic is also calculated.” n Kendall’s tau-b: “A nonparametric measure of association for ordinal or ranked variables that take ties into account. The sign of the coefficient indicates the direction of the relationship, and its absolute value indicates the strength, with larger absolute values indicating stronger relationships. Possible values range from -1 to 1, but a value of -1 or +1 can only be obtained from square tables.” n Kendall’s tau-c: “A nonparametric measure of association for ordinal variables that ignores ties. The sign of the coefficient indicates the direction of the relationship, and its absolute value indicates the strength, with larger absolute values indicating stronger relationships. Possible values range from -1 to 1, but a value of -1 or +1 can only be obtained from square tables.”

59 59 Correlations: n Pearson correlation coefficient r “a measure of linear association between two variables” n Spearman correlation coefficient “a measure of association between rank orders. Values of both range between -1 (a perfect negative relationship) and +1 (a perfect positive relationship). A value of 0 indicates no linear relationship.”

60 60 When you have a dependent variable measured on an interval scale & an independent variable with a limited number of categories: n Eta: –“A measure of association that ranges from 0 to 1, with 0 indicating no assoication between the row and column variables and values close to 1 indicating a high degree of association. Eta is appropriate for a dependent variable measured on an interval scale (e.g., income) and an independent variable with a limited number of categories (e.g., gender). Two eta values are computed: one treats the row variable as the interval variable; the other treats the column variable as the interval variable.”


Download ppt "1 Lecture 7: Two Way Tables Graduate School Quantitative Research Methods Gwilym Pryce"

Similar presentations


Ads by Google