Using RStudio, find \(P_{16}\),\(๐ท_{6}\),\(๐_{1}\),\(๐_{3}\) and the interquartile range of the following data set on the total weight, in kilograms, of ready-to-cook chicken inasal leg quarters sold by a frozen foods retail store during selected days of June and July. Does the sample have outliers? Data: 35.2, 7.0, 24.0, 42.4, 33.0, 27.5, 24.0, 21.0, 8.0, 45.6, 25.9, 14.8, 29.8, 21.0, 17.5, 9.7, 40.0, 18.8, 57.9, 21.0, 12.0, 12.0, 19.6, 51.5, 12.0, 36.8, 13.7, 32.8, 12.0, 10.5, 22.5, 19.5, 37.5, 35.0, 10.5, 33.6, 14.5, 36.5, 17.9, 26.9, 12.0, 41.5
\(~\)
Create the data vector:
totwt <- c(35.2, 7.0, 24.0, 42.4, 33.0, 27.5, 24.0, 21.0, 8.0, 45.6, 25.9, 14.8, 29.8, 21.0, 17.5, 9.7, 40.0, 18.8, 57.9, 21.0, 12.0, 12.0, 19.6, 51.5, 12.0, 36.8, 13.7, 32.8, 12.0, 10.5, 22.5, 19.5, 37.5, 35.0, 10.5, 33.6, 14.5, 36.5, 17.9, 26.9, 12.0, 41.5)
\(~\)
Generate the \(16^{th}\) percentile, \(P_{16}\):
p16 <- quantile(totwt, 0.16)
pander(p16)
16% |
---|
12 |
The \(16^{th}\) Percentile is 12kg. This would imply that 16% of the weight measurements are lower than 12 kg.
\(~\)
Generate the \(6^{th}\) decile, \(D_{6}\):
d6 <- quantile(totwt, 0.60)
pander(d6)
60% |
---|
26.5 |
The \(6^{th}\) Decile is 26.5 kg. This would imply that 60% of the weight measurements are lower than 26.5 kg.
\(~\)
Generate the \(1^{st}\) quartile, \(Q_{1}\):
q1 <- quantile(totwt, 0.25)
pander(q1)
25% |
---|
13.9 |
The \(1^{st}\) Quartile is 13.9 kg. This shows that 25% of the weights are lower than 13.9 kg.
\(~\)
Generate the \(3^{rd}\) quartile, \(Q_{3}\):
q3 <- quantile(totwt, 0.75)
pander(q3)
75% |
---|
34.65 |
The \(3^{rd}\) Quartile is 34.65 kg. 75% of the weight measurements are below 34.65 kg.
\(~\)
Generate the Interquartile Range:
IntRange <- q3-q1
# Or by using the IQR function:
IntQuaRange <- IQR(totwt)
pander(IntRange)
75% |
---|
20.75 |
pander(IntQuaRange)
20.75
The interquartile range is 20.75 kg.
\(~\)
Check for data outliers:
library(outliers)
library(EnvStats)
\(~\)
Create boxplot to initially assess presence of outliers:
boxplot(totwt, outcol = "red", cex=1.5)
\(~\)
Based on the boxplot, there are no outliers. This could be further verified by running the Rosnerโs Test for outliers. For the test, we set k to the default value of 3.
rosnerTest(totwt, k=3, warn=TRUE)
Results of Outlier Test
-------------------------
Test Method: Rosner's Test for Outliers
Hypothesized Distribution: Normal
Data: totwt
Sample Size: 42
Test Statistics: R.1 = 2.605014
R.2 = 2.345154
R.3 = 2.023399
Test Statistic Parameter: k = 3
Alternative Hypothesis: Up to 3 observations are not
from the same Distribution.
Type I Error: 5%
Number of Outliers Detected: 0
i Mean.i SD.i Value Obs.Num R.i+1 lambda.i+1 Outlier
1 0 24.87857 12.67611 57.9 19 2.605014 3.056723 FALSE
2 1 24.07317 11.69511 51.5 24 2.345154 3.046571 FALSE
3 2 23.38750 10.97781 45.6 10 2.023399 3.036097 FALSE
The boxplot, used to initially assess the presence of outliers, shows no extreme data points, hence, no outliers. This was verified by the Rosnerโs Test for outliers.