Hypothesis Testing: Categorical Data
Jin Xe
Categorical Data
> Dats classed into categories (ordered or unordered.
Methods include
2. Two-Sample Tes for Sinomal Distribution
Tete of Assocation and Homgeny
Goodness. of Fit Test
4. The Kappa State
=
© invodueion
a Sar
© TwoSample Test for Binomial Proportions,a ST
Two Sample pi vs po Breast Cancer Example
Assume that
A study on rik factors for Breast cancer (Bea)
= Cazes: Bea women in selected hospitals
= Contrals: Non-Bea women of comparable age who were in the
hospital a the same time
5) ~-binlpism), 22 ~ bintpam)
> The hypotheses of interest,
Homan ow Kemer
> Data
> The test depends cn whether the samples ar independent or pled
2 Independent Samples
|. normal: theory method or contingency table method
i, Fishers exact text
bares Samples (MeNemar's Tes)
|. normal theary method
[Age at fest bith
Bea status | 23029 | torah
peters came Normal Theory Approach
+ By lng hey
(oe st > ee) a-n¥x(o-n(2+2))
‘Pa = P(age at first birth > 30jcontrol) *
we
Hosp pa _
nn ~ Renin
— Approximate Methods (Normal-Theory or Contingency-Table) = B= (m1 + a2)/(m +m)
aR 9)> Sand ma -91> 8a ST
Normal Theory Approach Normal Theory Approach
> Tost statisti » For the Bca example, we can use the prop. test function in R
>xsc(683, 1498); n*6(3220, 10245)
Ddprop.teet(, a, alternative = e(*two.eided"),
conf level = 0.95, correct » TRUE)
+ ahr + ph; contin cretion 2-aanple test for equality of proportions
data: x out of a
7 Rapes Bi 4> non Fenquased = 77-8851, af = 4, porsiae < 2.2036
= Pralue siseraative hypotheasa: t4o sided
po vae~ 2% P(2 > Somat 95 percent confadence aneereal
0,04999981 0, 08178846
Sample Size Determination Power Calculation
‘Suppose ie anticipate tat times as many people a ingroup 1 wil be
enrled in group 2
=
[a (eB)nne year] J ed
were where
ad Cees (mpi + mapa)/(m + ma)
» 4.91 and gy ae as defined before
For one sided test, replace a/2 with 0,
For one sided ts, replace a2 witha.a
Contingency Table Approach ~ Chi-square Test
+ Cardiovascular Disease: A study looked a the fects of Oral
Contraceptive (OC) use on heart dense in women 40 to 48 years of
ee
Mi over 3-year period
OC use ates Yer Te. Tear
Teer 13 087 "5000
Non user | 7 9.093 | 10,000
Total | 20145980 [75.000
> The row totals/margins ar ied and known
Chi-square Test
Let Oy; be the observed frequency of cl (3).
> Under Hp, the expected el frequencies, denoted by Ey. 20
Bu sng, Ba=m(1-7) By =mp and Ba =m ~ 9,
> For lage sample (al iy > 5), under Hi,
ey ew
+ When some Fi <5, we use Fisher's exact test
ST
Contingency Table Approach ~ Chi-square Test
Mi over 3-year period
Deus ates | Ver Wo Tear
User i ra 7
Non vser_| On, On ma
Total [ra ™a 7
P= POM over 3.yr periodlOC user)
P= POM! over 3-y periodlon OC user)
+ Mas ps = pave th psf pa
Ce ‘—_
a
Contingency Table Approach
» Reade
pemze-nateix(c( 19,4907, 7,9983) rrow = 2, neal = 2,
yrou = TRUE)
>enteg.test(t22)
continuity correction
ata: 122
0.005626
squared = 7.8665, af = 1, prvaluea
Fisher's Exact Test
> A retoipectve dit stady on cardiovascular dase (CVD) among
ren ages 50-54 n a speci county who ded ove 9 T-menth period.
‘Type of Dict
Cause of Death | High Salt_Low Sat | Total
Ton-OV 7 BS
vo 5 o_| as
Toad 7 33 |e
» Hypothesis
pr and Heep < pa,
where
pi =Pfhigi-salt dizt!non CV death)
Plaigi-slt dit CV death)
a
The Urn (Hypergeometic) Model
Color ofthe ball | Drawn Not drawn | Total
She aes Xanlaend
Red m=X mom tx]
Total 7 ma [+e
fora
ST
Fisher's Exact Test
» Pevaie
~ the probability of geting 2 data as extreme as or more
‘extreme than the observed data if Tip was tue,
~ This probability can be computed under the assumption that cow
realm taal margins are Gel
+ Tho Um (Hypergcometic) model: Suppose an um contains ns
blue balls and ns re balls. and m, balls are drawn randomly. What is
‘the probability that actly ofthe Balls are Bue?
Ce
a
Fisher's Exact Test
Returning tothe CVD example, assume the row totals ae fed
The ur model can be applied
Type of Diet
‘Cause of Death [Tigh Satt_Low Sat [ Torr
Non VO 73 m=
vo 30 [ms
Tor 73
Than the probability of getting a data as extreme as of more extreme
than the abvered data fH
pow = P(X $2) = PUY =0) + PX
= 017 + 105 +.252 =
) + PIX =2)a
Fisher's Exact Test
> In general assume the table rearranged in sucha way that
For the loversidad aterative Maps
For uppersided stenative Hm. > pe
povalue = PIX a) = PIX =a) + P(X = att) t+ POX =H)
> For the o-sdedsleratve Hpi # ps
prvalue = 2 x min|PUX Evaluate hypergeometric elstibuton in using phyper,r2.}.
Ce ae
a
Paired Samples ~ Example
Compare two chemotherapy regimens for Bea patients afer
mastectomy
~ Patients ate asigned to pairs matched on age (withia§ years)
land clinical conditions an fllned fr 8 years
“Treatment &
Treatment A | Sunive Die | Total
Sunive | 510 16] 505
Die Be poe eel
Toral [BIS 105 [BET re
» Assuming independent samples (WRONG assumption),
prop. teat (e(626, 616) -2+e(621 621)?
ppvalue= 0.441 = no significant diference between the two
frestrents
ST
Fisher's Exact Test
+ Reade
dezze-mutrine(2,25,5,90),ar0¥ © 2, acel = 2, byroe
Deinker- eat (220)
‘nteravivehypotbeia: tee ode ratio fa no onl 1
Ce
a
Paired Samples ~ McNemar's Test
A concordant pr fs 9 matched par whose outcomes ar the same
+ A discordant pie i a matched pair whose outcomes ae diferent
= Type A discordant pst: the treatment A member ofthe par has
the event but treatment Bamber doesnot
= Type B discordant pai siniarly dened
+ The concordant pats provide no information about siferences
between treatmentsa
Paired Samples ~ McNemar's Test
vletp
(a discordant par is of type 8),
= Ifthe teatments are equally fictive then we expet an equal
umber of type A and type 8 dscordant pairs. Thos we wish to test
iysy
2 ww Hy #12
= Let np and ng be the number af discordant and type A dscordant
pairs, respectively
The tes statistic of the McNemr's text is
(ra=nel= 0?
x
This is ecacly the sign test!
a
a
R codes ~ McNemar’s Test
> For large sample (nip > 20), we eam apply the norma method
prop. test (ara Aara.D, pe05,correct=THUE,
siternativer'tyo.sidee")
» For small samples (roy < 20), we can use
binon-tostGern_A,2°8,D,pr0.5, altornativen"tvo. sided")
Example: Assess the statistical sgnifeance ofthe chemo data
= prop.test -> pualue 0.0291
~ inom. teat = pralve = 0.0266
ST
R codes ~ McNemar’s Test
> table tenenar. vest (table)
Mefonar's Chi-equared teat with continuity
correction
Nekonar's chivaquared = 4.7619, éf = 1, prvalu
0.0201
Ce
a
Paired Samples ~ McNemar's Test
+ The sample sre need to conduct # two-sided test with significance
level and power I~ 3 is
42 VATE)
“Wpnlpa — 057
ster 9p tn 94 se popin o erns e
+ Pome aot
Powe
Plas en on tps 05am
provided ny > 20 and mppall~ pa) > 5.© 8 «© Contingency Taber
Test for association ~ Contingency table
The data canbe graphically displayed as
> Are the two stacked bar significantly diferent?
> Lower anes appesr more prevalent inthe controls ad higher ages in
TT
Test for association ~ Contingency table
Consider the following data from a case-control ca study
Age at fest bieth
status [290205242529 594335 | Toxo
Gse | 320 — 106 01463200 | 3D
ont | 42244322693 1092 __406_ | 10245
“oral |r 638 3008 1585 625 | Ta40
» Let pi, pa sro and ps be the probally dstribution of age at fst
birth © 20,2024, 21-20, 30-24 ang > Xo given that 9 person is
+ We wish tote if the same probability dstbution holds fr cases as
a
TT
The Null Hypothesis ~ Contingency table
“The null hypothess can be expressed 35
> Ha:mo association batmona the case-control stu and age ot ft
bin
» Hy no ssscietion betwsen A and B in the follwing x C table
+ Data is callcted in an 12 contingeney table with Oy, observation
inthe (,3)0h eal ¢ = Tyee =k. Let be the ow sum
and my, bethe column Sum. Let n = $n, be the fatal numberof
subjects
1 c
—_ {|
A |‘The Chi-square Test ~ Contingency table Test for association ~ Contingency table
Under Ho, > Entering the Frequencies 35 2 matrie
By >érage-natr(e(820, 1206, 2011 483, 220,1422, 4492,
"2699, 1092,406) row = 2, neo) = 6, byrow = TRUE)
> Under Hp, the test statistic hs a Ch square distribution with degree >jire-chieg. teat (retreg)
ee nee
2 (Og- Fu? a data: freq.
> Valid when no more that 20% of the expected frequencies are <5 [1,] 416.5793 1348,263 933.5967 371.8604 149.7007
ee ee ee Ce _—
—cn —
Chi-Square Test for Trend in Binomial Proportions: Chi-Square Test for Trend: R-Codes
+ Previous, we show some reatonshp between breast cancer and age
st fit birth, but i doesnot eur spctealy about the nature of We can us the prop tend test command of R fer this purpose
the relations. prop.trend.test(s, m, score)
> In porticuar, we notice an incessng tend in the proportion of
Ate ak beast cance n each stcedng cole + eis tr with he mumber of succes i ach group
Thus we ith ots + isa vector wth the sme ize in ech ou
Figs Tht taeda he's ee ee
tet Bs ee increasing or decreasing function of the S, » Hf there are ke groups, then x, n, and score should be of length ke
> Reference: Masel, AE. (1961). Analyzing qualtatve dataChi-Square Test for Trend: R-Codes
cts20, 2208, 1021, 483, 220)
> Ee CLITHD, $898, 390%, 1585, 625)
eet)
Seend. eee,
Chi-Square Goodness-of-Fit Test
» In Chapters 6,7 and 8, we assumed that the data came from an
underying probably model
+ In this section, we consider 2 general metho of testing for the
oodnese off of probably model
© Cri Seuare Goodness of Fit Test
Chi-Square Goodness-of-Fit Test
ample: The frequency dsribution of diastolic blood presse (OBP) of
11,736 alts ages 30.59 in Est Boston, given belon
Group Obsereé_ Expectee
(evil) Frequency _Frequengy
=o)
>i0,<00
Sa<7
Sm<80
San, <00
3,100
S o0,< 10
30
We with to test itis data came from a narml distribution,ED TT
Chi-Square Goodness-of Fit Test Cont'd, Chi-Square Goodness-of- Fit Test Cont'd.
The agreement betwen the observed and expected fequences can
Recall that the normal stributon i indexed by two parameter, be quantes using
ando?
» We estimate these parameters fom the dats by and S?, the
sample mean and vaiance
where is the total rumber of lasses an isthe number of
Th expaced eae of he ith es i the god porinete inte neta hd fo be cated
Banx Pex Ba
where [x and U; are the loner and upper elas limits ofthe ith dss. pralue = P63. 14 > Xap
+ nour ample we take 4 = ~2o and Ua =, + Ue this stony 0 mae than (1/5) ofthe expec eqenis
pee and neath oe
—_—— —— ee
Chi-Square Goodness-of-Fit Test: Example Chi-Square Goodness-of-Fit Test: R-Codes
+ frampe Ase th goodness ft fhe nal rin tthe
Dera
Le eta se(60, 210,10)
+ Te spleen ad standard cea ong fo the eee
eon, 30) iad
ea ee prob<-pnorm(U, 80,68, 12)-pnorn(L,80.68,12)
+ To empath potable ofthe dass, we ue rm Teervedce (6790, 3132, 4504, 604,219,680, 251
Se SComtsteerved
Spec ape
(60 X < m0) ~ pore, 80.68 12) —porm( 7, 8085 12) Toda Coenres™ expecta) 2/opected)
fe the fens bt ot) par tr iagentonereed) 1 2
farthest cls, P(X < 60) = paoen(0,8068, 12). eee eee
+ Since we estimating 2 pater and we hove eight dass inthe
feguny abe
a oe ee are© The Kappa Statistic
Measuring the Strength of Association
Survey 2
Survey 1 | Yes _No | Tota!
Yes [mn mia
No__| maim | ma
ic a
C be response categorie.
+ Leto; = ny/ and by = m/e the probabilities of response
centegary forthe frst and second survey,
Let ny = (ns +na)/n be observed concordance rate
> The expected concordance rate fe pe = EL a
TT
Measuring the Strength of Association
+ We at inerested in the degree of association between to categorical
vanabies
When the same variables messured more than once, the dagree of
association between the multiple measurements tls us about the
reproducbilty ofthe survey (also known 3 relly).
> Another name fer such association is concordance a there i
ratural paring relsorship among the observed valves,
Ce
TT
‘The Kappa Statistic
> A measure of reproccbilty of = suey is
=P
T= Fr
The quanti «interpreted 2s ollons
‘> 076 -+ Exealnt Reproducbilny
O4-¢ 20.75» Good Reproducity
Om 04+ Marginal Repoducbilsy
+ Reade:
nibrery (ert)
Bibrary(wea)
c-tablowwacrix(e(ayc,by4), nrow
appaCe.tabie)co
‘The Kappa Statistic
* Amount of best consumption reported by S87 female Amencan nurses
at too diferent survey,
Survey 2
Survey 1_| < 1 swings > L servings | Tota
Zisevinaginee] 13 7 BE
5 iservngiek| 69 20 ‘oo
Tat 2 Br 7
‘The Kappa Statistic
Compute she Kappa statistic and assess its statistical sigiicance
> asbesey(eri)
> Rbrary(oe)
> Rappataatrix(e(136, 69, 92, 240), nrov = 2))
vale Ae Pele)
‘netgnted 013782 0.04085 9.361 8, 7054-2