Descriptive Statistics: Summarizing and Stratifying Data

Calculate statistical tracking scalars—including arithmetic means, medians, variances, and stratified group metrics—while handling missing observation parameters cleanly.

1. Central Tendency and Variance Vectors

Raw numbers must be compressed into tracking indicators to communicate clinical realities. Central tendency metrics—like the mean (average) and median (middle point)—locate the center of your data distribution. Spread metrics—like variance and standard deviation—quantify how much your sample vectors drift away from that central point.

The Missing Value Trap

If a single cell within your data vector contains an unrecorded value or missing tracker (represented as NA), R mathematical algorithms will evaluate the final function output as NA. You must explicitly pass the 'na.rm = TRUE' flag to drop missing positions during calculation.

2. Group-Wise Data Stratification

Evaluating an entire patient group as a single block often masks critical insights. Stratification involves splitting continuous indicators by categorical variables (such as separating drug efficacy by a 'placebo' or 'active' treatment assignment). This enables you to compare separate subset distributions directly.

# Statistical calculations handling missing parameters:
# Compute global sample metrics safely
avg_weight <- mean(patients$weight_kg, na.rm = TRUE)
var_weight <- var(patients$weight_kg, na.rm = TRUE)

# Stratified subset summaries
placebo_mean <- mean(patients$weight_kg[patients$group == "Placebo"], na.rm = TRUE)
treated_mean <- mean(patients$weight_kg[patients$group == "Treated"], na.rm = TRUE)

Practical Assignment

Instructions:
1. Load the native 'mtcars' dataset.
2. Calculate the global mean and median for the 'mpg' (miles per gallon) vector.
3. Split and calculate the mean mpg specifically for cars with 4 cylinders ('cyl == 4') versus cars with 8 cylinders ('cyl == 8').

Proof of Work: Your analysis script is complete when your console displays isolated mean values that show a clear variation between the stratified groups.

Lesson Metadata

Duration: 40 mins
Module Scope: Bioinformatics Bootcamp 2026: Computational Thinking for Biomedical Research