Top Banner
Analysis of Two-Way tables Ch 9
25

Analysis of Two-Way tables Ch 9. In statistics we call categorical variables present in an experimental design: FACTORS Each possible value of the.

Jan 04, 2016

Download

Documents

Lee Clarke
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

Analysis of Two-Way tablesCh 9

Page 2: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

In statistics we call categorical variables present in an experimental design: FACTORS

Each possible value of the categorical variable (factor) is called a level of the factor.

With this language a two-way table is a representation of an experiment that studies the relationship between two factors.

First factor: ageGroup by age

Second factor: education

Record education

Page 3: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

We can look at each categorical variable separately in a two-

way table by studying the row totals and the column totals.

They represent the marginal distributions, expressed in

counts or percentages (They are written as if in a margin.)

2000 U.S. census

Page 4: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

The marginal distributions can then be displayed on separate bar graphs, typically expressed as percents instead of raw counts. Each graph represents only one of the two variables, completely ignoring the second one.

Page 5: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

Does parental smoking influence the smoking habits of their high school children?

Summary two-way table: High school

students were asked whether they smoke and

whether their parents smoke.

Marginal distribution for the categorical variable “parental smoking”: The row totals are used and re-expressed as percent of the grand total.

The percents are then displayed in a bar graph.

Page 6: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

The marginal distributions summarize each categorical variable independently. But the two-way table actually describes the relationship between both categorical variables.

The cells of a two-way table represent the intersection of a given level of one categorical factor with a given level of the other categorical factor.

Because counts can be misleading (for instance, one level of one factor might be much less represented than the other levels), we prefer to calculate percents or proportions for the corresponding cells. These make up the conditional distributions.

Page 7: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

The counts or percents within the table represent the conditional

distributions. Comparing the conditional distributions allows you

to describe the “relationship” between both categorical variables.

Here the percents are calculated by

age range (columns).29.30% =

1107137785

= cell total . column total

Page 8: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

The conditional distributions can be graphically compared using side by side bar graphs of one variable for each value of the other variable.

Here the percents are calculated by age range

(columns).

Page 9: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

We want to compare the conditional distributions of the response variable (wine purchased) for each value of the explanatory variable (music played). Therefore, we calculate column percents.

What is the relationship between type of music played in supermarkets and type of wine purchased?

We calculate the column conditional percents similarly for

each of the nine cells in the table:

Calculations: When no music was played, there were 84 bottles of wine sold. Of these, 30 were French wine. 30/84 = 0.357 35.7% of the wine sold was French when no music was played.

30 = 35.7%84

= cell total . column total

Page 10: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

For every two-way table, there are two sets of possible conditional distributions.

Wine purchased for each kind of music played (column percents)

Music played for each kind of wine

purchased (row percents)

Does background music in

supermarkets influence customer

purchasing decisions?

Page 11: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

An association or comparison that holds for all of several groups can

reverse direction when the data are combined (aggregated) to form a

single group. This reversal is called Simpson’s paradox.

Hospital A Hospital BDied 63 16Survived 2037 784

Total 2100 800% surv. 97.0% 98.0%

On the surface, Hospital B would seem to have a better record.

Here patient condition was the lurking variable.

Patients in good condition Patients in poor conditionHospital A Hospital B Hospital A Hospital B

Died 6 8 Died 57 8Survived 594 592 Survived 1443 192

Total 600 600 Total 1500 200% surv. 99.0% 98.7% % surv. 96.2% 96.0%

But once patient condition is taken into account, we see that hospital A has in fact a better record for both patient conditions (good and poor).

Example: Hospital death rates

Page 12: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

The main test is to check whether or not the two factors are

independent or if there is a relationship between them.

◦Put it differently we check if the differences in sample proportions that are observed

are likely to have occurred by just chance because of the random sampling.

To assess this we use a chi-square () test to check the null

hypothesis of no relationship between the two categorical variables

of a two-way table.

Page 13: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

Two-way tables sort the data according to two categorical variables. We want to test the hypothesis that there is no relationship between these two categorical variables (H0).

To test this hypothesis, we compare actual counts from the sample data with expected counts given the null hypothesis of no relationship.

The expected count in any cell of a two-way table when H0 is true

(under independence hypothesis) is:

Page 14: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

Cocaine addictionCocaine produces short-term feelings of physical and mental well being. To maintain the effect, the drug may have to be taken more frequently and at higher doses. After stopping use, users will feel tired, sleepy and depressed. 

The pleasurable high followed by unpleasant after-effects encourage repeated compulsive use, which can easily lead to dependency.  Desipramine is an antidepressant affecting the brain chemicals that may become unbalanced and cause depression. It was thus tested for recovery from cocaine addiction.

Treatment with desipramine was compared to a standard treatment

(lithium, with strong anti-manic effects) and a placebo.

Page 15: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

25*26/74 ≈ 8.7825*0.35

16.2225*0.65

9.1426*0.35

16.8625*0.65

8.0823*0.35

14.9225*0.65

Desipramine

Lithium

Placebo

Expected relapse counts

No Yes35% 35%35%

Expected

Observed

Page 16: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

The chi-square statistic (2) is a measure of how much the observed cell counts in a two-way table diverge from the expected cell counts.

The formula for the 2 statistic is:(summed over all r * c cells in the table)

2 observed count - expected count 2

expected count

Large values for 2 represent strong deviations from the expected

distribution under the H0 and providing evidence against H0.

However, since 2 is a sum, how large a 2 is required for statistical

significance will depend on the number of comparisons made.

Page 17: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

For the chi-square test, H0 states that there is no association

between the row and column variables in a two-way table. The

alternative is that these variables are related.

If H0 is true, the chi-square test has approximately a χ2

distribution with (r − 1)(c − 1) degrees of freedom.

The P-value for the chi-square

test is the area to the right of

2 under the 2 distribution

with df (r−1)(c−1):

P(χ2 ≥ X2).

Page 18: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

We can safely use the chi-square test when:

◦ The samples are simple ransom samples (SRS).

◦ All individual expected counts are 1 or more

◦ No more than 20% of expected counts are less than 5

For a 2x2 table, this implies that all four expected

counts should be 5 or more.

Page 19: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

When comparing only two proportions such as in a 2x2

table where the columns represent counts of “success”

and “failure,” we can test

H0: p1 = p2 vs. Ha p1 ≠ p2

equally with a two-sided z test or with a chi-square test

with 1 degree of freedom and get the same p-value. In

fact, the two test statistics are related: X2 = (z)2.

Page 20: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

Observed

Cocaine addiction

The p-value is 0.005 or half a

percent. This is very significant.

We reject the null hypothesis of

no association and conclude that

there is a significant relationship

between treatment

(desipramine, lithium, placebo)

and outcome (relapse or not).

Minitab statistical software

output for the cocaine study

Page 21: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

Franchise businesses are sometimes given an exclusive territory by

contract. This means that the new outlet will not have to compete with

other outlets of the same chain within its own territory. How does the

presence of an exclusive-territory clause in the contract relate to the

survival of the business?

A random sample of 170 new franchises recorded two categorical

variables for each firm: (1) whether the firm was successful or not

(based on economic criteria) and (2) whether or not the firm had an

exclusive-territory contract.

This is a 2x2 table (two levels for

success, yes/no; two levels for

exclusive territory, yes/no).

df = (2 − 1)(2 − 1) = 1

Page 22: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

How does the presence of an exclusive-territory clause

in the contract relate to the survival of the business?

To compare firms that have

an exclusive territory with

those that do not, we start by

examining column percents

(conditional distribution):

The difference between the percent of successes among the two

types of firms is quite large. The chi-square test can tell us whether or

not these differences can be plausibly attributed to chance (random

sampling). Specifically, we will test

H0: No relationship between exclusive clause and success

Ha: There is some relationship between the two variables

Page 23: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

The p-value is significant at α 5% (p 1.5%) thus we reject H0: we have

found a significant relationship between an exclusive territory and the

success of a franchised firm.

Successful firms

Here is the chi-square

output from Minitab:

Page 24: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

Computer output

using Crunch It!

Successful firms

Page 25: Analysis of Two-Way tables Ch 9.  In statistics we call categorical variables present in an experimental design: FACTORS  Each possible value of the.

R code:

•In R you create a matrix with elements the counts. •Then to perform the chi-square test use simply:

chisq.test()

•More details can be found on pages 136-137 of the R textbook.