StatBCS 7Regression 4 handout without solutions
Table of contents
- Statistics for Brain and Cognitive Sciences
- Multiple linear regression (MLR)
- Test of the regression coefficients
- Multicollinearity and Singularity
- ANOVA Table for MLR
- General Linear F-Test
- Advanced: alternative approaches to OLS
- Multivariate regression
- So, why Multivariate regression is less common?
- Path Analysis
- Confounder, mediator, moderator, and collider
- Fixed versus random effects
- Generalized Linear Model
- Hat Matrix formulation
1. Statistics for Brain and Cognitive Sciences
1.1 From simple linear regression to multiple linear regression and beyond
The field of statistics for brain and cognitive sciences progresses from foundational models like Simple Linear Regression (SLR) to more complex methodologies such as Multiple Linear Regression (MLR) and various advanced statistical models. This progression allows for increasingly nuanced analyses of complex data structures inherent in cognitive and brain research 1.
1.2 Further extending the SLR
Simple Linear Regression (SLR) serves as a fundamental building block for a wide array of advanced statistical models used in brain and cognitive sciences. These extensions allow researchers to address more intricate hypotheses and account for multiple variables and their interactions 3.
- Hierarchical model structure: Many complex statistical models can be conceptualized as extensions of SLR, building upon its core principles to incorporate additional factors or relationships.
- Advanced model types: Models such as ANOVA, ANCOVA, Multiple Regression, Multivariate Regression, MANOVA, MANCOVA, Mixed-effect models, Generalized Linear Models (GLM), Path Analysis, Factor Analysis, and Structural Equation Modeling (SEM) all represent further developments from the basic SLR framework 3.

📝 Models like ANOVA, ANCOVA, Multiple Regression, Multivariate Regression, MANOVA, MANCOVA, Mixed-effect models, Generalized Linear Models (GLM), Path Analysis, Factor Analysis, and Structural Equation Modeling (SEM) are all extensions of the basic SLR framework 3.
1.3 Multiple linear regression
Multiple Linear Regression (MLR) extends SLR by incorporating multiple independent variables to predict a single dependent variable. This allows for a more comprehensive understanding of the factors influencing an outcome in cognitive and brain science research 2 4.
1.4 Beyond MLR
Beyond MLR, statistical methodologies continue to expand to address even more complex research questions. These advanced techniques are crucial for modeling intricate relationships and structures often encountered in brain and cognitive data 3 4.
- Advanced topics: The curriculum includes discussions on topics beyond MLR, such as the Hat Matrix formulation, which provides deeper insights into regression diagnostics and influence 3 4.
2. Multiple linear regression (MLR)
2.1 Introduction to MLR in cognitive neuroscience
Multiple Linear Regression (MLR) is a statistical method used to model the linear relationship between a dependent variable and two or more independent variables. In cognitive neuroscience, MLR is applied in contexts such as Statistical Parameter Mapping (SPM) for analyzing functional magnetic resonance imaging (fMRI) data 5.
The General Linear Model (GLM) framework, which encompasses MLR, is fundamental to fMRI analysis.

- Design matrix: This matrix contains all experimental predictors and nuisance variables.
- Experimental paradigm: Includes task/stimulus time courses and their temporal derivatives.
- Nuisance regressors: Such as head motion parameters and physiological signals.
- Session constants and drifts: Intercepts for baseline and polynomial drifts 5.
- Temporal derivatives: Often introduced to account for temporal jitter in the hemodynamic response 6.
2.2 Mathematical formulation of MLR
The MLR model describes the dependent variable Y as a linear combination of p predictor variables (X1,X2,…,Xp), an intercept α, and an error term ϵ 6. Y=α+β1X1+β2X2+…+βpXp+ϵ In matrix notation, this equation is expressed more compactly, which is particularly useful for handling multiple predictors and observations8. y=Xβ+e
- y: A vector representing the dependent variable observations.
- X: The design matrix, where each column corresponds to a predictor variable (including a column of ones for the intercept) and each row is an observation.
- β: A vector of regression coefficients, including the intercept α and the partial regression coefficients βj for each predictor.
- e: A vector of residual errors 7.

2.3 Geometric interpretation and coefficient interpretation
Geometrically, an MLR with two independent variables (IVs) represents a plane in R3, extending the concept of Simple Linear Regression (SLR) as a line in R2 7.
- Conditional expected value: The expected value of Y given X is E(Y∣X)=α+∑j=1pβjXj.
- Intercept (α): Represents the conditional expected value of Y when all independent variables are zero, i.e., α=E(Y∣X=0).
- Partial regression coefficient (βj): Indicates the change in Y for a one-unit change in Xj, while all other predictors are held constant.
βj=E(Y∣Xj=xj+1,Xj′=j=xj′=j)−E(Y∣Xj=xj,Xj′=j=xj′=j)

📝 If β1=−0.05 in a study of Stroop Interference Score (Y) and Prefrontal Cortex Volume (X1), it means that for every 1 mm3 increase in Prefrontal Cortex Volume, the Stroop Interference Score decreases by 0.05 ms, assuming all other regressors are constant 9.
2.4 Ordinary Least Squares (OLS) solution
The Ordinary Least Squares (OLS) method aims to minimize the sum of squared residuals (SSRes=∑i=1nei2). This minimization is achieved by satisfying two conditions:
- Zero-mean residuals: The sum of residuals must be zero (∑i=1nei=0), ensuring the fitting hyperplane passes through the mean of the data points.
- Null covariances: The covariance between each predictor Xj and the residuals e must be zero (sXj,e=0). These conditions are summarized by the matrix equation XTe=0 10. The OLS solution for the regression coefficients β^ is given by the pseudo-inverse of the design matrix. β^=(XTX)−1XTy=X+y
- (XTX)−1: This term involves the inverse of the matrix product of the transpose of the design matrix and the design matrix itself, which contains means and covariances of the independent variables.
- XTy: This vector contains the mean of the dependent variable and its covariances with the independent variables 11.

3. Test of the regression coefficients
3.1 Properties of OLS estimators
Ordinary Least Squares (OLS) estimators are characterized as Best Linear Unbiased Estimators (BLUE), meaning they are the most efficient among all linear unbiased estimators. This property ensures that, on average, the estimated coefficients accurately reflect the true population parameters 12.

- Expected value: The expected value of the OLS estimator β^ is equal to the true population parameter β, denoted as E(β^)=β.
- Variance: The variance of the OLS estimator β^ is given by Var(β^)=σ2(XTX)−1, where σ2 is the error variance and X is the matrix of predictors.
- Standard error: The variance of an individual regression coefficient β^j is the square of its standard error, Var(β^j)=SE(β^j)2.
- This variance can also be expressed as nsxj2(1−Rj2)σ2, where sxj2 is the sample variance of predictor Xj, and Rj2 is the R-squared from regressing Xj on the other predictors X.
- Practical application: Since the true error variance σ2 is typically unknown, the Mean Squared Error (MSE), also known as MSRes, is used as an estimate.
- Hypothesis testing: With the estimated variance, individual regression coefficients β^j can be tested using a t-test, similar to Simple Linear Regression (SLR) 12.
3.2 Exercise 1: Expected value and variance of OLS estimators
This exercise requires demonstrating the derivation of the expected value and variance formulas for OLS estimators, as presented in the theoretical framework 12.
4. Multicollinearity and Singularity
4.1 Multiple Linear Regression Coefficient Derivation
The estimation of coefficients in multiple linear regression (MLR) becomes complex as the number of independent variables (p) increases. For p=2 independent variables, the estimated coefficients (β^) can be expressed in matrix form or an expanded form involving partial correlations 13.

- Partial correlations: These "clean" the relationship between the dependent variable (DV) and one independent variable (IV) by accounting for the contribution of other variables.
- Coefficient calculation: The partial regression coefficients are proportional to the partial correlations 13.
- Problematic estimates: If the correlation between two independent variables (rx1x2) approaches 1, the denominator term 1−rx1x22 approaches 0, causing the estimates of the coefficients (β1^, β2^) to inflate towards infinity 14.
4.2 Multicollinearity and Singularity Defined 16
Multicollinearity refers to an excessive correlation between independent variables, specifically when rx1x2≈1. Singularity, or perfect multicollinearity, occurs when rx1x2=1 15.
- Problematic nature: When independent variables are highly correlated, they become redundant, and one can be expressed as a function of the others.
- OLS solution: If one or more IVs are linear combinations of others, the determinant of the (XTX) matrix is 0, making it non-invertible and preventing an Ordinary Least Squares (OLS) solution.
- Inflated terms: Even if the determinant is not zero but very small, the inverse matrix (XTX)−1 can have inflated terms, leading to significant issues 16.
| Issue | Consequence |
|---|---|
| Inflated SEs of estimates | Reduced precision of coefficient estimates |
| Deflated t-tests | Increased difficulty in detecting significant predictors |
| False non-significance of p-values | Type II errors (failing to reject a false null hypothesis) |
| Lack of power | Reduced ability to detect true effects |
| Degrading model predictions | Poor generalization to new data |
4.3 Detecting Multicollinearity
Detecting multicollinearity is crucial for ensuring the reliability of regression models. Several methods can be employed to identify its presence 17.
- Detection methods:
- Scatterplots: Visual inspection of relationships between independent variables.
- Singularity of XTX matrix: Checking if the determinant of the XTX matrix is zero.
- Eigenvalue methods: Advanced statistical techniques (not covered in detail).
- Variance Inflation Factor (VIF): A quantitative measure of multicollinearity for each predictor 17.
The variance of the estimated coefficients, Var(βj^), is influenced by several factors: Var(βj^)=SE(βj^)2=nsxj2(1−Rj2)σ2
- Noise (σ2): A greater error variance leads to a worse standard error (SE) 17.
- Sample size (n) and predictor variance (sxj2): Larger values for n and sxj2 result in a better SE.
- Rj2: A smaller Rj2 (the R-squared from regressing Xj on other predictors) indicates a better SE, as it means the predictor is less explained by other predictors 18.

📝 If the error variance is large, the data points will be widely scattered around the regression line, leading to a larger standard error for the coefficient estimates. Conversely, a small error variance results in data points tightly clustered around the line, yielding a smaller standard error 17.
4.4 Variance Inflation Factor (VIF)
The Variance Inflation Factor (VIF) quantifies the severity of multicollinearity for each independent variable. It is calculated as VIFj=1−Rj21, where Rj2 is the R-squared value obtained from regressing the j-th predictor (Xj) on all other predictors 19.
-
Interpretation of VIF values:
-
VIFj=1: Indicates no collinearity for predictor Xj.
-
1<VIFj<5: Suggests moderate collinearity.
-
VIFj≥5: Points to strong collinearity.
-
VIFj≥10: Signifies a serious multicollinearity problem 19.
-
Addressing multicollinearity:
-
Predictor removal: Consider removing the predictor that causes the multicollinearity.
-
Outlier detection: Check for outliers or influential data points that might be contributing to the issue.
-
Variable transformation: Try centering variables or removing the intercept by standardizing variables 19.
📝 If a VIF calculation for a predictor Xj yields a value of 7, it indicates strong collinearity, suggesting that Xj is highly correlated with other predictors in the model. This would prompt investigation into potential solutions such as removing Xj or examining outliers 19.
5. ANOVA Table for MLR
The Analysis of Variance (ANOVA) table for Multiple Linear Regression (MLR) systematically partitions the total variability in the dependent variable into components attributable to the regression model and residual error. This framework is crucial for assessing the overall statistical significance of the regression model 20.
5.1 Components of the ANOVA table
The ANOVA table for MLR includes several key components that quantify the sources of variation, their associated degrees of freedom, sums of squares, mean squares, and the F-statistic. The number of predictors, p, can sometimes be defined as p−1 such that it becomes p with the intercept, which would alter the table's structure 20.
| Source of variation | df | SS | MS | F |
|---|---|---|---|---|
| Regression | p | SSReg=∑i=1n(y^i−yˉ)2 | MSReg=pSSReg | F=MSResMSReg |
| Residual error | n−p−1 | SSRes=∑i=1n(yi−y^i)2 | MSRes=n−p−1SSRes | — |
| Total | n−1 | SSTot=∑i=1n(yi−yˉ)2 | — | — |
- Degrees of freedom (df): These represent the number of independent pieces of information used to calculate the sum of squares.
- Sum of Squares (SS): These measure the total variability from different sources.
- Mean Squares (MS): These are calculated by dividing the sum of squares by their respective degrees of freedom, representing the average variability.
- F-statistic: This is the ratio of the mean square regression to the mean square residual, used to test the overall significance of the model 20.
5.2 Conditions and interpretation
For valid estimation and testing in MLR, the sample size n must be greater than the number of predictors plus one (n>p+1). The overall F-test evaluates whether at least one of the regression parameters is significantly different from zero, indicating that the model as a whole explains a significant portion of the variance in the dependent variable 20.
📝 If an MLR model has 3 predictors (p=3) and a sample size of 20 (n=20), the degrees of freedom for residual error would be 20−3−1=16. The condition n>p+1 (20>3+1) is met, allowing for valid inference.
5.3 Coefficient of multiple determination (R2)
The coefficient of multiple determination (R2) quantifies the proportion of the variation in the dependent variable (DV) that is explained by the multiple linear regression model. It serves as a measure of the model's explanatory power 20.
- Partial R2: This can be utilized to determine the proportion of variation explained by a specific subset of predictors within the model.
- Coefficient of multiple correlation (R): This is the square root of R2, calculated as ryy^, representing the correlation between the observed and predicted values of the dependent variable 20.
6. General Linear F-Test
6.1 Overview of the General Linear F-Test
The General Linear F-test is a robust statistical method employed to evaluate the significance of regression coefficients, particularly for subsets of predictors within a model. It determines if at least one partial regression coefficient in a given subset is significantly different from zero 22.
6.2 Procedure for the General Linear F-Test
The General Linear F-test involves comparing a full (unrestricted) model with a reduced (restricted) model to assess the contribution of specific predictors 21.
- Model estimation:
- Calculate Ordinary Least Squares (OLS) estimates and the Sum of Squared Residuals (SSRes) for a full model, denoted as SSRes,F.
- Calculate OLS estimates and SSRes for a reduced model, denoted as SSRes,R.
- Sequential sum of squares: Define the sequential (extra) sum of squares as the difference between the reduced and full model's SSRes: SSRes,R−SSRes,F. This value represents the reduction in SSRes (or increase in SSReg) when moving from the reduced to the full model.
- F-statistic calculation: Use the F-statistic to test the hypothesis that any parameters present in the full model but absent in the reduced model are null. F=dfFSSRes,FdfR−dfFSSRes,R−SSRes,F where dfR and dfF are the degrees of freedom for the reduced and full models, respectively 21.
📝 Consider a scenario where a full model includes predictors A and B, while a reduced model includes only predictor A. The General Linear F-test would assess if the addition of predictor B significantly improves the model's explanatory power by comparing SSRes from both models.
6.3 Sequential (Extra) Sum of Squares and Partial R-squared
The sequential (extra) sum of squares quantifies the change in SSRes when a group of predictors is added to a model 22.
- Sequential sum of squares: This value, SSRes,R−SSRes,F, captures the change due to adding a group of predictors B to an existing group of predictors A in the reduced model. It can also be expressed as SSRes,A−SSRes,A∪B.
- Partial R-squared: This metric indicates the percentage of variation explained by the additional predictors B, given that predictors A are already in the model. Ry,B∣A2=SSRes,ASSRes,A−SSRes,A∪B=SSRes,ASSRes,B∣A This formula highlights the incremental explanatory power of the added predictors 22.
| Model Type | Description |
|---|---|
| Full (unrestricted) model | Includes all predictors under consideration, yielding SSRes,F and dfF. |
| Reduced (restricted) model | A smaller model, typically nested within the full model, yielding SSRes,R and dfR 21. |
7. Advanced: alternative approaches to OLS
7.1 Weighted Least Squares (WLS) and Generalized Least Squares (GLS)
Weighted Least Squares (WLS) and Generalized Least Squares (GLS) are advanced regression techniques that address issues with the error variance-covariance matrix, unlike Ordinary Least Squares (OLS) which assumes homoscedasticity and uncorrelated errors. All three methods share the general linear model y=Xβ+e, but differ in their assumptions regarding the structure of the error variance-covariance matrix, Θ 23.
| Method | Error Variance-Covariance Matrix (Θ) | Assumptions |
|---|---|---|
| OLS | ΘOLS (diagonal with equal variances) | Homoscedasticity, uncorrelated errors |
| WLS | ΘWLS (diagonal with unequal variances) | Heteroscedasticity, uncorrelated errors |
| GLS | ΘGLS (general matrix) | Heteroscedasticity, correlated errors |

The estimated coefficient vector β^ for these linear least squares approaches is given by the formula β^=(XTWX)−1XTWy, where W=Θ−1 is the inverse of the error variance-covariance matrix 23.
- OLS simplification: For OLS, W=σ21I, which simplifies the general solution to the familiar OLS estimator 23.
8. Multivariate regression
8.1 Limitations of multiple linear regression
Multiple Linear Regression (MLR) is a powerful analytical tool, yet it possesses several limitations that necessitate more advanced statistical models for complex research designs 25.
- Single dependent variable: MLR is restricted to analyzing only one dependent variable (DV) at a time, which is insufficient when multiple correlated DVs are present.
- Direct effects only: It models direct relationships between independent variables (IVs) and a single DV, failing to account for direct effects among multiple IVs and DVs simultaneously.
- Fixed effects: MLR primarily handles fixed effects for predictors, treating only the error term as random.
- Continuous dependent variables: The DV in MLR must always be continuous.
- Observed variables: Both IVs and DVs are assumed to be observed, with only the error term being latent.
| Limitation of MLR | Advanced Model |
|---|---|
| Only one DV | Multivariate Regression |
| Models only direct effects | Path Analysis |
| Only fixed effects for predictors | Mixed-Effects Models |
| DV always continuous | Generalized Linear Models |
| IVs and DVs are observed | Latent Variable Models |
8.2 Introduction to multivariate regression
Multivariate regression extends the linear regression framework to scenarios involving multiple dependent variables (DVs) that are often correlated, allowing for a more comprehensive analysis than running separate multiple linear regressions. This approach is particularly useful when researchers are interested in the combined effects of independent variables on a set of related outcomes 26.
📝 A research team studying the relationship between several independent variables (e.g., Pre-Frontal Cortex volume, Dopamine Receptor density, Age, Sex) and a Stroop interference Score (Y1) might also want to analyze two other correlated dependent variables: Task-Switching Cost (Y2) and Working Memory Capacity (Y3). Instead of running three separate MLRs, which would ignore the correlations among Y1, Y2, and Y3, multivariate regression can analyze all three DVs simultaneously 26.
8.3 Formulation of multivariate regression
Multivariate regression is a generalized case involving p independent variables and d dependent variables, where each dependent variable is modeled as a linear combination of the independent variables plus an error term. This can be expressed as a system of equations: Y1=α1+β11X1+β12X2+⋯+β1pXp+ϵ1Y2=α2+β21X1+β22X2+⋯+β2pXp+ϵ2…Yd=αd+βd1X1+βd2X2+⋯+βdpXp+ϵd This system can be compactly represented in matrix notation as Y=XB+E, where Y is the matrix of dependent variable observations, X is the design matrix of independent variables, B is the matrix of regression coefficients, and E is the matrix of error terms 27.

8.4 Least squares estimator
The least squares estimator in multivariate regression aims to minimize the residuals, which are collected in a matrix E. The objective is to minimize the sum of squares and cross-products of these residuals, typically by minimizing the determinant of the ETE matrix.
The ETE matrix contains the sums of squared residuals for each dependent variable on its diagonal and the sums of cross-products of residuals between different dependent variables off its diagonal 28.
ETE=∑i=1nei12∑i=1nei1ei2⋮∑i=1nei1eid∑i=1nei1ei2∑i=1nei22⋮∑i=1nei2eid……⋱…∑i=1nei1eid∑i=1nei2eid⋮∑i=1neid2=SSRes,1SSRes,12⋮SSRes,1dSSRes,12SSRes,2⋮SSRes,2d……⋱…SSRes,1dSSRes,2d⋮SSRes,d The ratio n−p−1ETE provides an estimate of the variance-covariance matrix Θ of the errors, analogous to how MSRes estimates σ2 in simple and multiple linear regression 28.

The least squares solution for the matrix of regression coefficients, B^, is given by: B^=(XTX)−1XTY This solution effectively stacks multiple individual multiple regressions together, where B^ is a matrix containing the estimated regression coefficients for each dependent variable 29.

8.5 Relationship to MANOVA and MANCOVA
Multivariate regression serves as a foundational framework that encompasses other multivariate analyses depending on the nature of the predictors 29.
- Multivariate ANOVA (MANOVA): This occurs when all independent variables in the multivariate regression model are categorical. MANOVA assesses whether there are statistically significant differences between two or more groups on multiple dependent variables simultaneously.
- Multivariate ANCOVA (MANCOVA): This arises when the model includes both categorical and continuous independent variables. MANCOVA extends MANOVA by controlling for the effects of continuous covariates on the dependent variables.
Multivariate approaches, by accounting for correlated errors, can also be utilized for analyzing repeated measures data, offering an alternative to traditional "univariate" methods like within-subjects ANOVA or mixed-design ANOVA, although univariate approaches remain more common in practice 29.
9. So, why Multivariate regression is less common?
9.1 Univariate approaches are simpler
Multivariate regression is less frequently employed than univariate methods primarily due to the comparative ease of implementing and interpreting univariate approaches 30.
9.2 Complexity of test statistics
While multiple linear regression (MLR) typically relies on t-tests or F-tests, multivariate analyses involve several distinct test statistics. These statistics, though generally in agreement, can yield differing results in specific situations, lacking conventional solutions for discrepancies 30.
| Multivariate Test Statistic | Description |
|---|---|
| Wilk’s Lambda | Likelihood ratio test for the equality of mean vectors. |
| Pillai’s Trace | Sum of the eigenvalues of a specific matrix, robust to violations of assumptions. |
| Hotelling-Lawley Trace | Sum of the eigenvalues of another matrix, often used in conjunction with Wilk's Lambda. |
| Roy’s greatest root | Largest eigenvalue, sensitive to differences along a single dimension. |
Sampling distributions: Understanding the sampling distributions of parameters and testing procedures in multivariate analysis necessitates knowledge of multivariate distributions and eigenvalue techniques, which adds to the complexity 30.
9.3 The curse of dimensionality
Multivariate models require the estimation of numerous parameters, leading to data sparsity in higher-dimensional spaces, a phenomenon known as the "curse of dimensionality" 31.
📝 In fMRI studies, a mass-univariate approach (one General Linear Model per voxel) is typically used instead of a multivariate regression encompassing all voxels. This is because the variance-covariance matrix of residuals, which has a size of d×d (where d is the number of voxels), becomes singular and cannot be inverted without regularization when d>n−p−1 (where n is time points/subjects and p is predictors). This singularity arises because a scan often has thousands of voxels but relatively few time points or subjects 31.
Alternative approaches: In situations where multivariate regression is problematic due to dimensionality, it is more common to reverse the problem and predict experimental labels from voxel patterns using methods like Multivoxel Pattern Analysis (MVPA) 31.
10. Path Analysis
10.1 Introduction to path analysis
Path analysis is a statistical technique used to model direct and indirect causal relationships among multiple observed variables, extending beyond simple multiple linear regression when variables directly affect each other in complex ways. This method is distinct from structural equation models, which incorporate latent variables 32 33.
| Variable Type | Description |
|---|---|
| Exogenous variables | Independent or external variables that are not caused by other variables in the model. |
| Endogenous variables | Dependent variables within the model that can also act as independent variables for other endogenous variables. |
📝 Consider a scenario where cortisol (X1) affects response time variability (Y2). In patients with chronic stress, cortisol also influences hippocampal volume (Y1), which in turn affects response time variability. This forms a system of regressions where Y1 and Y2 are endogenous variables, and X1 is an exogenous variable 32.

10.2 Direct, indirect, and total effects
In path analysis, particularly in mediation scenarios, the effect of an exogenous variable on an endogenous variable can be decomposed into direct and indirect paths 33.
- Direct path: This represents the direct effect of one variable on another, not mediated by any other variable in the model.
- Indirect path: This occurs when the effect of one variable on another is transmitted through an intermediate variable.
- Total effect: This is the sum of all direct and indirect effects of one variable on another.
For a system defined by the equations: Y1=α1+γ11X1+ϵ1 Y2=α2+β21Y1+γ21X1+ϵ2
| Effect Type | Formula |
|---|---|
| Direct effect of X1→Y2 | γ21 |
| Indirect effect of X1→Y1→Y2 | β21γ11 |
| Total effect of X1 on Y2 | γ21+β21γ11 |
📝 In the mediation model where X1 affects Y1, and both X1 and Y1 affect Y2, the direct effect of X1 on Y2 is γ21. The indirect effect of X1 on Y2 through Y1 is β21γ11. The total effect of X1 on Y2 is the sum of these, γ21+β21γ11, which can be derived by substituting the equation for Y1 into the equation for Y2 33.

11. Confounder, mediator, moderator, and collider
Understanding the roles of confounders, mediators, moderators, and colliders is critical for accurate causal inference and the interpretation of regression models. Each variable type interacts with the relationship between an independent variable (X) and a dependent variable (Y) in distinct ways, necessitating different analytical approaches 34.
11.1 Variable roles in causal relationships
The relationship between an independent variable (X) and a dependent variable (Y) can be influenced by other variables (Z) in four primary ways, each requiring specific consideration in study design and analysis.
| Variable Type | Relationship to X and Y | Analytical Implication |
|---|---|---|
| Confounder | Affects both X and Y, creating a spurious association between them. | Must be controlled for to avoid a fake path X → Y. |
| Mediator | Is caused by X and, in turn, causes Y, explaining part of the direct path X → Y. | Creates an indirect path X → Z → Y, adding explanatory power. |
| Moderator | Changes the strength or direction of the relationship between X and Y. | Influences the path X → Y, indicating conditional effects. |
| Collider | Is caused by both X and Y. | Must not be controlled for, as it can induce spurious associations. |
📝 Consider the relationship where Traumatic Brain Injury (TBI) severity (X) worsens Executive Functions (Y).
- Confounder: Age (Z) can affect both TBI severity and Executive Functions. If not controlled, age might create a false association between TBI severity and Executive Functions.
- Mediator: Attention Deficit (Z) caused by TBI severity (X) might then impact Executive Functions (Y). This suggests an indirect pathway where TBI severity leads to attention deficit, which then impairs executive functions.
- Moderator: Premorbid IQ or cognitive reserve (Z) could modify the impact of TBI severity (X) on Executive Functions (Y). A higher cognitive reserve might compensate for TBI damage, altering the strength of the X → Y path.
- Collider: If a study only includes patients hospitalized for both TBI and severe executive dysfunction, hospitalization (Z) acts as a collider. Hospitalization is caused by both severe TBI and severe executive dysfunction. Controlling for hospitalization in such a sample could create a spurious association between TBI severity and executive functions that does not exist in the general population 34.

12. Fixed versus random effects
12.1 Introduction to fixed versus random effects
In statistical modeling, particularly with longitudinal or hierarchical data, it is crucial to distinguish between fixed and random effects. While coefficients in a standard regression model are typically treated as fixed effects, assuming they are specific, non-varying numbers, real-world data often exhibit variability at multiple levels 37.
- Fixed effects: These coefficients are considered specific, constant numbers, often associated with a particular individual or condition.
- Random effects: These coefficients are viewed as realizations of a random variable, meaning they are possible draws from a larger population distribution.
- Variance levels: In many contexts, such as fMRI studies, variance exists both between subjects (group level, σB2) and within subjects (individual level, σW2), with between-subject variance often being significantly larger (σB2≫σW2).
- Mixed-effect modeling: To accurately estimate both types of variance, mixed-effect models are introduced, combining both fixed and random effects 37.
📝 In an fMRI experiment, estimating the effect of a task (β1) for each subject and then calculating the mean β1 and its variance across participants treats β1 as a fixed effect for each individual. However, this approach overlooks the inherent variability between subjects and within each subject over time, which random effects modeling can address 35 37.
12.2 Mixed-effects models with random intercept and slope
When analyzing longitudinal data, such as cognitive recovery (Y) of patients (Z) over months (X) post-surgery, a moderation model might initially be considered. This model, Y=α+β1X+β2Z+β3XZ+ϵ, can be rewritten as Y=(α+β2Z)+(β1+β3Z)X+ϵ, where Z provides a fixed change to the coefficients for each person.
However, if the population of persons is considered potentially infinite rather than a categorical Z, a mixed-effects model becomes more appropriate 38.
- Model formulation: A mixed-effects model with random intercept and slope can be expressed as: Y=α′+β′X+ϵ α′=α+u0 β′=β+u1 where u0 and u1 are normally distributed random variables, uj∼N(0,σuj2).
- Coefficient distributions: In this model, both the intercept (α′) and slope (β′) have distributions: α′∼N(α,σu02) and β′∼N(β1,σu12).
- Parameters to estimate: The parameters to be estimated include the fixed effects (α, β) and the variances of the random effects (σu0, σu1) and the residual error (σ) 39.
- Regression lines: This approach allows for potentially infinite regression lines, each with its own intercept and slope, reflecting individual variability 40.

12.3 Comparison of statistical approaches for longitudinal data
Different statistical approaches can be used for analyzing longitudinal data, each with distinct characteristics regarding equations, degrees of freedom, and variance components 41.
- Approach: Equation, dfX, dfZ, dfXZ, dfRes, Variances
- ANOVA Within: Y=α+β1X+β2Z+ϵ, T−1, n−1, 0, (T−1)(n−1), σ
- Moderation (X categ.): Y=α+β1X+β2Z+β3XZ+ϵ, T−1, n−1, (T−1)(n−1), 0, σ
- Moderation (X cont.): Y=α+β1X+β2Z+β3XZ+ϵ, 1, n−1, n−1, (T−2)n, σ
- Mixed-Effect model: Y=α+u0+(β1+u1)X+ϵ, 1, 0, 0, Debated, σ,σu0,σu1
- ANOVA Within: This model does not allow for testing interactions due to too many fixed effects saturating the model.
- Moderation models: Using a continuous predictor in a moderation model improves upon the limitations of ANOVA Within.
- Mixed-effect models: These models significantly reduce the number of parameters to be estimated, although the determination of degrees of freedom for testing remains a subject of debate 41.
12.4 Intraclass correlation coefficient (ICC)
The Intraclass Correlation Coefficient (ICC), denoted as ρ0, quantifies the proportion of total variability in an outcome that is attributable to differences between groups 42.
- Formula: The ICC is defined as: ρ0=σu02+σ2σu02 where σu02 represents the variance at the group level (between-group variance) and σ2 is the variance at the individual level (within-group variance).
- Intercept-only ICC: The ρ0 calculated this way is an intercept-only or unconditional ICC, as it only provides the ICC at X=0 in the presence of a random slope.
- Conditional ICC: A conditional ICC, which is a more complex function of X, is less commonly used.
- Multilevel models: These are a subset of mixed-effect models, characterized by hierarchical structures, though not all mixed-effect models require nested designs 42.

12.5 Diagram representations
Random effect models can be represented diagrammatically in several ways, typically illustrating hierarchical structures and latent variables 43.
- Latent variable approach: One approach treats random effects as latent variables at the same level, where, for instance, u1 acts as a moderator and u0 as an error term.
- Hierarchical structure approach: Another approach follows a hierarchical structure, including latent variables for the random coefficients at a higher level, explicitly showing the within- and between-subject components 43.

12.6 Final remarks
Multilevel/mixed-effects models are known by various names, including random-coefficients regression models, hierarchical linear models, and nested data models 44.
- Random effects distribution: The random effects are typically assumed to follow a multivariate normal distribution with a mean of zero and a specific variance-covariance matrix: (σu02σu0u1σu0u1σu12).
- Multilevel context: In multilevel models, individuals at the micro-level are grouped, but variables can operate at both micro- and macro-levels.
- Pooling strategies: Multilevel models represent a compromise (semi-pooling) between running a separate regression for each group (no pooling, e.g., ANCOVA) and conducting a single regression analysis for all data (complete pooling) 44.
13. Generalized Linear Model
13.1 Introduction to Generalized Linear Models
Generalized Linear Models (GLMs) extend the linear regression framework to accommodate dependent variables that are not continuous, such as binary outcomes. When the dependent variable (Y) is a dummy variable, for instance, representing a "Yes/No" diagnosis, its expected value is a probability, which is inherently bounded between zero and one.
Standard regression methods are ill-suited for such constraints, necessitating a transformation of the expected value to a scale where a linear relationship can be modeled 45 46.

13.2 Components of a GLM
A GLM re-frames regression by assuming three core components to handle non-continuous dependent variables: a specific distribution for Y, a linear predictor, and a link function 47.
- Distribution for Y: This specifies the probability distribution of the dependent variable, such as a Bernoulli distribution for binary outcomes.
- Linear predictor (η): This is a linear combination of predictor variables, typically expressed as η=α+βX.
- Link function (g): This function transforms the expected value of Y, μ=E(Y∣X), such that g(μ)=η. The inverse of the link function, g−1(η), then maps the linear predictor back to the scale of the expected value, μ=g−1(η) 47.
For a Bernoulli distribution, the canonical link function is the logit function, defined as logit(p)=ln(1−pp), which represents the natural logarithm of the odds of Y=1. This transformation maps probabilities (bounded between 0 and 1) to the entire range of real numbers, making it suitable for linear modeling 47.
📝 For a binary outcome like "Yes/No impairment diagnosis" (Y) based on a continuous test score (X), the expected value E(Y|X) is a probability p(X). The logit function, logit(p)=ln(1−pp), transforms this probability into a linear predictor η=α+βX, allowing for linear modeling 47.
13.3 Simple Logistic Regression
Logistic regression is a specific type of GLM used for binary outcomes, where the logit of the probability of the outcome is linearly related to the predictor variables. This establishes a linear relationship between the logit of p and the linear predictor: logit(p)=α+βX 48.
The relationship between the probability of an event and the linear predictor can be expressed in three equivalent forms:
| Representation | Formula |
|---|---|
| Logit/Log-odds | ln(1−P(Y=1∣X)P(Y=1∣X))=α+βX |
| Odds | OY=1(X)=1−P(Y=1∣X)P(Y=1∣X)=eα+βX |
| Probability | P(Y=1∣X)=1+eα+βXeα+βX |
The inverse of the logit function is known as the logistic function, which is why this modeling approach is termed logistic regression 48.

13.4 Parameter Interpretation in Logistic Regression
The parameters α and β in a logistic regression model have specific interpretations related to the log-odds and odds ratio 50.
- α (Intercept): This represents the log-odds of the event occurring when all predictor variables (X) are zero. Consequently, eα is the ratio between the probability of a positive outcome versus a negative outcome when the test score is null.
- β (Slope): This parameter signifies the log of the odds-ratio. For every unit increase in the predictor variable X, the odds of the outcome are multiplied by eβ. This means that β quantifies the change in the log-odds for a one-unit increase in X 50.

14. Hat Matrix formulation
14.1 Hat Matrix formulation in linear regression
The Hat Matrix, denoted as H, is a fundamental component in the matrix formulation of linear regression, particularly for calculating predicted values. In a matrix representation, the linear regression model is expressed as y=Xβ+e, where y is the vector of observed responses, X is the design matrix, β is the vector of coefficients, and e is the vector of residuals 52.
- OLS solution: The Ordinary Least Squares (OLS) solution for the coefficient vector β^ is given by β^=(XTX)−1XTy.
- Predicted values: The vector of predicted values, y^, is calculated as y^=Xβ^=X(XTX)−1XTy=Hy.
- Hat Matrix (H): This matrix, H=X(XTX)−1XT, is also known as the projection matrix or influence matrix, as it "puts the hat on y" to produce y^ 52.
14.2 Matrix formulation and leverage values
The diagonal elements of the Hat Matrix, known as hat or leverage values (hi), quantify the influence of individual observations on their own fitted values. These values indicate the extent to which an observation (xi,yi) controls the regression line 53.
- Hat/leverage values: For simple linear regression, the i-th diagonal element hi is given by:
hi=hii=n1+∑j=1n(xj−xˉ)2(xi−xˉ)2 This formula shows how yi influences y^i as a function of the deviation of xi from the mean xˉ 53.

📝 For a simple linear regression, the i-th leverage value hi is hi=n1+∑j=1n(xj−xˉ)2(xi−xˉ)2 53.
14.3 Exercise 3
This exercise asks to demonstrate that for a simple linear regression, the Hat Matrix H is a symmetric n×n matrix with elements hij defined as: hij=n1+∑k=1n(xk−xˉ)2(xi−xˉ)(xj−xˉ)=n1[1+x2ˉ−(xˉ)2(xˉ−xi)(xˉ−xj)] This exercise tests the understanding of the matrix formulation of simple linear regression and the properties of the Hat Matrix elements 53.
14.4 Residuals and properties of the Hat Matrix
The Hat Matrix also plays a crucial role in the calculation of residuals and possesses specific mathematical properties that are important for understanding its behavior in linear regression. The residuals represent the difference between the observed and predicted values 54.
- Residual calculation: The vector of residuals e can be expressed as e=y−y^=(I−H)y, where I is the identity matrix. The matrix (I−H) is known as the residual maker matrix.

- Variance of residuals: For a single residual ei, assuming independent yi, its variance is given by Var(ei)=σ2(1−hi).
- Properties of H and (I−H):
- Symmetry: Both H and (I−H) are symmetric matrices, meaning HT=H and (I−H)T=I−H.
- Idempotence: Both matrices are idempotent, satisfying H2=H and (I−H)2=I−H.
- Sum of squares of residuals (SSRes): The SSRes can be calculated using the Hat Matrix as the inner product eTe=yT(I−H)T(I−H)y=yT(I−H)y 54.
© 2026 Maeve. All rights reserved. This content is protected by copyright.
