Tutorials › Exam SRM - Statistics for Risk Modeling › Counting Parameters In Regression AIC

Exam SRM · Information Criteria · Tutorial 189 of 926

Counting Parameters In Regression AIC

Determine the number of estimated parameters in a Gaussian regression AIC and calculate comparable values without confusing coefficients, variance, or reporting conventions.

Intermediate 10 min read

What You'll Learn

  • Count identifiable regression coefficients using the rank of the design matrix.
  • Include an estimated Gaussian error variance in the full AIC parameter count.
  • Treat an intercept as a coefficient, not as an additional term beyond the coefficient count.
  • Distinguish full AIC from versions that omit a common likelihood constant.
  • Recognize why a zero residual sum of squares prevents a finite Gaussian variance MLE.

Why Parameter Counting Matters in Regression AIC

AIC balances a model’s maximized likelihood against a penalty for the number of estimated parameters. In Gaussian linear regression, that count includes more than the slopes: it also includes an intercept when one is estimated and the error variance when it is unknown. A one-parameter counting difference changes the penalty by 2, so a small bookkeeping error can change a model comparison.

The key is to count free, identifiable parameters in the likelihood, rather than simply counting predictor names. The rank of the design matrix determines the number of distinct regression coefficients. The error variance is another parameter if it is estimated. An intercept is already among the regression coefficients; it is not an extra parameter to add after counting all coefficient terms.

Definition: For a Gaussian linear regression with \(n\) observations, write \(Y=X\beta+\varepsilon\), where \(X\) is a fixed \(n\times p\) design matrix, \(\beta\) is a vector of regression coefficients, and the errors are independent with \(\varepsilon_i\sim N(0,\sigma^2)\). Let \(q=\operatorname{rank}(X)\). If the coefficients and the common error variance are estimated, the full AIC parameter count is \(k=q+1\): \(q\) identifiable coefficient parameters and one variance parameter.

This statement assumes a Gaussian model with a common, unknown variance. If the variance is specified as known, it is not estimated and is not counted. If a model has additional free distributional parameters, they must also be counted. A coefficient constrained by the model is not a free parameter; an unidentifiable coefficient does not add a distinct likelihood parameter. In the usual full-rank regression design, \(q\) is the number of columns of \(X\).

The Gaussian Likelihood and the Count

For the model above, the residual sum of squares at the least-squares coefficient estimate is \(\mathrm{RSS}=\sum_{i=1}^{n}(y_i-\widehat{y}_i)^2\). When \(\mathrm{RSS}>0\), maximizing the Gaussian likelihood over the coefficients and the unknown variance gives \(\widehat{\beta}\) as a least-squares estimate and the maximum-likelihood variance estimate \(\widehat{\sigma}^2_{\mathrm{ML}}=\mathrm{RSS}/n\). The denominator is \(n\), not the residual degrees of freedom \(n-q\).

For \(\mathrm{RSS}>0\), the maximized negative twice log-likelihood and the full AIC are therefore

$$ -2\ell(\widehat{\beta},\widehat{\sigma}^2_{\mathrm{ML}}) =n\left[\log(2\pi)+1+\log\left(\frac{\mathrm{RSS}}{n}\right)\right], \qquad \mathrm{AIC} =-2\ell(\widehat{\beta},\widehat{\sigma}^2_{\mathrm{ML}})+2(q+1). $$

The formula requires a finite maximum-likelihood estimate of the variance, which in this setting requires \(\mathrm{RSS}>0\). A saturated model whose design matrix has rank \(n\) fits every observation exactly, so \(\mathrm{RSS}=0\). More generally, any exact fit with zero RSS creates the same issue: the Gaussian likelihood increases without bound as \(\sigma^2\) approaches zero. There is then no finite maximum-likelihood estimate of the variance, and the displayed log-likelihood and ordinary AIC calculation are not finite.

Why the Variance Counts

The likelihood depends on both the mean parameters and the error variance. For a fixed coefficient vector, its log-likelihood is

$$ \ell(\beta,\sigma^2) =-\frac{n}{2}\log(2\pi\sigma^2) -\frac{1}{2\sigma^2}\sum_{i=1}^{n}(y_i-x_i^\mathsf{T}\beta)^2. $$

The first term depends on \(\sigma^2\), and the second term depends on it as well. Thus, when the variance is unknown, choosing its value is part of fitting the model, just as choosing \(\beta\) is. That is why the variance contributes one estimated parameter to the full AIC count.

For completeness, fix \(\beta=\widehat{\beta}\) and write the residual sum of squares as \(R>0\). Differentiating the log-likelihood with respect to \(\sigma^2\) gives

$$ \frac{\partial \ell}{\partial \sigma^2} =-\frac{n}{2\sigma^2}+\frac{R}{2(\sigma^2)^2}. $$

Setting this derivative to zero gives \(R=n\sigma^2\), hence \(\widehat{\sigma}^2_{\mathrm{ML}}=R/n\). The second derivative at this value is negative, so it is a maximum. Substitution into the log-likelihood produces the stated expression, provided \(R>0\). If \(R=0\), this calculation has no positive finite solution; the likelihood is unbounded as the variance tends to zero.

Worked Example: Counting the Intercept and Variance

A hypothetical portfolio study fits a Gaussian regression to \(n=20\) observations. Its model has an intercept and two slopes, and its residual sum of squares is 16. Calculate the full AIC. State the parameter count and check the variance estimate.

Method. Count the identifiable coefficients, add one for the unknown Gaussian error variance, and use the maximized-likelihood AIC formula. This avoids counting the intercept twice or using the unbiased residual variance in place of the MLE.

There are three regression coefficients: one intercept and two slopes. Thus \(q=3\), and the full parameter count is \(k=q+1=4\). The maximum-likelihood variance estimate is

$$ \widehat{\sigma}^2_{\mathrm{ML}}=\frac{\mathrm{RSS}}{n}=\frac{16}{20}=0.8. $$

Since \(0.8>0\), the finite-variance formula applies. Using \(\log(2\pi)\approx1.837877\) and \(\log(0.8)\approx-0.223144\),

$$ -2\ell =20[1.837877+1-0.223144] =20(2.614733) =52.29466. $$

The penalty is \(2k=2(4)=8\), so the full AIC is \(52.29466+8=60.29466\), or 60.29 to two decimal places. The count is three coefficients plus one variance parameter, and the positive estimated variance confirms the likelihood calculation is finite.

What Counts as a Regression Coefficient?

A predictor name does not necessarily correspond to one coefficient. For example, a categorical predictor with four levels is often represented by three indicator columns when a reference level is used. Those columns contribute three coefficients, not one. A continuous predictor represented by one column contributes one coefficient. An interaction or other model term contributes as many independent columns as its parameterization requires.

The reliable count is the rank \(q\) of the design matrix, not the number of labels in a model formula. This also handles redundant columns: if one column is an exact linear combination of others, the design matrix rank does not increase, and it does not create another identifiable coefficient. In the common case of a full-column-rank design, count the intercept column if present, then count each additional independent coefficient column.

Worked Example: A Categorical Predictor and Competing Models

Two hypothetical Gaussian regressions use the same \(n=12\) observations. Model A has an intercept and three slopes, with \(\mathrm{RSS}=12\). Model B adds one independent slope, with \(\mathrm{RSS}=9\). Calculate each full AIC and identify which is smaller.

Method. Count the coefficient columns and the unknown variance separately in each model, then calculate the maximized log-likelihood from its own RSS. This avoids assuming that adding a predictor adds both a slope and a new variance parameter: both models already estimate one variance.

For Model A, \(q_A=4\), so \(k_A=4+1=5\). Its variance estimate is \(12/12=1\), and

$$ -2\ell_A=12[1.837877+1+\log(1)] =12(2.837877)=34.054524. $$

Its AIC is \(34.054524+2(5)=44.054524\).

For Model B, \(q_B=5\), so \(k_B=5+1=6\). Its variance estimate is \(9/12=0.75\), and \(\log(0.75)\approx-0.287682\). Therefore,

$$ -2\ell_B =12[1.837877+1-0.287682] =12(2.550195) =30.602340. $$

Its AIC is \(30.602340+2(6)=42.602340\). Model B has the smaller AIC by \(44.054524-42.602340=1.452184\), or 1.45 to two decimal places. The additional slope increases the penalty by 2, while the improved fit lowers \(-2\ell\) by about 3.45, giving a net AIC decrease of about 1.45.

Reporting Conventions and Common Traps

Some regression summaries report a version of Gaussian AIC with a likelihood constant omitted. Because \(n\log(2\pi)\) is the same for models fitted to the same response observations, a commonly used reduced expression is

$$ n\left[1+\log\left(\frac{\mathrm{RSS}}{n}\right)\right]+2k. $$

This is the full AIC minus \(n\log(2\pi)\). It gives the same ranking among models fit to the same observations, but its reported numerical value is not the full AIC value. When comparing reported values, identify whether the constant is included and whether the parameter count includes the variance. A convention that omits the variance from \(k\) also changes the value by 2 per model relative to the full count; it should not be mistaken for the full likelihood-based AIC defined here.

Another common error is substituting the unbiased estimate \(s^2=\mathrm{RSS}/(n-q)\) into the maximized-likelihood formula. That estimate is often useful for other regression purposes, but it is not the maximum-likelihood estimate used to obtain this Gaussian AIC expression. Also check whether the model includes an intercept, whether its design columns are independent, and whether the candidate models use the same observations. A comparison with different samples or different reporting conventions is not a straightforward comparison of the displayed AIC values.

A particularly serious trap is mechanically applying the formula when \(\mathrm{RSS}=0\). For example, if \(q=n\) and \(X\) has rank \(n\), the fitted values can equal every observed response, yielding \(\mathrm{RSS}=0\). Substituting this into \(\log(\mathrm{RSS}/n)\) produces \(\log(0)\), not a finite AIC. The issue is not a rounding problem: the Gaussian likelihood has no finite maximum over the unknown variance.

Worked Example: No Intercept and a Known Variance

A hypothetical model without an intercept has two independent regression columns, \(n=10\), and \(\mathrm{RSS}=5\). First calculate its full AIC when the common error variance is unknown. Then state how the parameter count changes if the variance is known to be \(0.5\).

Method. Use the design rank rather than automatically adding an intercept, and distinguish an estimated variance from a known one. This avoids counting a coefficient that is absent from the model or counting a fixed quantity as estimated.

The design rank is \(q=2\). With unknown variance, \(k=2+1=3\), and

$$ \widehat{\sigma}^2_{\mathrm{ML}}=\frac{5}{10}=0.5. $$

Using \(\log(0.5)\approx-0.693147\),

$$ -2\ell =10[1.837877+1-0.693147] =10(2.144730) =21.447300. $$

The full AIC is \(21.447300+2(3)=27.447300\), or 27.45 to two decimal places. If the variance is instead known to be \(0.5\), it is no longer an estimated parameter, so the count is \(k=2\). At this particular value, the likelihood term is unchanged because \(0.5\) equals the MLE; the AIC penalty becomes \(2(2)=4\), giving \(25.447300\), or 25.45. This illustrates that the count follows what is estimated, not merely what appears in the likelihood.

Check Your Understanding

For each problem, use the full Gaussian AIC convention unless the question explicitly changes the variance assumption. Round numerical AIC values to two decimal places.

  1. A regression has \(n=18\), an intercept, two slopes, and \(\mathrm{RSS}=27\). Find \(q\), \(k\), the maximum-likelihood variance estimate, and the full AIC. (Answer: \(q=3\), \(k=4\), \(\widehat{\sigma}^2_{\mathrm{ML}}=1.5\), AIC \(=66.38\).)
  2. A model uses \(n=25\) observations, an intercept, a four-level categorical predictor represented by three indicator columns, and one continuous predictor. If the design columns are independent and \(\mathrm{RSS}=25\), find \(k\) and the full AIC. (Answer: \(q=5\), \(k=6\), AIC \(=82.95\).)
  3. A full-rank regression with \(n=16\) has an intercept and four slopes, with \(\mathrm{RSS}=8\). Find the full parameter count, maximum-likelihood variance estimate, and full AIC. (Answer: \(k=6\), \(\widehat{\sigma}^2_{\mathrm{ML}}=0.5\), AIC \(=46.32\).)
  4. For \(n=20\), a model has \(q=3\) identifiable coefficients and \(\mathrm{RSS}=10\). Find the full AIC and the value from the convention that omits \(n\log(2\pi)\). (Answer: full AIC \(=50.89\); reduced value \(=14.14\).)
  5. A Gaussian regression has \(n=8\), design rank \(q=8\), and therefore fits all observations exactly. Can its unknown-variance Gaussian AIC be calculated by substituting \(\mathrm{RSS}=0\) into the usual formula? (Answer: No. The likelihood is unbounded as \(\sigma^2\) tends to zero, so there is no finite variance MLE or finite AIC from that formula.)
Clinical Biostats