We will use the data from Table 12 in Section 2.2.
Table12 <- read.csv("https://sullystats.github.io/Statistics6e/Data/Chapter2/Table12.csv")
In Example 3, we are organizing the parking and camera violation fines into a frequency and relative frequency distribution. We use 50 as the lower class limit of the first class and a class width of 25. To create the frequency and relative frequency distribution requires a series of commands. First, we determine the lower class limits of each class:
LCL <- seq(50,325,25)
LCL
## [1] 50 75 100 125 150 175 200 225 250 275 300 325
NOTE: 50 is lower class limit of first class; 325 is the lower class limit of the first class with no observations; 25 is the class width.
Now, use the cut function to create the frequency distribution.
fine_cut <- cut(Table12$Fine, LCL, right=FALSE)
The right=FALSE argument means the right-endpoint is not included (that is, open). Now create the table using the tally command (from Mosaic). If necessary, install the Mosaic package.
install.packages("mosaic")
library(mosaic)
tally(~fine_cut)
## fine_cut
## [50,75) [75,100) [100,125) [125,150) [150,175) [175,200) [200,225) [225,250)
## 1 0 7 10 5 4 13 4
## [250,275) [275,300) [300,325)
## 5 0 1
Note: The notation [50,75) is interval notation. It means
$50 \(\leq fine < \$75\)
To obtain the relative frequency distribution, use the format = “prop” argument.
tally(~fine_cut,format="prop")
## fine_cut
## [50,75) [75,100) [100,125) [125,150) [150,175) [175,200) [200,225) [225,250)
## 0.02 0.00 0.14 0.20 0.10 0.08 0.26 0.08
## [250,275) [275,300) [300,325)
## 0.10 0.00 0.02