2  Descriptive Statistics

3 Mean versus median

3.1 Variance

Show the code
x <- c(97.88, 107.91, 88.26, 115.21, 87.38)

\[ s^2 = \frac{\Sigma(x_i - \bar{x})^2}{n - 1} \tag{3.1}\]

Show the code
variance_vis(x, plot_deviances_x = 4, plot_deviances = FALSE, plot_population_variance = FALSE) +
    ylim(c(-1, 5)) + theme(axis.text.y = element_blank()) +
    annotate('text', x = mean(x) + (max(x) - mean(x)) / 2, y = 4,
             label = bquote("x - bar(x)"), parse = TRUE, vjust = 1.5, size = 8)
Figure 3.1: Deviation for the largest value.
Show the code
variance_vis(x, plot_deviances_x = 4, 
             plot_deviances = 4, 
             plot_population_variance = FALSE) +
    ylim(c(0, 20))
Figure 3.2: Squared deviation for the largest value.
Show the code
variance_vis(x, 
             plot_deviances = TRUE, 
             plot_population_variance = FALSE) +
    ylim(c(0, 20))
Figure 3.3: Squared deviation for all observations.
Show the code
variance_vis(x, 
             plot_deviances = TRUE, 
             plot_population_variance = TRUE,
             plot_sample_variance = TRUE) + 
    ylim(c(0,35))
Figure 3.4: Squared deviation for all observations along with population and sample variances.

\[ s = \sqrt{s^2} = \sqrt{\frac{\sigma(x_i - \bar{x})^2}{n - 1}} \tag{3.2}\]

This Shiny application can be run locally using the VisualStats::variance_shiny() function.