Set environment
library(modeest)
library(tidyr)
library(kableExtra)
Define 2 sets of data
set1 <- c(10,2,3,2,4,2,5)
set2 <- c(20,12,13,12,14,12,15)
Central Tendency: compute mean, medium, mode
ct_set1 <- c( mean(set1), median(set1), mfv(set1) )
ct_set2 <- c( mean(set2), median(set2), mfv(set2) )
Variation: compute range, interquartile, variance, & standard deviation
v_set1 <- round( c(range(set1), IQR(set1), var(set1), sd(set1) ), 2 )
v_set2 <- round( c(range(set2), IQR(set2), var(set2), sd(set2) ), 2 )
Results: Central Tendency
ct <- as.data.frame(rbind(ct_set1,ct_set2) )
colnames(ct) <- c("Mean","Median","Mode")
# print
ct %>% kbl(align = "ccc") %>%
kable_styling(full_width = F)
| Mean | Median | Mode | |
|---|---|---|---|
| ct_set1 | 4 | 3 | 2 |
| ct_set2 | 14 | 13 | 12 |
Results: Variation
v1 <- as.data.frame( rbind(v_set1,v_set2) )
# combine the 2 columns of 'range' into 1
v2 <- v1 %>%
unite("tmp", V1:V2, sep="-")
colnames(v2) <- c("Range","Interquartile","Variance", "Standard Deviation")
# print
v2 %>% kbl(align = "cccc") %>%
kable_styling(full_width = F)
| Range | Interquartile | Variance | Standard Deviation | |
|---|---|---|---|---|
| v_set1 | 2-10 | 2.5 | 8.33 | 2.89 |
| v_set2 | 12-20 | 2.5 | 8.33 | 2.89 |
Discussion
Central Tendency and Variation provide 2 ways to describe data. The measures of center show the datasets’ difference in their numeric values. The measures of variation broadly show the degree to which they vary; it seems to hints at little variation - only the range provides a clue what the underlying values may look like.
The coefficient of variation can be used to compare the datasets: \(CV = (\frac{S}{\bar x} ) \cdot 100\)
\(CV_{set1} =\) 72.17%
\(CV_{set2} =\) 20.62%
While both datasets have the same standard deviation, they differ relative to their mean.
GitHub
Related file(s) can be found at Git Me