23 (Apr 14) MGSC 291 Regularization 3 & Exam 3 Review HZ

1. Introduction to regularization and exam review

This section introduces the concept of regularization, with a specific focus on Lasso regression, and serves as a review for Exam 3, covering topics from weeks 11, 12, and 13.

1.1 Regularization: The Lasso regression example

Regularization techniques are employed to prevent overfitting in statistical models by adding a penalty term to the loss function. Lasso (Least Absolute Shrinkage and Selection Operator) regression is a prominent form of regularization that not only shrinks coefficients towards zero but also has the ability to perform feature selection by setting some coefficients to exactly zero.

1.1.1 Lasso cost function and scaling

The standard Lasso cost function aims to minimize the sum of the residual sum of squares and a penalty proportional to the sum of the absolute values of the coefficients:

Minimize1ndev(β)+λ∑j∣βj∣\text{Minimize} \quad \frac{1}{n} \text{dev}(\beta) + \lambda \sum_{j} |\beta_j|

where dev(β)\text{dev}(\beta) is a measure of model deviance, λ\lambda is the regularization parameter controlling the strength of the penalty, and ∣βj∣|\beta_j| is the absolute value of the jj-th coefficient.

A crucial consideration for Lasso regression is the scale of the covariates. Since all βj\beta_j are penalized by the same λ\lambda, variables with larger scales can be unfairly penalized more. To address this, the penalty term is often adjusted by the standard deviation of the corresponding covariate:

Minimize1ndev(β)+λ∑jsd(xj)∣βj∣\text{Minimize} \quad \frac{1}{n} \text{dev}(\beta) + \lambda \sum_{j} \text{sd}(x_j) |\beta_j|

This standardization ensures that each βj\beta_j's penalty is measured on the scale of a one standard deviation change in xjx_j, making the model fit invariant to the units of measurement (e.g., meters vs. feet).

Note: The standardize=TRUE argument in packages like gamlr and glmnet implements this scaling by default. It is generally recommended unless dealing with exclusively indicator variables for categorical features where standardization might be undesirable.

1.1.2 The free argument in gamlr

The gamlr package offers a free argument that allows specific coefficients to be unpenalized. This is useful when certain variables are deemed essential for the model and their coefficients should be estimated without any shrinkage towards zero. For instance, in a sales prediction model, log(price) might be a variable that you want to include with an unpenalized coefficient.

Example: fitOJfree <- gamlr(x=xOJ, y=log(ojdfUSDsales), free="log(price)")

1.1.3 Handling missing data with gamlr

Missing data is a common challenge in real-world datasets. The gamlr package provides the naref function to address this:

  • For factor variables: Missing values are treated as a separate category by setting NA as the reference level. This ensures that sparse.model.matrix creates a model matrix column for every other factor level.
  • For quantitative variables: The impute=TRUE argument can be used. The imputation strategy (zero imputation or mean imputation) is determined by the pzero argument.
    • If the proportion of zeros in the non-missing entries is greater than pzero (default is 0.5), zero imputation is performed.
    • Otherwise, mean imputation is used.
    • Setting pzero=0 forces zero imputation.

Important: Never impute missing response variable values; instead, drop those observations from the analysis.

1.2 Exam 3 Review

This section serves as a guide for reviewing topics pertinent to Exam 3, focusing on material from weeks 11, 12, and 13. The key concepts likely to be covered include:

  • Regularization techniques: Understanding the principles behind L1 (Lasso) and L2 (Ridge) regularization, their objective functions, and their impact on model coefficients and feature selection.
  • Lasso Regression in practice: Application of Lasso using packages like gamlr or glmnet, including data preparation (handling missing values, feature engineering), model fitting, and interpretation of results.
  • Model Selection Criteria: Familiarity with information criteria such as AIC (Akaike Information Criterion), BIC (Bayesian Information Criterion), and AICc (Corrected AIC) for selecting the best model from a set of candidates, particularly in the context of regularization paths.
  • Interpretation of Regularization Paths: Understanding how to visualize and interpret model performance across a range of λ\lambda values (e.g., using path plots) and how to identify the optimal λ\lambda based on selected criteria.
  • Handling of Variables: Strategies for dealing with different types of variables, including factors, quantitative variables, and the implications of feature scaling.
  • gamlr package specifics: Knowledge of key arguments within the gamlr function such as family, free, standardize, and lmr (lambda minimum ratio).

1.2.1 Example: Ames Housing Lasso Regression

The Ames Housing dataset provides an opportunity to apply Lasso regression for predicting log sale prices. This involves several steps:

  1. Data Loading and Preparation:
    • Loading the dataset.
    • Feature engineering, such as converting year and month sold into factors and taking the logarithm of lot area.
    • Handling missing data: Using naref to impute missing values for both factor and numeric variables.
  2. Model Matrix Creation:
    • Creating a sparse model matrix using sparse.model.matrix, typically excluding the intercept as gamlr handles it.
  3. Lasso Model Fitting:
    • Running the gamlr function with the prepared design matrix and response variable.
    • Adjusting the lmr argument if the optimal model selected by information criteria falls at the extreme end of the λ\lambda path, indicating a need to explore smaller penalization levels.
  4. Model Selection and Interpretation:
    • Using functions like AICc, AIC, and BIC to evaluate models across the regularization path.
    • Identifying the segment (corresponding to a specific λ\lambda value) that minimizes each information criterion.
    • Extracting coefficients for the selected models using coef().
    • Counting the number of non-zero coefficients to assess the sparsity induced by Lasso.

Example: The process involves fitting a model, plotting the path, identifying the best segment using AICc, and then examining the coefficients at that selected segment. Similar procedures are followed for BIC and AIC.

CriterionOptimal Segment (Example)Lambda Value (Example)Number of Non-Zero Coefficients (Example)
AICc620.001154232Varies
BIC48(Derived from segment)95
AIC62(Derived from segment)Varies

2. Review of foundational statistics and modeling concepts

This section revisits core statistical principles and modeling techniques, including data structure interpretation, coefficient estimation across different model types, and fundamental inferential statistics concepts.

2.1 Data structure interpretation

Understanding the structure of a dataset is crucial for effective analysis. This involves identifying the number of observations (rows) and variables (columns), as well as the data type of each variable. Variables can be numerical (continuous or discrete) or categorical (factors in R). For example, examining a dataset might reveal it has 1303 observations and 13 variables, with 'Weight' potentially being a factor with many levels if not properly converted from its string representation (e.g., "0.69kg"). Identifying the number of unique categories within a factor variable, such as operating system types, is also a key step 25.

Example: When interpreting str(comp), we see 1303 obs. of 13 variables:. This tells us the dataset comp contains 1303 rows (observations) and 13 columns (variables). We also note variable types like int (integer), Factor, and num (numeric). The 'Weight' variable is initially listed as a Factor with 179 levels, indicating it needs careful handling if numerical analysis is intended.

2.2 Interpreting coefficient estimates in various models

The interpretation of regression coefficients depends critically on the functional form of the model.

Model TypeEquationInterpretation of β1\beta_1 for a 1 unit increase in x1x_1Interpretation of β1\beta_1 for a 1% increase in x1x_1
Linear Modely=β0+β1x1+ϵy = \beta_0 + \beta_1 x_1 + \epsilonAssociated with β1\beta_1 units increase in yyNot directly interpretable in percentage terms
Log-Linear Modellog⁡(y)=β0+β1x1+ϵ\log(y) = \beta_0 + \beta_1 x_1 + \epsilonAssociated with (eβ1−1)×100%(e^{\beta_1} - 1) \times 100\% increase in yyNot directly interpretable in percentage terms
Log-Log Modellog⁡(y)=β0+β1log⁡(x1)+ϵ\log(y) = \beta_0 + \beta_1 \log(x_1) + \epsilonAssociated with β1%\beta_1 \% increase in yy (elasticity)Associated with β1%\beta_1 \% increase in yy (elasticity)

For instance, if β1=0.4\beta_1 = 0.4 in a log-log model, a 1% increase in x1x_1 is associated with a 0.4% increase in yy. This percentage change relationship is known as elasticity 26.

Example: In a linear model, a coefficient β1=0.4\beta_1 = 0.4 signifies that for every one-unit increase in the predictor x1x_1, the response yy is expected to increase by 0.4 units, holding other variables constant.

2.3 Sampling distributions and statistical inference

2.3.1 Sampling distributions

A sampling distribution is the probability distribution of a statistic (like the sample mean) obtained from drawing multiple samples of the same size from a population. Key characteristics include its shape, center, and variability. Typically, the sampling distribution of the mean is approximately normal, centered around the population mean (μ\mu), with a standard error (σ/n\sigma/\sqrt{n}), where σ\sigma is the population standard deviation and nn is the sample size 27.

2.3.2 Hypothesis testing

Hypothesis testing involves evaluating evidence against a null hypothesis (H0H_0) in favor of an alternative hypothesis (HaH_a or H1H_1). For a regression coefficient β\beta, common hypotheses are H0:β=0H_0: \beta = 0 and Ha:β≠0H_a: \beta \neq 0. A test statistic, often calculated as the estimated coefficient divided by its standard error (β^/se(β^)\hat{\beta} / \text{se}(\hat{\beta})), is used to quantify how far the observed data deviates from the null hypothesis 28.

The p-value represents the probability of observing a test statistic as extreme as, or more extreme than, the one calculated, assuming the null hypothesis is true. A pre-specified significance level (α\alpha), commonly 0.01, 0.05, or 0.10, serves as a cutoff. If the p-value is less than α\alpha (p<αp < \alpha), the null hypothesis is rejected, and the estimate is considered statistically significant at the α\alpha level 29.

Note: A statistically significant result does not necessarily imply practical significance.

2.3.3 Confidence intervals

A confidence interval (CI) provides a range of plausible values for an unknown population parameter. It is constructed as: CI=Point Estimate±(Critical Value)×(Standard Error)\text{CI} = \text{Point Estimate} \pm (\text{Critical Value}) \times (\text{Standard Error}) A 95% confidence interval corresponds to a 5% significance level. For a 95% CI, the critical value is typically 1.96 for a normal distribution. The interpretation is that we are 95% confident that the true population parameter lies within the calculated interval bounds 30.

The population parameter of interest can be a population mean, a regression coefficient, or a regression prediction. If the response variable is log-transformed, predictions and their confidence intervals must be exponentiated back to the original scale 31.

Example: If a 95% confidence interval for a regression coefficient β1\beta_1 is [0.15, 0.65, we are 95% confident that the true population coefficient lies between 0.15 and 0.65. Since this interval does not contain zero, we would reject the null hypothesis H0:β1=0H_0: \beta_1 = 0 at the 5% significance level.

2.4 Advanced sampling techniques

2.4.1 Bootstrapping

Bootstrapping is a resampling technique used to estimate the sampling distribution of a statistic. It involves repeatedly drawing samples with replacement from the original dataset to generate numerous bootstrap estimates. The number of bootstrap samples, denoted by BB, influences the accuracy and computational time; larger BB reduces Monte Carlo error but increases computation 32.

The standard error of a statistic can be estimated by calculating the standard deviation of these bootstrap estimates. Setting a "seed" ensures reproducibility of results. It is crucial to acknowledge data dependencies; ignoring them can lead to underestimation of uncertainty and smaller standard errors 33.

Important: If your data has inherent dependencies (e.g., time series, clustered data), standard bootstrapping without modifications may yield misleading results regarding the uncertainty of your estimates.

2.5 Model complexity and regularization

2.5.1 Model fit and overfitting

An underfit model suffers from high bias, meaning it is too simplistic to capture the underlying patterns in the data. Conversely, an overfit model has high variance, learning the training data too well, including its noise, leading to poor performance on new, unseen data. Including too many predictors without proper justification often leads to overfitting 34.

The data used to train the model is termed "training data," while data used to evaluate its out-of-sample performance is "test data."

2.5.2 Regularization techniques

Regularization methods penalize model complexity to prevent overfitting. A regularization path illustrates how model parameters (coefficients) change as the regularization parameter (λ\lambda) varies. Typically, a regularization path starts with λ\lambda set to its largest value, resulting in a model with zero inputs (or zero coefficients). The path plot should be read from right to left, corresponding to decreasing values of λ\lambda 35.

The numbers above a regularization path plot indicate the number of inputs or non-zero coefficients in the model at that specific λ\lambda segment 36.

2.5.3 Model selection criteria

In Lasso regression, the "best" model is often identified by a vertical dashed line on a regularization path plot, typically corresponding to a specific value of λ\lambda that optimizes a chosen criterion 37.

For generalized additive models (GAMs) and related models like gamlr, model selection is frequently based on information criteria such as AICc (Akaike Information Criterion corrected) or BIC (Bayesian Information Criterion). AICc is an improvement over AIC, particularly for smaller sample sizes. For all these criteria, a lower value indicates a better-fitting model 38.

Remember: Model selection criteria like AIC, AICc, and BIC help balance model fit with parsimony. A model that is too complex, even if it fits the training data perfectly, is often penalized by these criteria.

3. Exam 3 instructions and preparation guidance

This section details the logistics for Exam 3 and provides a structured approach to preparation, emphasizing thorough review of course materials.

3.1 Exam 3 details

Exam 3 will be administered during regular class time on Thursday, April 16th. It is a closed-book examination, meaning no external materials are permitted. Students are required to bring a pen or pencil, and answer sheets will not be used; responses should be written or circled directly on the exam paper.

The exam will cover course materials from Weeks 11, 12, and 13. The format consists of 27 multiple-choice questions, with a total point value of 100. These questions are weighted as follows: 19 questions are worth 4 points each, and the remaining 8 questions are worth 3 points each.

Important: Ensure you bring a writing utensil (pen or pencil) to the exam.

3.2 Preparation strategies

Effective preparation for Exam 3 involves a systematic review of previously assigned materials and course content.

3.2.1 Review of course materials

The following components should be reviewed thoroughly:

  • Homework Assignments: Specifically, review Homework 7 and Homework 8 (both Part a and Part b).
  • In-class Quizzes: Revisit all quizzes administered during class sessions.
  • Lecture Materials: Consult slides and script files for any topics that remain unclear after reviewing homework and quizzes. A detailed list of topics covered is available on Blackboard under "Exam 3 Content -> Exam 3 Preparation & Instructions."

Tip: When encountering unfamiliar topics, dedicate time to rereading lecture slides and notes to solidify understanding.

3.2.2 Practice exam utilization

Once all course materials have been reviewed and you feel confident in your grasp of the topics, it is highly recommended to take the practice exam. This should be approached as if it were the actual examination to simulate real-time conditions and identify any remaining areas of weakness. The practice exam is accessible on Blackboard under "Exam 3 Content -> Exam 3 Practice."

3.3 Support and questions

For any questions or clarification regarding the exam or course material, students are encouraged to attend the designated office hours. Office hours are held on Tuesdays and Thursdays from 3:30 PM to 5:00 PM in room 401S2.

Reminder: Utilize office hours for any lingering questions to ensure you are fully prepared for Exam 3.

Common mistakes to avoid

  • Review all topics thoroughly before exams
  • Pay attention to formulas and key definitions
  • Practice with examples provided in each section
  • Don't memorize without understanding the underlying concepts

© 2026 Maeve. All rights reserved. This content is protected by copyright.

See also