Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Univariate analysis

Univariate analysis studies one variable at a time to describe its centre, spread and shape — used by engineers to summarize data, detect outliers and prepare features for BI reports and further analysis.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Two-sentence practical view: In Business Intelligence an engineer uses univariate analysis to summarize each attribute (column) in a dataset before building dashboards, reports, or models. It finds central values, dispersion and outliers so downstream tasks (cleaning, feature selection, visualization, OLAP cubes) are correct and robust.

Key ideas

Start from first principles and simple definitions.

  • Variable: a measured quantity (numeric or categorical). We study one variable at a time in univariate analysis.
  • Population: the complete set of items of interest (all customers, all transactions). Symbol for population mean is μ, for population variance σ².
  • Sample: a subset of the population (data collected). Notation: sample values x₁, x₂, ..., x_n; sample mean is x̄ (read "x-bar"); sample variance is s².
  • Measure of central tendency: a single number summarizing the centre of data. Common measures: mean (arithmetic average), median (middle value of ordered data), mode (most frequent value).
    • Exact definitions: mean x̄ = (1/n) Σ_{i=1..n} x_i. Median is the value m so half observations ≤ m and half ≥ m (for even n median is average of two middle values). Mode is the value with highest frequency; may be multiple or none for continuous data.
  • Measures of dispersion: numbers describing spread. Range = max − min. Interquartile range (IQR) = Q3 − Q1 where Q1 and Q3 are 25% and 75% quantiles. Variance measures the average squared deviation from the mean; standard deviation is the square root of the variance (a linear scale of spread). The mean absolute deviation (MAD) is the average absolute deviation.
    • Population variance: σ² = E[(X − μ)²]. Sample variance (unbiased): s² = (1/(n−1)) Σ (x_i − x̄)². The denominator n−1 is the Bessel correction; it corrects bias so s² is an unbiased estimator of σ².
  • Shape measures: skewness measures asymmetry; defined (population) γ₁ = E[(X − μ)³]/σ³. Kurtosis measures tail weight/peakedness; (population) γ₂ = E[(X − μ)⁴]/σ⁴ − 3 (the −3 gives zero for the normal distribution).
  • Outlier rules: common rules are the IQR rule (points < Q1 − 1.5·IQR or > Q3 + 1.5·IQR) and z-score rule (|z| > 3 flagged; z = (x − x̄)/s). Explain each rule’s assumptions: IQR rule is non-parametric; z-score rule assumes approximately normal (or at least symmetric, light-tailed) data.
  • Histograms and frequency tables: group numeric values into bins and count frequency. Draw a histogram with x-axis labelled with bin ranges and y-axis frequency (or relative frequency). For exams: sketch bars contiguous (no gaps) and label bin boundaries and height. If bins have unequal widths, plot frequency density so the area of each bar is proportional to frequency. For categorical variables, use a bar chart (separated bars) and a frequency table; summarize with counts/proportions and the mode (mean/SD are not defined for nominal categories).
  • Boxplot: draw a box from Q1 to Q3, a line at median, whiskers to min and max inside fences, and mark outliers individually. Label Q1, median, Q3, fences (Q1 − 1.5·IQR, Q3 + 1.5·IQR).

Key derivations universities ask for (step-by-step):

  1. Computational formula for variance: show that Σ (x_i − x̄)² = Σ x_i² − n x̄². Start from expansion of square and cancel the linear term using Σ (x_i − x̄) = 0.
  2. Expectation of sum of squared deviations: derive E[Σ (X_i − X̄)²] = (n−1) σ² by writing Σ (X_i − μ)² = Σ (X_i − X̄)² + n (X̄ − μ)², taking expectation and substituting Var(X̄) = σ²/n.

Where to draw diagrams (exact instructions):

  • Histogram: draw horizontal axis labelled "value" and vertical axis labelled "frequency"; draw 5–8 contiguous bars; write bin ranges above/below each bar.
  • Boxplot: draw number line; draw rectangle from Q1 to Q3, vertical line in rectangle at median, whiskers to nearest non-outlier values, and small circles for outliers with their numeric labels if needed.

Assumptions to state in answers: whether you treat data as sample or population; whether normal approximation is used (for empirical rule); which formula for skewness/kurtosis convention you use (many possible sample formulae exist).

Formulas

x̄ = (1/n) Σ_{i=1..n} x_i — x̄ = sample mean, unit = same as x, applies to sample of n observations. median = middle value of ordered {x_i}; if n even then median = (x_{(n/2)} + x_{(n/2+1)})/2 — units same as x, applies to ordered sample. range = x_{(max)} − x_{(min)} — units same as x. Q1 = 25th percentile, Q3 = 75th percentile, IQR = Q3 − Q1 — units same as x. s^2 = (1/(n−1)) Σ_{i=1..n} (x_i − x̄)^2 — s² = sample variance (unbiased estimator), unit = (unit of x)^2, applies when estimating population variance from sample. s = sqrt(s^2) — s = sample standard deviation, unit = unit of x. CV = s / x̄ (or σ / μ for a population) — coefficient of variation (dimensionless), use when the mean is positive to compare relative variability across scales. σ^2 = E[(X − μ)^2] — population variance; μ is population mean, unit = (unit of X)^2. Σ_{i=1..n} (x_i − x̄)^2 = Σ_{i=1..n} x_i^2 − n x̄^2 — computational shortcut, used for hand calculations. z = (x − x̄)/s — sample z-score, unitless; use to compare relative position in sample. IQR outlier fences: lower = Q1 − 1.5·IQR, upper = Q3 + 1.5·IQR — units same as x. Population skewness γ1 = E[(X − μ)^3]/σ^3 — dimensionless. (Note: sample formulas vary; verify convention.) Empirical rule (normal): ≈68% within μ ± σ, ≈95% within μ ± 2σ, ≈99.7% within μ ± 3σ — applies when variable ≈ Normal distribution.

Worked examples

Example 1 — numeric summary and outliers (standard exam style) Data (n = 9): 10, 12, 13, 13, 14, 15, 15, 16, 20 (units: items sold) Steps:

  1. Order data (already ordered). Sum = 128. Mean: x̄ = 128/9 = 14.222... (units: items). Final: 14.222 items.
  2. Median is 5th value = 14 items. Mode(s): 13 and 15 (each twice) so bimodal: 13 and 15.
  3. Range = 20 − 10 = 10 items.
  4. Quartiles: lower half = {10,12,13,13} → Q1 = (12+13)/2 = 12.5. Upper half = {15,15,16,20} → Q3 = (15+16)/2 = 15.5. IQR = 3.0.
  5. IQR fences: lower = 12.5 − 1.5·3 = 8.0; upper = 15.5 + 4.5 = 20.0. Since 20.0 is exactly the upper fence, it is not flagged as an outlier by the strict > fence rule. So no outliers by IQR rule.
  6. Sample variance and SD: compute Σ (x_i − x̄)^2 (exact arithmetic gives 63.555555556). Then s^2 = 63.555555556 / (9−1) = 7.944444444 (items^2). s = sqrt(7.944444444) ≈ 2.819 (items). Final: s ≈ 2.819 items.
  7. z-score for 20: z = (20 − 14.2222)/2.8187 ≈ 2.05 (not >3), so again not an outlier by z-rule. Answer summary (bold): mean 14.222 items, median 14, mode 13 & 15, range 10, IQR 3, s ≈ 2.819, no outliers.

Example 2 — derivation asked in exams: computational formula and unbiasedness (a) Show Σ (x_i − x̄)^2 = Σ x_i^2 − n x̄^2. Proof steps: expand left: Σ (x_i^2 − 2 x_i x̄ + x̄^2) = Σ x_i^2 − 2 x̄ Σ x_i + n x̄^2. But Σ x_i = n x̄, so middle term = 2 x̄ · n x̄ = 2 n x̄^2. Thus result = Σ x_i^2 − 2 n x̄^2 + n x̄^2 = Σ x_i^2 − n x̄^2. (b) Show E[s^2] = σ^2 (sketch): write Σ (X_i − μ)^2 = Σ (X_i − X̄)^2 + n (X̄ − μ)^2. Take expectation: n σ^2 = E[Σ (X_i − X̄)^2] + n Var(X̄). But Var(X̄) = σ^2/n, so E[Σ (X_i − X̄)^2] = (n−1) σ^2. Dividing by (n−1) gives E[s^2] = σ^2. That is why we divide by n−1.

Common mistakes

  • Computing quartiles incorrectly by including or excluding the median wrongly for odd n; state the method used.
  • Treating a value equal to the IQR fence as an outlier (the usual IQR rule flags > fence, not ≥).
  • Using the empirical rule on data not approximately normal without saying so.
  • Forgetting units: variance has squared units, mean has original units.

For your exam

Kinds of questions you will see: definitions (mean, variance, skewness), short notes (IQR, boxplot), derivations (computational variance identity, proof of Bessel correction), numericals (compute mean/median/SD/outliers on a small dataset), sketch diagrams (histogram/boxplot) and short programs/pseudocode to compute summaries. What a full-marks answer includes:

  • State whether data is sample or population and write symbols used (n, x̄, μ, s, σ).
  • Show every step: sums, intermediate values, and units.
  • For derivations, state assumptions (independent identically distributed if computing expectations) and show algebra cleanly.
  • For diagrams: label axes, bins/quartiles, fences, and mark outliers.
  • For skewness/kurtosis mention which sample formula or population formula you use (many conventions exist), and state any approximation assumptions.

Quick check

  1. Define sample mean and sample standard deviation in one line each.
  2. For data 3, 7, 7, 10 what is the median and mode?
  3. Using IQR rule, are 2 and 20 outliers for data 3,5,7,9,11,13? Answers: 1) x̄ = (1/n) Σ x_i; s = sqrt((1/(n−1)) Σ (x_i − x̄)^2). 2) Median = (7+7)/2 = 7; Mode = 7. 3) For data sorted 3,5,7,9,11,13 Q1=(5+7)/2=6, Q3=(9+11)/2=10, IQR=4, fences 6−6=0 and 10+6=16 → 2 >0 and <16 so not outlier; 20 >16 so 20 would be outlier (if present).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?