User Tools

Site Tools


hcistats:chisquare

Chi-square, Fisher's exact, and McNemar's test


Chi-square test

A Chi-square test is a common test for nominal (categorical) data. One application of a Chi-square test is a test for independence. In this case, the null hypothesis is that the occurrence of the outcomes for the two groups is equal. For example, you have two user groups (e.g., male and female, or young and elderly). And you have nominal data for each group, for example, whether they use mobile devices or which OS they use. So, your data look like this. If your data of the two groups came from the same participants (i.e., the data were paired), you should use the McNemar's test.

Own device ADon't own device A
Male255
Female1515
WindowsMacLinux
Young16113
Old2181

And now you are interested in figuring out whether the outcomes for the two groups were statistically equal. The assumption of Chi-square is that the samples are taken independently or are unpaired. If not, you need to use McNemar's test. And if you have only a small sample size, you should use the Fisher's exact test.


Effect size

The effect size of a Chi-square test can be described by phi or Cramer's V. If your data table is 2 x 2, you will calculate phi (k=2 in the equation below) and otherwise, Cramer's V (k>2 in the equation below) . But the calculation is pretty much the same and it is as follows:

,

where N is the total number of the samples, and k is the number of the rows or columns, whichever smaller, in your data table. And the chi-squared here is the value without any correction. Here are values which are considered small, medium and large sizes.

small sizemedium sizelarge size
Cramer's phi or V0.100.300.50

R code example

Let's use the examples above. First, prepare the data.

data <- matrix(c(25, 5, 15, 15), ncol=2, byrow=T) data2 <- matrix(c(16, 11, 3, 21, 8, 1), ncol=2, byrow=T)

And run a Chi-squared test.

chisq.test(data) Pearson's Chi-squared test with Yates' continuity correction data: data X-squared = 6.075, df = 1, p-value = 0.01371 chisq.test(data2) Pearson's Chi-squared test data: data2 X-squared = 2.1494, df = 2, p-value = 0.3414

So, the first example has a significant difference, which means the ownership of device A significantly differs between male and female users. The effect size of the first test can be calculated with vcd package:

library(vcd) assocstats(data) X^2 df P(> X^2) Likelihood Ratio 7.7592 1 0.0053440 Pearson 7.5000 1 0.0061699 Phi-Coefficient : 0.354 Contingency Coeff.: 0.333 Cramer's V : 0.354

For a 2×2 table, you can also calculate the odds ratio. The odds ratio is how the probability of the phenomena is affected by the dependent variable. This can be calculated as ad / bc.

Own device ADon't own device A
Malea = 25b =5
Femalec = 15d = 15
(25 * 15) / (5 * 15) 5

How to report

You can report the results of a Chi-square test like this:

Our Chi-square test with Yates' continuity correction revealed that the percentage of the ownership of device A significantly differed by gender ((1, N = 60) = 6.08, p < 0.01, = 0.35, the odds ratio is 5.0).


Fisher's exact test

You can instead use Fisher's exact test if your sample size is small. It is hard to say how many samples are small, but in general, it is better to use a Fisher's exact test than a Chi-square test when you have small than 10 in any cell of your data table (like the examples above).

R code example

Running a Fisher's exact test is pretty similar to Chi-square.

fisher.test(data) Fisher's Exact Test for Count Data data: data p-value = 0.0127 alternative hypothesis: true odds ratio is not equal to 1 95 percent confidence interval: 1.335859 20.757326 sample estimates: odds ratio 4.859427

How to report

How to report the results of a Fisher's exact test is pretty much the same as the Chi-square test. Unlike Chi-square test, you don't have any statistics like chi-squared. So, you just need to report the p value. Some people include the odd ratio with the confidence intervals.


McNemar's test

McNemar's test is basically a paired version of Chi-square test. Let's say you asked whether the participants liked the device before and after the experiment.

After experiment
Yes No
Before experimentYes62
No84

Here, what you want to test is whether the number of the participants who liked the device were significantly changed between before and after the experiment.


Effect size

The effect size of the Fisher's exact test can be calculated in the same way as the one for the Chi-square test.


R code example

Running a McNemar's exact test is pretty similar to Chi-square.

data <- matrix(c(6, 2, 8, 4), ncol=2, byrow=T) mcnemar.test(data) McNemar's Chi-squared test with continuity correction data: data McNemar's chi-squared = 2.5, df = 1, p-value = 0.1138

Thus, we cannot reject the null hypothesis, and it means that the number of the participants who liked the device were not significantly changed between before and after the experiment. As you can see here, mcnemar.test() automatically makes correction for continuity. You can disable it with correct=F option, and the results will become the same with the function for Cochran Cochran's Q test.


McNemar's test and binomial test

In SPSS, the binomial distribution is used for McNemar's test. Thus, the results look different from those you can get in R. A binomial test is very similar to McNemar's test, but its null hypothesis is that the ratio of the two categories is equal to an expected distribution. In most cases, a binomial test is used for testing whether two categories are equally likely to occur.

Question 2 (post-treatment)
Yes No
Question 1 Yes a b
(pre-treatment) No c d

More precisely, you need to use a binomial test rather than McNemar's test if b+ c in the 2×2 table is small. However, in R, you can run McNemar's test with continuity correction, so it will cause a big problem because the results of a binmoal test and McNemar's test with continuity correction become similar.

If you want to do a binomial test like SPSS does, you need to use binomial function. And you need two numbers, which is the total count for the cases where the participants flipped the responses (i.e., b+ c. In the example we are using, 2 + 8 = 10), and the number of one of these two cases (i.e., 2 or 8).

After experiment
Yes No
Before experiment Yes 6 2
No 8 4
binom.test(2, 10, 0.5) Exact binomial test data: 2 and 10 number of successes = 2, number of trials = 10, p-value = 0.1094 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.02521073 0.55609546 sample estimates: probability of success 0.2

In this case, the p value is pretty close regardless of the ways to do a McNemar's test.


How to report

How to report the results of a McNemar's test is pretty much the same as the Chi-square test.


Comments

Guest, 2015/02/16 02:13
Wow this really help thank you so much
Guest, 2015/03/07 00:10
# "chisq.test(data2)" gives a different results from the one shown above, with a warning message.



> data2 <- matrix(c(16, 11, 3, 21, 8, 1), ncol=2, byrow=T)

> chisq.test(data2)



Pearson's Chi-squared test



data: data2

X-squared = 19.465, df = 2, p-value = 5.932e-05



Warning message:

In chisq.test(data2) : 카이제곱 approximation은 정확하지 않을수도 있습니다 (roughly, chi-square approximation may not be correct.)
Guest, 2015/03/07 00:18
# continuation from the above
# I wonder if the following result of Fisher's exact test for 'data2' indicates it is significant
# unlike the chi-square test for the same data shown above.

> fisher.test(data2)

Fisher's Exact Test for Count Data

data: data2
p-value = 2.335e-05
alternative hypothesis: two.sided
Guest, 2015/04/09 17:53
Am I wrong to think that the number of columns assigned to data2 be 3, instead of 2?

data2 <- matrix(c(16, 11, 3, 21, 8, 1), ncol=3, byrow=T)
Guest, 2016/01/30 23:06
How P-value is computed, please
sildenafil viagra, 2016/09/14 18:21
Wow because this is great job! Congrats and keep it up. weferhervvbt
ASikebrecrealiBN, 2016/09/19 19:44
Yaboo! Don't worry about them, though: they will come out in the next process. https://www.levitradosageus24.com/levitra-what-dosage/ Try to control your breathing, engage in foreplay, kissing, feeling your body and then delivered to the sex partner. One of the main causes will be premature ejaculation.
Godeagow, 2016/12/11 21:20
<a href="http://dommtester1.com">dommtester1.com</a>
[url - http://dommtester4.com
"http://dommtester2.com" - dommtester2.com
http://dommtester.com
http://dommtester3.com - dommtester3.com


Абулия
kefeMest, 2017/01/22 09:07
<a href="http://zsearchdom1.com">zsearchdom1.com</a> <a href=http://zsearchdom2.com>zsearchdom2.com</a> <a href=http://zsearchdom3.com>zsearchdom3.com</a> http://zsearchdom5.com
Curtisgype, 2017/01/27 00:25
ptmmscm

http://www.puntocomadv.it/855-nike-shox-nero-oro
http://www.casevacanzesottoalduomo.it/air-max-90-special-edition-518.php
http://www.escargot-de-monceau.fr/reebok-montant-homme-164.php
http://www.animalcare.fr/adidas-stan-smith-original-homme-658.html
http://www.animalcare.fr/adidas-stan-smith-rose-scratch-833.html

<a href=http://www.microquadcopter.fr/converse-noir-strass-631>Converse Noir Strass</a>
<a href=http://www.uial.it/775-asics-cumulus-15.html>Asics Cumulus 15</a>
<a href=http://www.giovanni17.it/nike-roshe-one-ld-1000-975.htm>Nike Roshe One Ld 1000</a>
<a href=http://www.giovanni17.it/nike-roshe-one-nere-zalando-026.htm>Nike Roshe One Nere Zalando</a>
<a href=http://www.wildvisions.it/air-jordan-12-retro-the-master>Air Jordan 12 Retro The Master</a>
Thomassaw, 2017/01/28 14:51
oqwoxui

http://www.lldlm.fr/813-chaussure-asics-trail.html
http://www.comite-jumelage-vigneux-sur-seine.fr/052-saucony-chaussure.html
http://www.deco-at.fr/707-nike-cortez-ultra-white
http://www.uial.it/587-scarpe-asics-uomo-running.html
http://www.clinicaviaemilia.it/nike-free-run-5.0-grigie-499

<a href=http://www.caminowatch.fr/adidas-gazelle-og-rouge-pas-cher-961.html>Adidas Gazelle Og Rouge Pas Cher</a>
<a href=http://www.retedipli.it/777-saucony-shadow-nere-e-bianche.html>Saucony Shadow Nere E Bianche</a>
<a href=http://www.lucilepeuch.fr/nike-air-huarache-noir-daim-641.php>Nike Air Huarache Noir Daim</a>
<a href=http://www.animalcare.fr/adidas-stan-smith-femme-or-461.html>Adidas Stan Smith Femme Or</a>
<a href=http://www.turismolastminute.it/147-vans-grigie-e-viola.html>Vans Grigie E Viola</a>
perfictgirls, 2017/01/31 05:43
egg insertion porngranniesluts http://www.minmag.mining.kz/index.php?option=com_k2&view=itemlist&task=user&id=2080463-brianna-blair-kitchen
http://subparticlesalternative.com/component/k2/itemlist/user/865691-madurita-se-viene
http://zoraholidays.com/index.php?option=com_k2&view=itemlist&task=user&id=675197-daddy-fucks-sleep-walking-daughter-porn
http://aseguranet.com/index.php?option=com_k2&view=itemlist&task=user&id=2336-hypnotism-ass-fuck
http://afamiaelsham.com/index.php?option=com_k2&view=itemlist&task=user&id=5795&amp;lang=en-jovencita-argentina-sabrosa-cojiendo
http://Www.reydreyes.com/index.php?option=com_k2&view=itemlist&task=user&id=576931-asako-honma-doble-penetracion
http://www.noncera.it/index.php?option=com_k2&view=itemlist&task=user&id=81784-bromance-fyff-creampie
I mean, I'd told him I intended to marry Jen, so he knew she and I would fill a pile to stammer about.Of course, it was nothing and I select no offense, but I must say you seem to be highly well wordy for a enslaved.We are successful in that my parents were rich and left us a smallish fortune, so I prefer not sustain to work/ He is eighteen years senior and has always a apex or 2 about my sundress, jewellery, and beget-up..
mydirtyhobby, 2017/02/02 17:17
mi vesina desnudaoops i cumed http://afina-mos.ru/component/k2/itemlist/user/86483-soando-con-mi-hija
http://www.larecasa.com.br/index.php?option=com_k2&view=itemlist&task=user&id=1767332-young-girlsfriend-guy-jerk-off-and-cum
http://www.Kaeledyrspasning.dk/index.php?option=com_k2&view=itemlist&task=user&id=254487-money-talks-lost-bet
http://Www.alians-tg.ru/component/k2/itemlist/user/2092198-public-girls-kiss
http://www.associazioneridere.it/index.php?option=com_k2&view=itemlist&task=user&id=94610-qual-o-nome-dessa-atrz-desse
http://Abarancapital.com/index.php?option=com_k2&view=itemlist&task=user&id=1673087-richelle-rhode-strips-and-plays-with-dildo-on-stage
http://www.fish-action.com/component/k2/itemlist/user/14115-japanese-grill-di-dream-boss
We hadn't needed a clubhouse for several years - we sensed we had outgrown the need for one - but I guess the privacy it frail to suggest would collected comply us well.She very likely did not even know.The next time queue moved, I permitted my gams to fumble her thighs a bit..
Richardmiff, 2017/02/16 10:53
tisirhc

http://www.misstilly.co.uk/nike-shoes-for-kids-boys-161.htm
http://www.cyberville.co.uk/769-new-balance-574-sale.htm
http://www.accomlink.co.uk/adidas-superstar-2015-women-944
http://www.offerzone.co.uk/179-converse-shoes-for-girls-with-heels.htm
http://www.lanarkunitedfc.co.uk/351-nike-air-max-90-black-and-white-mens

<a href=http://www.wandsworth-plumbing.co.uk/ray-ban-wayfarer-sunglasses-974.htm>Ray Ban Wayfarer Sunglasses</a>
<a href=http://www.offerzone.co.uk/316-converse-trainers-sale-amazon.htm>Converse Trainers Sale Amazon</a>
<a href=http://www.southportsuperbikeshop.co.uk/042-nike-air-max-95-white-and-grey.html>Nike Air Max 95 White And Grey</a>
<a href=http://www.bike-courier.co.uk/max-nike-shoes-609.html>Max Nike Shoes</a>
<a href=http://www.bencookartist.co.uk/nike-air-force-1-white-gum-006.html>Nike Air Force 1 White Gum</a>
DouglasGYPE, 2017/02/17 03:30
duptykc

http://www.poloshirtsonlineshop.co.uk/lacoste-shoes-for-men-formal-356
http://www.offerzone.co.uk/816-ladies-converse-size-5-uk.htm
http://www.cyberville.co.uk/250-new-balance-996-revlite.htm
http://www.marrandmacgregor.co.uk/655-adidas-yeezy-boost-350-size-6.html
http://www.accomlink.co.uk/adidas-tubular-runner-woven-grey-320

<a href=http://www.giantfang.co.uk/air-max-95-601>Air Max 95</a>
<a href=http://www.bencookartist.co.uk/nike-air-force-1-high-outfit-black-465.html>Nike Air Force 1 High Outfit Black</a>
<a href=http://www.realmortgagefinance.co.uk/nike-air-shox-womens-625.php>Nike Air Shox Womens</a>
<a href=http://www.misstilly.co.uk/nike-trainers-womens-uk-sale-630.htm>Nike Trainers Womens Uk Sale</a>
<a href=http://www.evoslimmingcoupon.co.uk/nike-air-jordan-1-grey-and-black-348.php>Nike Air Jordan 1 Grey And Black</a>
Qddieknill, 2017/02/17 16:22
Post by : July 07,2014 from : fabuleux louis vuitton lv277 working chronograph white ceramic case silver dial lady size montre lv 076268. Replique Montre Suisse ... <a href="https://www.officielsaclv.com">Pas Cher Louis Vuitton</a> Sac Louis Vuitton pas cher wql mfd <a href=https://www.lvuittonsacsfrancesaclouisvuitton.com>Sac Louis Vuitton pas cher</a>echarpe louis vuitton 2014 homme bonne qualite coton pas cher 213 noir,Echapres Louis Vuitton femmes Nouveau,Echapres Louis Vuitton Pas Cher art xon
Richardmiff, 2017/02/18 03:53
ldcoudc

http://www.aspasi.es/572-saucony-xodus-5.0-gtx.htm
http://www.aspasi.es/278-saucony-comprar.htm
http://www.elregalofriki.es/ray-ban-lentes-685.php
http://www.lubpsico.es/ultra-boost-amazon-821.html
http://www.cuadros-famosos.es/902-camisas-ralph-lauren-polo-hombre.html

<a href=http://www.cdoviaplata.es/zapatos-mbt-sevilla-precios-419.html>Zapatos Mbt Sevilla Precios</a>
<a href=http://www.lubpsico.es/adidas-superstar-black-702.html>Adidas Superstar Black</a>
<a href=http://www.el-codigo-promocional.es/861-reebok-blanco-con-azul.aspx>Reebok Blanco Con Azul</a>
<a href=http://www.younes.es/183-nike-air-force-1-mid-white>Nike Air Force 1 Mid White</a>
<a href=http://www.felipealonso.es/740-vans-toy-story-woody-comprar.html>Vans Toy Story Woody Comprar</a>
Richardmiff, 2017/02/19 21:55
cicrcuy

http://www.cars-wrapping.co.uk/528-nike-free-flyknit-4.0-womens-grey.html
http://www.howzituk.co.uk/262-nike-flyknit-air-max-womens-2015.html
http://www.lanarkunitedfc.co.uk/612-nike-air-max-90-ltr
http://www.ukfinanceguide.co.uk/456-nike-air-max-1-essential-white-blue.html
http://www.ukbriberyact2010.co.uk/nike-free-5.0-boys-399.html

<a href=http://www.marrandmacgregor.co.uk/079-adidas-yeezy-boost-350-buy-online.html>Adidas Yeezy Boost 350 Buy Online</a>
<a href=http://www.accomlink.co.uk/adidas-nmd-black-camo-908>Adidas Nmd Black Camo</a>
<a href=http://www.lanarkunitedfc.co.uk/442-nike-air-max-90-ultra-br-mens-shoe>Nike Air Max 90 Ultra Br Mens Shoe</a>
<a href=http://www.hairextensionscity.co.uk/072-roshe-run-women-outfit-shorts.html>Roshe Run Women Outfit Shorts</a>
<a href=http://www.cars-wrapping.co.uk/098-nike-free-rn-flyknit-with-jeans.html>Nike Free Rn Flyknit With Jeans</a>
Richardmiff, 2017/02/20 08:59
tbjbesn

http://www.wvaegir.nl/adidas-superstar-w-schoenen-roze-wit-168.php
http://www.fitkid-inform.de/jordan-kappe-für-kinder.php
http://www.ausbildung-in-pflegeberufen.de/presto-weiß-preis-640.html
http://www.gisela-immich.de/544-nike-cortez-wmns
http://www.deermedia.de/hollister-weste-pink

<a href=http://www.visrestaurantlepescadou.nl/831-adidas-stan-smith-aanbieding.html>Adidas Stan Smith Aanbieding</a>
<a href=http://www.bootlegdjcafe.nl/new-balance-schoenen-hardlopen-520.php>New Balance Schoenen Hardlopen</a>
<a href=http://www.srbijaleverkusen.de/nike-free-damen-schwarz-grau-282.php>Nike Free Damen Schwarz Grau</a>
<a href=http://www.12deliver.nl/510-saucony-grid-8000.php>Saucony Grid 8000</a>
<a href=http://www.geschenkemachen.de/830-adidas-ultra-boost.html>Adidas Ultra Boost</a>
Curtisgype, 2017/02/23 12:36
mhrvwop

http://www.mis-printed.se/594-timberland-black-shoes.html
http://www.zonnigemuziek.nl/306-nike-basketball-shoes-2006.htm
http://www.nocnsfsportconventie.nl/358-adidas-sneakers-zwart-dames.php
http://www.frbk.se/ny-yankees-keps-stadium.html
http://www.nocnsfsportconventie.nl/468-adidas-nmd-xr1-dames.php

<a href=http://www.sanysad.es/nike-blazer-low-black-034.html>Nike Blazer Low Black</a>
<a href=http://www.itcigarrilloelectronico.es/196-zapatillas-adidas-energy-boost-mujer.html>Zapatillas Adidas Energy Boost Mujer</a>
<a href=http://www.slojdakademin.se/976-puma-creepers-fenty-rihanna.php>Puma Creepers Fenty Rihanna</a>
<a href=http://www.bliv-ergoterapeut.nu/tênis-timberland-gorge-c2-vermelho-440.php>Tênis Timberland Gorge C2 Vermelho</a>
<a href=http://www.herz-jesu-huellen.de/nike-air-max-2017-314.html>Nike Air Max 2017</a>
Please enter your comment. You cannot remove your comments by yourself. So double-check before you submit.:
If you can't read the letters on the image, download this .wav file to get them read to you.
 
hcistats/chisquare.txt · Last modified: 2014/08/14 05:22 by Koji Yatani

Page Tools