Section 12 Numeric: Descriptive Statistics

12.1 Descriptive statistics

Function Explanation
length Number of elements in a vector
sum Sum of the values in a vector
min Minimum of a vector
max Maximum of a vector
mean Mean of the values in a vector
median Median of the values in a vector
quantile Quantile of a vector
range Range (min, max) of a vector
var Variance
sd Standard deviation

12.2 Central tendency of data

  • Mean

  • Median

  • Mode

  • Quartiles

  • Median Absolute Deviation (MAD): Compute the median absolute deviation, i.e., the median of the absolute deviations from the median, and (by default) adjust by a factor for asymptotically normal consistency.

  • Box plot stats: Tukey’s five number summary (minimum, lower-hinge, median, upper-hinge, maximum) for the input data.

12.3 Dispersion of data

  • Range
  • Inter-quartile range
  • Standard Deviation

12.4 Example 1

12.4.1 Central tendency of data

x <- c(0, 2, 4, 6, NA, 8, 4, 5, 15, 11, 4, 7)

mean(x, na.rm=TRUE)
median(x, na.rm=TRUE)

Mode <- function(x) {
  ux <- unique(x)
  # tab <- ux[which.max(tabulate(match(x, ux)))]
  tab <- tabulate(match(x, ux))
  modex <- ux[tab == max(tab)]
  return(modex)
}

Mode(x)

quantile(x=x, probs=c(0.25,0.50,0.75), na.rm=TRUE)

mad(x, na.rm=TRUE)

fivenum(x, na.rm = TRUE)

12.5 Example 2

12.5.1 Dispersion of data

x <- c(0, 2, 4, 6, NA, 8, 4, 5, 15, 11, 4, 7)

range(x, na.rm=TRUE)

sd(x, na.rm=TRUE)

IQR(x=x, na.rm=TRUE)

rX <- quantile(x=x, probs=c(0.25,0.50,0.75), na.rm=TRUE)
str(rX)
unname(rX[3] - rX[1])