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.

Bivariate and multivariate analysis

Clear, exam-focused notes on bivariate and multivariate analysis: definitions, formulas, derivations (least squares), hypothesis tests for correlation, multiple regression (normal equations, matrix form), VIF and partial correlation, with worked examples and common mistakes.

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-variable (bivariate) and many-variable (multivariate) analysis let engineers find, measure and test relationships between variables in data — for example, how study hours relate to exam marks (bivariate) or how marks depend on hours, attendance and prior grade (multivariate). These methods are core to Business Intelligence (BI) tasks such as feature selection, building predictive models, and explaining KPIs from data.

Key ideas

  • Pearson correlation coefficient (population): ρ (rho) is a scale-free measure of linear association: ρ = Cov(X,Y) / (σX σY). Range: -1 ≤ ρ ≤ 1. ρ = 0 means no linear association (not necessarily independence). Units: unitless.

  • Sample Pearson correlation (r): computed from sample data as the sample covariance divided by product of sample standard deviations. Used to estimate ρ and test hypotheses.

  • Simple linear regression: model Y = β0 + β1 X + ε where β0 is intercept, β1 slope, and ε error term with E[ε]=0. Ordinary Least Squares (OLS) finds β0, β1 minimizing sum of squared residuals Σ(yi - β0 - β1 xi)^2. Assumptions for classical inference: linearity, independence of errors, homoscedasticity (constant variance), exogeneity: E[ε|X]=0 (errors have zero mean conditional on X), and (for t-tests) normality of errors. Under Gauss–Markov assumptions (first four), OLS estimators are BLUE (Best Linear Unbiased Estimators).

  • Derivation of OLS (simple case) — step by step (exam style):

    1. Write SSE(β0,β1) = Σ(yi - β0 - β1 xi)^2.
    2. Set partial derivatives to zero: ∂SSE/∂β0 = -2 Σ(yi - β0 - β1 xi) = 0 and ∂SSE/∂β1 = -2 Σ xi(yi - β0 - β1 xi) = 0.
    3. Solve the two normal equations: Σ yi = n β0 + β1 Σ xi Σ xi yi = β0 Σ xi + β1 Σ xi^2
    4. Solve for β1 = Σ(xi - x̄)(yi - ȳ) / Σ(xi - x̄)^2 = Sxy / Sxx and β0 = ȳ - β1 x̄.
  • Coefficient of determination (R^2): proportion of variance in Y explained by model: R^2 = SSR / SST = 1 - SSE/SST. For simple linear regression R^2 = r^2. Adjusted R^2 = 1 - (SSE/(n - p - 1))/(SST/(n - 1)); it penalizes adding predictors and may decrease when irrelevant variables are added.

  • Hypothesis test for correlation (two-sided): under bivariate normal assumption, test H0: ρ = 0 using t = r·sqrt((n-2)/(1 - r^2)) with df = n - 2. In simple linear regression with an intercept, this is equivalent to the t-test for H0: β1 = 0.

  • Multivariate (multiple) linear regression: model Y = β0 + β1 X1 + β2 X2 + ... + βp Xp + ε. In matrix form: y = Xβ + ε where X is n×(p+1) with first column ones.

  • Normal equations (matrix): X'X β = X'y. OLS solution (if X'X invertible): β̂ = (X'X)^{-1} X'y. This requires X to have full column rank (no perfect multicollinearity).

  • Partial correlation: correlation between X and Y after removing linear effect of Z. For single control Z, r_{XY·Z} = (r_{XY} - r_{XZ} r_{YZ}) / sqrt[(1 - r_{XZ}^2)(1 - r_{YZ}^2)].

  • Multicollinearity: strong correlation among predictors leads to unstable coefficient estimates (large variance). Variance Inflation Factor (VIF) for predictor j: VIF_j = 1 / (1 - R_j^2), where R_j^2 is R^2 when regressing predictor j on the other predictors. Rule of thumb: VIF > 10 indicates serious multicollinearity.

  • Always remember: correlation ≠ causation. Bivariate linear relation may be due to confounding variables.

(diagram to draw for exams) Scatterplot with X on horizontal axis and Y on vertical; plot points, draw best-fit line y = β0 + β1 x; label residuals as vertical distances from points to line; indicate sample means x̄ and ȳ on axes and show one product (xi - x̄)(yi - ȳ) for covariance.

Formulas

Cov(X,Y) = E[(X - μX)(Y - μY)] μX, μY are population means; units = units(X)·units(Y); applies to population definition.

Sxy = Σ(xi - x̄)(yi - ȳ) Sxy is sum of cross-deviations; units = units(X)·units(Y); used in sample formulas.

Sample covariance s_xy = Sxy / (n - 1) units = units(X)·units(Y); applies to sample.

r = s_xy / (s_x s_y) r is sample Pearson correlation; s_x, s_y are sample standard deviations; unitless; applies to sample linear association.

β1 = Sxy / Sxx where Sxx = Σ(xi - x̄)^2 slope of simple regression; units = units(Y)/units(X).

β0 = ȳ - β1 x̄ intercept; units = units(Y).

R^2 = 1 - SSE/SST where SST = Σ(yi - ȳ)^2, SSE = Σ(yi - ŷi)^2 unitless; proportion explained. Adjusted R^2: R̄^2 = 1 - (SSE/(n - p - 1))/(SST/(n - 1)) (p = number of predictors; intercept is the +1 in the df).

t = r * sqrt((n - 2) / (1 - r^2)) t-statistic for testing ρ = 0, df = n - 2.

β̂ = (X'X)^{-1} X' y matrix OLS solution; X' is transpose of X; applies when X'X invertible. Error variance estimate: σ̂^2 = SSE / (n - p - 1); covariance of coefficients: Var(β̂) = σ̂^2 (X'X)^{-1}; overall F-test for multiple regression (H0: all slopes = 0): F = (R^2/p)/((1 - R^2)/(n - p - 1)) with df = (p, n - p - 1).

VIF_j = 1 / (1 - R_j^2) variance inflation factor for predictor j; unitless.

r_{XY·Z} = (r_{XY} - r_{XZ} r_{YZ}) / sqrt((1 - r_{XZ}^2)(1 - r_{YZ}^2)) partial correlation controlling Z.

Worked examples

Example 1 — Bivariate correlation and simple regression (numerical) Data: study hours X (hours) = [1,2,3,4,5]; marks Y (out of 100) = [40,50,60,65,80]. n = 5.

  1. Compute means: x̄ = (1+2+3+4+5)/5 = 3 hours. ȳ = (40+50+60+65+80)/5 = 295/5 = 59 marks.
  2. Deviations and products: Σ(xi - x̄)^2 = 10; Σ(yi - ȳ)^2 = 920; Σ(xi - x̄)(yi - ȳ) = 95.
  3. Sample covariance s_xy = 95/(n-1) = 95/4 = 23.75 (hours·marks).
  4. Sample variances s_x^2 = 10/4 = 2.5 (hours^2), s_y^2 = 920/4 = 230 (marks^2).
  5. Sample standard deviations s_x = sqrt(2.5) = 1.5811 h, s_y = sqrt(230) = 15.1658 marks.
  6. Correlation r = s_xy / (s_x s_y) = 23.75 / (1.5811·15.1658) ≈ 0.990 (unitless).
  7. Regression slope β1 = Sxy/Sxx = 95/10 = 9.5 marks/hour. Intercept β0 = ȳ - β1 x̄ = 59 - 9.5·3 = 30.5 marks.
  8. Regression line: ŷ = 30.5 + 9.5 x. Predict for x = 6 hours: ŷ = 30.5 + 9.5·6 = 87.5 marks. Final answer: ŷ(6) = 87.5 marks.

Example 2 — Multiple regression (small matrix solve) Data (n = 4): (X1, X2, Y) rows: (1,0,3), (2,1,8), (3,0,7), (4,1,12). Units arbitrary. Compute sums: Σx1 = 10, Σx2 = 2, Σy = 30; Σx1^2 = 30, Σx2^2 = 2, Σx1 x2 = 6; Σx1 y = 88, Σx2 y = 20. Normal equations: 4 b0 + 10 b1 + 2 b2 = 30 10 b0 + 30 b1 + 6 b2 = 88 2 b0 + 6 b1 + 2 b2 = 20 Solving (substitute or invert) gives b0 = 1, b1 = 2, b2 = 3. Regression: ŷ = 1 + 2 x1 + 3 x2. Check on first row: ŷ = 1 + 2·1 + 3·0 = 3 which equals y. Final answer: β̂ = [1, 2, 3]ᵀ.

Common mistakes

  • Interpreting r or R^2 as causation.
  • Using correlation when relationship is non-linear (Pearson r measures linear association only).
  • Omitting intercept in regression without justification — forces line through origin and biases slope.
  • Ignoring multicollinearity (large standard errors, wrong signs) — always check VIF.
  • Using t-test for correlation without checking bivariate normality assumption.

For your exam

Types of questions: define terms (covariance, correlation, partial correlation, VIF), derive OLS normal equations for simple regression, compute r and regression line from a small dataset, solve normal equations for multiple regression (small n, p), explain assumptions and Gauss–Markov theorem, calculate and interpret R^2 and adjusted R^2, compute VIF or partial correlation. Full-marks answers include formulas, assumptions, step-by-step derivations, and numeric checks (units, means).

Quick check

  1. Define sample covariance in one line. 2) Give the OLS formula for multiple regression in matrix form. 3) If r = 0.8 and n = 10, compute t for test of ρ = 0. Answers: 1) Sample covariance s_xy = Σ(xi - x̄)(yi - ȳ)/(n - 1). 2) β̂ = (X'X)^{-1} X' y (when X'X invertible). 3) t = 0.8 * sqrt((10 - 2)/(1 - 0.8^2)) = 0.8 * sqrt(8 / (1 - 0.64)) = 0.8 * sqrt(8 / 0.36) = 0.8 * sqrt(22.222...) = 0.8 * 4.714 = 3.771 (df = 8).

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

Stuck on something here?