Introduction to Statistics (MAT/SST 115.03 2008S)
To do chi-squared tests in R, you use the
function. A typical form of chi-squared test (and the kind that matches
the form we see in this book) looks like the following:
For example, for the first chi-squared test of birthdays, we might write
Similarly, for the second test (Activity 24-2), we might write
Similarly, for the third test (Activity 24-3), we might write
By the time you hit 24-4 d, you should know what to do.
We'll start by creating vectors of counts and probabilities.
(Just so you know,
cld stands for
“country population leading digit”.)
cpld = c(55,36,22,23,15,14,12,12,5) benford = c(.301,.176,.125,.097,.079,.067,.058,.051,.046)
Those vectors make many things easier. To compute proportions, we
just divide each value in
cpld by the total population.
Similarly, to compute expected values, we multiply the Benford probabilities by 194.
Calculating the test statistic and p-value:
Copyright (c) 2007-8 Samuel A. Rebelsky.
This work is licensed under a Creative Commons
Attribution-NonCommercial 2.5 License. To view a copy of this
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.