Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 31

Chapter_16

Categorical data
Field (2005)
What are categorical variables?

We know already grouping (dummy) variables.


They are variables that describe categories of
entities.

Categorical data are not continuous scores but


discrete values such as being male/female,
pregnant/not pregnant, etc.

With categorical tests, we can test relationships


between such categorical data.
Theory of analysing categorical data

In the simplest case, we compare two categorical


variables.
However, we cannot use the mean, since we do
not have a continuous measure. Instead we
analyse frequencies, namely the number of things
that fall into each combination of categories.
Example: Dancing cats
Research question: Can animals
be trained to line-dance?

Experiment: 200 cats were trained to line-dance


by rewarding them with food or affection:

2 Variables
 Training: reward through food or affection

 Dance: could they dance or not?

After training, the number of cats that could or


could not line-dance, was counted and compared
between the two training groups.
http://www.cyber-cats.com/images/cards/dancing-
Example: Dancing cats
Frequencies of cats being able to dance after food
or affectionate reward are tabulated in a
Contingency table:
'Contingency' means a
Training fact that is not logically
Food Affection Total necessarily true or false.
Could They Acts can be contingent
upon other acts, as here:
Dance? Yes 28 48 76 dancing or not dancing is
No 10 114 124 contingent upon food or
Total 38 162 200 affection.

We now want to know whether there is a


relationship between the two categorical
variables, namely if the number of dancing cats
relates to the kind of training they received.
Pearson's Chi-square test ( ) 2

The Chi-square test compares the empirically


observed frequencies against the frequencies that
are expected by chance alone.
The logic of the Chi-square test follows the same
general logic of fitting a model to a set of data:

deviation = (observed-model)2
'observed' = frequencies of data
 = (observedij-modelij)
2 2
'model' = expected frequencies

Modelij
Calculating expected values
How many cats do we expect to be there in each
of the 4 cells?

Modelij = Eij = Row Totali x Column Totalj


n
E=
Expected

This equation takes into account the unequal


number of cats that received a reward and
unequal number of cats that could or could not
dance.
Expected model values for all 4 cells
Training
RT = row total Food Affection Total
CT = column total Could They
Dance? Yes 28 48 76
No 10 114 124
Total 38 162 200

ModelFood, Yes = (RTYes x CTFood)/n = 76 x 38/200 = 14.44

ModelFood, No = (RTNo x CTFood)/n = 124 x 38/200 =23.56

ModelAffect,Yes = (RTYes x CTAffect)/n = 76 x 162/200 = 61.56

ModelAffect,No = (RTNo x CTAffect)/n = 124 x 162/200 = 100.44


Expected frequencies Deriving the 2 statistic Observed frequencies

Training Training
Food Affection Food Affection
Could They Could They
Dance? Yes 14,44 61,56 Dance? Yes 28 48
No 23,56 100,44 No 10 114

We now have to subtract from each observed value its


corresponding model value, square it,divide it by the model
value, and sum it up:

2 = (28-14.44)2/14.44 + (10-23.56)2/23.56
+ (48-61.56)2/61.56 + (48-61.56)2/n

= 12.73 + 7.80 + 2.99 + 1.83

= 23.35
Expected frequencies The Likelihood ratio Observed frequencies

Training Training
Food Affection Food Affection
Could They Could They
Dance? Yes 14,44 61,56 Dance? Yes 28 48
No 23,56 100,44 No 10 114

An alternative to Pearson's 2 test is the likelihood ratio


statistic which is based on the maximum-likelihood theory. In
its equation, the natural logarithm ln is used:
L2 is tested for
L2 = 2 Observedij ln (Observedij/Modelij) significance
in the same way
= 2[ 28xln(28/14.44) + 10xln(10/23.56) as 2.
+ 48xln(48/61.56) + 114xln(114/100.44)]

= 2[(28 x .662) + (10 x -.857) + (48 x- .249) + (114 x .127)]


= 2(18.54 – 8.57 – 11.94 + 14.44) L2 yields similar results as 2 for
= 24.94 large samples. L2 is preferred
over 2 for small samples.
Yates's continuity correction
For a 2x2 contingency table, Pearson's 2 statistics may
overestimate the correct value, hence be prone of
making a Type 1-error. Therefore, Yates's correction is
applied. It considers only the absolute of the observed
minus the model values and subtracts -1/2 from it.

2 =  [(|Observedij – Modelij|) - .5)2]/Modelij

= (13.56-.5)2/14.44 + (13.56-.5)2/23.56
+ (13.56-.5)2/61.56 + (13.56-.5)2/100.44

= 11.81 + 7.24 + 2.77 + 1.7 Note:


In most cases, a
Yates' correction
Note: The corrected value is somewhat will not be necessary.
= 23.52 smaller than the uncorrected one (25.35). Only for df=1 it is
The significance level therefore decreases advised.
a little bit.
Assumptions of the 2 test
What it does NOT What it DOES assume:
assume: 
Each person, item, or

Continuous and entity may only contribute
normally distributed to a single cell in the
contingency table. Hence,
data NO repeated testing is
possible.

The expected frequencies
should be > 5. Only in
larger contingency tables
20% of the expected
frequencies may be <5.
Testing the 2 statistic for significance
The observed value  = 23.35 now has to be compared
2

against a critical 2 value which it has to exceed in order to


be significant.
The df's of the  value are (r-1)(c-1) where r is the
2
number of rows (2) and c the number of columns (2).

df = (2-1)(2-1) = 1

Look the critical 2 value for df=1 up in Appendix A4. It is


3.84 (for p< .05) and 6.63 (for p<.01).
Since our empirically derived 2 value (23.35) exceeds the
critical  value (3.84 or 6.63), we can conclude that the
2
different training methods have an influence on cats'
learning to line-dance.
Running a  test using SPSS
2
(using the Cats.sav and catsWeight.sav data)

Entering the data can be done in two


ways:

Entering raw data 
Entering weight
cases
Entering raw data: Cats.sav
 Specify a dummy variable for
both variables, e.g.

Training: 0 = food reward
1 = affection

Dance: 0 = dances
1 = does not dance
 Each row represents one
subject.
 Expl.: a cat that was rewarded
with food and did not learn to
dance receives the coding: 0 1
 This is the way cats.sav is
organized
Entering weight cases: CatsWeight.sav
Training
Food Affection
Could They
Dance? Yes 28 48
No 10 114

When we enter the weight


cases, we add a third
variable to 'Training' and
'dance', namely 'frequent'
Data  Weight cases... with which we encode the
frequency found in the
respective cell-combination,
e.g., 28 cats that received
food as reward and danced.
Next, we have to tell SPSS
SPSS now weights each category that we are using weight
combination by the number in the
column 'frequent', i.e., it 'knows' cases.
now that there are 28 cases of 00.
Running the analysis with cross-tabs
'Crosstabs' is a command that analyses data that
fall into categories.
Analyze  Descriptive Statistics  Crosstabs

Enter 1 Variable into 'Row' and


the other into 'Column'.

Here, you may enter a 'layer'


variable by which you could split
the rows of the table into further
categories.
Running the analysis with cross-tabs

You can run the 2 test either with the weighted


data (CatsWeight.sav) or with the raw data
(Cats.sav). The following specification in the
dialog windows and the subsequent output are
the same.
Statistics

There are various


options for analyzing
categorical data.
See next slide

Here you could


request tests for
ordinal data
Statistical options for crosstabs
Chi-square: This is the basic Pearson chi-square test. It
detects significant associations between two categorical
variables but it does not tell you how strong the relation
is.
Phi and Cramer's V measure the strength of association
between two categorical variables. Phi is used for 2x2
contingency tables (2 variables with 2 categories).
Cramer's V is applied when one of the 2 variables has >
2 categories. Cramer's V can also be used as a measure
of the effect size.
Lambda: Goodman and Kruskal's  measure how well
one variable can predict membership of another variable
in a category. A value of 1 means that the variable
predicts the other perfectly.
Kendall's statistics: for small data sets, good estimate of
the population, also used for ordinal data (see 4.5.5)
Cells

Besides the 'oberseved' counts


check the 'expected' counts. They
should not be smaller than 5 in a
2x2 contingency table.

Looking at the Row and Column


Percentages helps you interpret
the results.
Format

If you have 'Exact' instead


of 'Format' you can request
an exact test here

The rows are ordered in ascending


order

Finally, click OK
In total, 38% of the cats (76) danced.
Of these, 36.8% (28) were trained with Output of Crosstabs
food and 63.2% (48) with affection.
62% of the cats did NOT dance.8.1%
(10) of them were trained with food
and 91.9% (114) with affection.

DANCE Did they dance? * TRAINING Type of Training Crosstabulation

TRAINING Type of Training


,00 Food 1,00 Affection
as Reward as Reward Total
DANCE Did
they dance?
,00 Yes Count 28 48 76 'Count' gives you the absolute numbers
Expected Count
% within DANCE
14,4 61,6 76,0
Below are the %
36,8% 63,2% 100,0%
Did they dance?
% within TRAINING
Type of Training
73,7% 29,6% 38,0% % within type of training tells us that of
% of Total 14,0% 24,0% 38,0% those trained with food, 73.7% danced
1,00 No Count 10 114 124 and of those trained with affection,
Expected Count 23,6 100,4 124,0 70.4% did not dance.
% within DANCE
8,1% 91,9% 100,0%
Did they dance?
% within TRAINING
Type of Training 26,3% 70,4% 62,0%

 when food was


% of Total 5,0% 57,0% 62,0%
Total Count 38 162 200
Expected Count
% within DANCE
38,0

19,0%
162,0

81,0%
200,0

100,0%
used cats would dance
Did they dance?
% within TRAINING
100,0% 100,0% 100,0%
but when affection was
Type of Training
% of Total 19,0% 81,0% 100,0% used they would not.
http://www.cyber-
Checking the assumptions
DANCE Did they dance? * TRAINING Type of Training Crosstabulation

All frequencies
TRAINING Type of Training
,00 Food 1,00 Affection

should be >5.
as Reward as Reward Total
DANCE Did ,00 Yes Count 28 48 76
they dance?

In the row
Expected Count 14,4 61,6 76,0
% within DANCE
36,8% 63,2% 100,0%
Did they dance?
% within TRAINING
Type of Training
73,7% 29,6% 38,0% 'Expected counts'
1,00 No
% of Total
Count
14,0% 24,0% 38,0%
we see that the
smallest count is
10 114 124
Expected Count 23,6 100,4 124,0

14.4 (cats that had


% within DANCE
8,1% 91,9% 100,0%
Did they dance?
% within TRAINING
Type of Training
% of Total
26,3%
5,0%
70,4%
57,0%
62,0%
62,0%
food but did not
Total Count 38 162 200 dance).
Since this value is
Expected Count 38,0 162,0 200,0
% within DANCE
19,0% 81,0% 100,0%
Did they dance?
% within TRAINING
Type of Training
100,0% 100,0% 100,0% >5, the assumption
% of Total 19,0% 81,0% 100,0%
of the Chi-square
test has been met.
Pearson Chi-square statistic
The Pearson chi-square statistic tests whether the
two variables are independent. If the value is
significant we reject this hypothesis and instead
assume that they are related.
Chi-Square Tests

Value df
Asymp. Sig.
(2-sided)
Exact Sig.
(2-sided)
Exact Sig.
(1-sided)
2 is *!
Pearson Chi-Square 25,356 b 1 ,000
Continuity Correctiona 23,520 1 ,000 Yates' correction
Likelihood Ratio 24,932 1 ,000
Fisher's Exact Test ,000 ,000
Linear-by-Linear
25,229 1 ,000
Association
N of Valid Cases 200
a. Computed only for a 2x2 table
Interpretation:
b. 0 cells (,0%) have expected count less than 5. The minimum expected count is
14,44.
The pattern of responses in the two
training conditions is * different:
Assumption of Cats dance for food (74%) but not for love (26%)
2 test is fulfilled When they are trained with affection, only 30%
dance but 70% don't.)
Additional statistics
Symmetric Measures
Phi: valid only for 2x2 tables
Value Approx. Sig. Cramer's V: when variables have
Nominal by Phi ,356 ,000 >2 categories. Cramer's V is
Nominal Cramer's V ,356 ,000
already an adequate effect size.
Contingency Coefficient ,335 ,000
N of Valid Cases
Contingency coefficient: ensures
200
a. Not assuming the null hypothesis.
a value between 0 and 1.
b. Using the asymptotic standard error assuming the null
hypothesis.

Those values modify the chi-square statistic and


restrict the range of the test statistic from 0-1 so that
they can be interpreted like correlation coefficients.

The correlation between the 2 variables is medium


(around .35) but highly significant.
Calculating effect sizes

A rough measure of the effect size is Cramer's V


which ranges between 0 and 1. It is .356 in our
example.

However, a more common measure of the effect


size is the odds ratio. For a 2x2 contingency table
its interpretation is straightforward.
Calculating effect sizes - the odds ratio
Training
Food Affection
Could They
Dance? Yes 28 48
Oddsdancing after food No 10 114

= number of cats that had food and danced


number of cats that had food but didn't dance

= 28/10 = 2.8

Oddsdancing after affection


= number of cats that had affection and danced
number of cats that had affection but didn't dance

= 48/114 = 0.421
Calculating effect sizes - the odds ratio

Odds ratio:

Oddsdancing after food = 2.8/0.421 = 6.65


Oddsdancing after affection

 If cats were trained with food it was 6.65 times


more likely that they would dance as compared to
being trained with affection.
Reporting the  test 2

(Field, 2005_694)

„There was a significant association between the


type of training and whether or not cats would
dance  (1) = 25.36, p < .001.This seems to
2

represent the fact that based on the odds ratio


cats were 6.65 times more likely to dance if
trained with food than if trained with affection.“
If cats don't want to line-dance after affection,
maybe they would break-dance?!

http://i57.photobucket.com/albums/g231/adresaklumea/funny-cats/dance-
cat.jpg

You might also like