Tutorials › Exam PA - Predictive Analytics › The Ridge Objective Function

Exam PA · Penalties and Ridge Regression · Tutorial 397 of 966

The Ridge Objective Function

Learn to calculate and interpret the ridge objective, including how the tuning parameter changes the balance between fit and coefficient size.

Intermediate 10 min read

What You'll Learn

  • Write the ridge objective for a linear regression with an intercept.
  • Calculate residual sum of squares and the squared-coefficient penalty separately.
  • Explain how the tuning parameter changes the trade-off in the objective.
  • Compare candidate coefficient sets without confusing objective value with fitted-model optimality.
  • Identify intercept-penalty and objective-scaling mistakes.

Why Ridge Regression Uses an Objective

Ordinary least squares chooses coefficients to make the observed responses as close as possible to the model’s predictions, measured by the sum of squared residuals. Ridge regression keeps that fit measure but adds a cost for large slope coefficients. The resulting objective makes the trade-off explicit: a coefficient set must fit the data well while also avoiding unnecessarily large coefficient values.

This tutorial considers a continuous response and a linear predictor with \(n\) observations and \(p\) predictors. The ridge objective can be evaluated for any proposed coefficient values; a statistical model is not needed just to do that arithmetic. To interpret the fit as a conventional Gaussian linear regression, suppose \(y_i=\beta_0+\sum_{j=1}^{p}\beta_jx_{ij}+\varepsilon_i\), where the errors are independent with mean zero and common variance. If a Gaussian likelihood interpretation is wanted, assume additionally that \(\varepsilon_i\) are normally distributed. Ridge’s squared-error objective can still be used without Gaussian errors, but for a non-Gaussian response, squared error may not be the appropriate model-fitting loss.

Definition: For observed responses \(y_i\), predictor values \(x_{ij}\), an intercept \(\beta_0\), slope coefficients \(\beta_1,\ldots,\beta_p\), and tuning parameter \(\lambda\geq 0\), the ridge objective under the convention used here is
$$ J(\beta_0,\beta_1,\ldots,\beta_p) = \sum_{i=1}^{n}\left(y_i-\beta_0-\sum_{j=1}^{p}\beta_jx_{ij}\right)^2 + \lambda\sum_{j=1}^{p}\beta_j^2. $$
The first term is the residual sum of squares (RSS). The second term is the squared-coefficient penalty. In this convention, the intercept is not included in the penalty.

A proposed coefficient set has a fitted value \(\hat{y}_i=\beta_0+\sum_{j=1}^{p}\beta_jx_{ij}\) for each observation, and residual \(e_i=y_i-\hat{y}_i\). Thus the objective is the sum of the squared residuals plus \(\lambda\) times the sum of the squared slopes. The ridge fit is the coefficient set that minimizes this objective. Calculating \(J\) for one or several proposed coefficient sets does not, by itself, establish which values minimize it.

The intercept convention matters when calculating the penalty: \(\beta_0\) is omitted, but every included slope coefficient is squared and added. A model with no intercept has no \(\beta_0\) term. The objective above is one common scaling convention. Other conventions multiply the RSS and penalty by constants, so their numerical tuning parameter values need not be directly comparable.

Working Through the Objective

Keep the fit term and penalty term separate until both have been calculated. First use the proposed coefficients to obtain every fitted value and residual. Then square and add the residuals. Finally square and add the slope coefficients, multiply by \(\lambda\), and add that penalty to the RSS.

Worked Example: Comparing Two Candidate Fits

A hypothetical service team models the number of weekly requests using one predictor \(x\). The three observations are \((x,y)=(0,2),(1,4),(2,5)\). For \(\lambda=0.5\), calculate the ridge objective for each candidate: A has \((\beta_0,\beta_1)=(2,1)\), and B has \((\beta_0,\beta_1)=(1,1.5)\). Which candidate has the smaller objective? The method is to compute RSS and the slope penalty separately; this avoids comparing fit alone while overlooking the penalty.

Candidate A: fitted values and RSS. Its predictions are \(2+1(0)=2\), \(2+1(1)=3\), and \(2+1(2)=4\). The residuals are \(2-2=0\), \(4-3=1\), and \(5-4=1\). Therefore, \(\mathrm{RSS}_A=0^2+1^2+1^2=2\).

The squared slope is \(1^2=1\), so the penalty is \(0.5(1)=0.5\). Candidate A’s objective is \(J_A=2+0.5=2.5\).

Candidate B: fitted values and RSS. Its predictions are \(1+1.5(0)=1\), \(1+1.5(1)=2.5\), and \(1+1.5(2)=4\). The residuals are \(2-1=1\), \(4-2.5=1.5\), and \(5-4=1\). Therefore, \(\mathrm{RSS}_B=1^2+1.5^2+1^2=1+2.25+1=4.25\).

The squared slope is \(1.5^2=2.25\), so the penalty is \(0.5(2.25)=1.125\). Candidate B’s objective is \(J_B=4.25+1.125=5.375\). Since \(2.5<5.375\), A has the smaller objective among these two candidates. This comparison does not prove that A minimizes the objective over all possible coefficient values.

The tuning parameter \(\lambda\) determines how much the objective charges for large slopes. At \(\lambda=0\), the penalty vanishes, and minimizing this objective is the ordinary least-squares criterion. For \(\lambda>0\), a coefficient set with larger slopes pays a larger penalty, all else equal. Increasing \(\lambda\) makes that penalty more influential relative to RSS.

Do not interpret this statement as a guarantee that every individual slope must decrease whenever \(\lambda\) increases. The coefficients are chosen together, and relationships among predictors can make their individual changes complicated. The objective gives the trade-off; its minimizer depends on the data and all predictors.

Worked Example: The Penalty with Multiple Predictors

A hypothetical maintenance model has two predictors. For a particular proposed coefficient set, \(\beta_0=10\), \(\beta_1=0.8\), and \(\beta_2=-0.4\). The four observed rows \((x_1,x_2,y)\) are \((0,0,10),(1,0,11),(0,1,9),(1,1,10)\). Calculate its objective first for \(\lambda=0.5\), then for \(\lambda=2\). The method is to hold the candidate coefficients fixed and change only the penalty multiplier; this avoids treating the tuning parameter as if it changed the observed data.

The fitted values, in row order, are \(10\), \(10+0.8=10.8\), \(10-0.4=9.6\), and \(10+0.8-0.4=10.4\). The residuals are \(0\), \(0.2\), \(-0.6\), and \(-0.4\). Hence \(\mathrm{RSS}=0^2+0.2^2+(-0.6)^2+(-0.4)^2=0+0.04+0.36+0.16=0.56\).

The sum of squared slopes is \(0.8^2+(-0.4)^2=0.64+0.16=0.80\). For \(\lambda=0.5\), the penalty is \(0.5(0.80)=0.40\), so \(J=0.56+0.40=0.96\). For \(\lambda=2\), the penalty is \(2(0.80)=1.60\), so \(J=0.56+1.60=2.16\). The RSS is unchanged because the coefficients and data did not change; only the penalty contribution changed.

Why a Penalty Represents a Constraint

The penalty can be understood as a way to express a preference for small coefficients when fitting the data. One related formulation is to minimize RSS subject to a bound on the sum of squared slopes. This provides a short justification for why adding a squared-coefficient term produces a fit-versus-size trade-off.

1
Set a coefficient-size limit.
Consider minimizing \(\mathrm{RSS}\) subject to \(\sum_{j=1}^{p}\beta_j^2\leq t\), where \(t\) is a chosen nonnegative bound.
2
Form the constrained objective.
For an active constraint, a nonnegative Lagrange multiplier \(\lambda\) gives the expression \(\mathrm{RSS}+\lambda(\sum_{j=1}^{p}\beta_j^2-t)\).
3
Remove the constant.
For fixed \(\lambda\) and \(t\), the term \(-\lambda t\) is constant with respect to the coefficients. Removing it does not change which coefficients minimize the expression, leaving \(\mathrm{RSS}+\lambda\sum_{j=1}^{p}\beta_j^2\).

This derivation shows why the penalized objective is connected to limiting coefficient size. It does not mean that \(\lambda\) itself is the bound \(t\): \(\lambda\) is the multiplier on the penalty, while \(t\) specifies a constraint in the alternative formulation. The relationship between them depends on the data.

Worked Example: Applying the Intercept Convention

A hypothetical two-predictor model has three observed responses \(6,8,8\), with corresponding predictor pairs \((0,0),(1,0),(0,1)\). Evaluate the candidate \((\beta_0,\beta_1,\beta_2)=(5,2,-1)\) at \(\lambda=2\). The method is to calculate the predictions and RSS, then penalize only the slopes; this avoids the common mistake of including the intercept in the penalty.

The predictions are \(5+2(0)-1(0)=5\), \(5+2(1)-1(0)=7\), and \(5+2(0)-1(1)=4\). The residuals are \(6-5=1\), \(8-7=1\), and \(8-4=4\). Thus \(\mathrm{RSS}=1^2+1^2+4^2=1+1+16=18\).

The squared slopes sum to \(2^2+(-1)^2=4+1=5\), so the penalty is \(2(5)=10\). The correct objective is \(18+10=28\). A mistaken calculation would also penalize the intercept: \(18+2(5^2+2^2+(-1)^2)=18+2(25+4+1)=78\). That is not the objective defined here, because \(\beta_0\) is excluded.

Common Exam Traps

  • Adding rather than squaring coefficients. The ridge penalty uses \(\sum_j\beta_j^2\), not \(\sum_j\beta_j\) or \(\sum_j|\beta_j|\).
  • Applying \(\lambda\) to the whole objective. In the convention here, \(J=\mathrm{RSS}+\lambda\sum_j\beta_j^2\). It is not \(\lambda(\mathrm{RSS}+\sum_j\beta_j^2)\).
  • Penalizing the intercept. The displayed convention excludes \(\beta_0\). Follow the stated objective if a problem specifies a different convention.
  • Calling a candidate score the minimum. A calculated \(J\) is the objective value at those coefficients. To claim that a coefficient set is the ridge fit, it must minimize \(J\) over the allowed coefficient values.
  • Comparing tuning parameters across scaling conventions. Some formulations divide RSS by a sample-size factor or put a constant beside the penalty. Such changes affect the numerical meaning of \(\lambda\). Compare objectives only after writing down their exact conventions.
Key takeaway: Under the convention in this tutorial, ridge regression minimizes RSS plus \(\lambda\) times the sum of squared slope coefficients. Calculate the two terms separately, omit the intercept from the penalty, and interpret \(\lambda\) relative to the exact scaling of the stated objective. This treatment is aligned with the SOA Exam PA (Predictive Analytics) syllabus.

Check Your Understanding

For each problem, calculate the requested objective using the stated convention.

  1. A one-predictor candidate has residuals \(-1,0.5,1\), slope \(\beta_1=0.5\), and \(\lambda=2\). Calculate RSS, penalty, and objective. (Answer: RSS \(=2.25\), penalty \(=0.5\), objective \(=2.75\).)
  2. A two-predictor candidate has \(\beta_0=4,\beta_1=0.6,\beta_2=-0.8\), RSS \(=4.2\), and \(\lambda=1.5\). Calculate its objective. (Answer: \(5.7\).)
  3. A candidate has \(\beta_0=7,\beta_1=-0.5,\beta_2=0.25\), RSS \(=2.4\), and \(\lambda=4\). Calculate the correct objective without penalizing the intercept. (Answer: \(3.65\).)
  4. For \(\lambda=0.5\), candidate A has RSS \(=5\) and slopes \(1,1\); candidate B has RSS \(=5.4\) and slopes \(0.5,0.5\). Calculate both objective values and identify which candidate scores lower. (Answer: A has objective \(6\), B has objective \(5.65\); B scores lower.)
  5. An objective is defined as \(\mathrm{RSS}/(2n)+(\lambda/2)\sum_j\beta_j^2\). For \(n=6\), RSS \(=18\), \(\sum_j\beta_j^2=3\), and \(\lambda=0.4\), calculate its value. (Answer: \(2.1\).)
Clinical Biostats