Measures of Dispersion

Interquartile Range

The interquartile range can be calculated using the IQR() function:

IQR(
  pss$stfdem, 
  na.rm = TRUE
)
How do you interpret this number?

Alternative Calculation of IQR

A more customizable alternative is to combine the diff() and quantile() functions. In the quantile() function, you specify the variable (\(1^{st}\) argument), the desired quantiles (\(2^{nd}\) argument), and finally exclude NA's. The function returns two values, and the diff() function calculates and outputs the difference between these two values.

diff(
  quantile(
    pss$stfdem, 
    probs = c(
      0.25,
      0.75
    ),  
    na.rm = TRUE
  )
)   

Standard Deviation & Variance

We obtain the standard deviation and variance using the following two functions:

sd(
  pss$stfdem, 
  na.rm = TRUE
)

var(
  pss$stfdem, 
  na.rm = TRUE
)
How could you alternatively derive the variance from the standard deviation?

Now, let’s take a step further into data processing and enter the tidyverse!