Multicollinearity in the Sudan Renewable-Energy Model

Econometrics Exercise 8 | Diagnosis and remedies

Author

Ahmed Mustafa

Published

November 26, 2026

Code
:root {
  --brand: #AA272F;
  --brand-dark: #7F1D24;
  --brand-pale: #F7E9EA;
  --brand-blue: #1B4F72;
  --brand-green: #477A63;
  --brand-amber: #B7791F;
  --ink: #292929;
}
body { color: var(--ink); }
h1, h2, h3 { color: var(--brand-dark); }
h1 { border-bottom: 2px solid var(--brand); padding-bottom: .25rem; }
.callout-note    { border-left-color: var(--brand) !important; }
.callout-tip     { border-left-color: var(--brand-green) !important; }
.callout-warning { border-left-color: var(--brand-amber) !important; }
.callout-important { border-left-color: var(--brand-blue) !important; }
table caption { color: var(--brand-dark); font-weight: 700; }
table thead th { background: var(--brand-dark) !important; color: #fff !important; }
.table > tbody > tr:nth-of-type(odd) > * { background-color: #FBF5F5; }

1 Roadmap

NoteWorkflow

Multicollinearity means that some regressors are (almost) linear combinations of the others. The OLS estimates stay unbiased, but individual coefficients become imprecise: large standard errors, small t-statistics, unstable signs.

In order to finish this exercise, five steps are applied to Sudan’s annual data (FDI and renewable energy):

  1. Diagnose the baseline model: correlations, VIF, condition number.
  2. Create a stronger problem on purpose with a quadratic term in log GDP.
  3. Remedy I: drop the redundant term (if justified).
  4. Remedy II: transform or center the regressors.
  5. Remedy III: basic ridge regression.
WarningTwo limitations specific to this dataset
  • Annual time series, not a cross-section. Sudan’s series is short and trending, so regressors that move together over time are a natural source of collinearity. Autocorrelation in the errors is a separate problem that also distorts standard errors.
  • Course convention: the matrix of regressors \(\mathbf X\) is treated as fixed (deterministic). VIF, eigenvalues and the condition number fit this convention. The Farrar–Glauber test assumes random regressors, so it is shown only as a supplement.

2 Data and workspace

2.1 Restore the cleaned Sudan data

The cleaned sudan_clean object is restored from a saved workspace instead of re-importing and re-cleaning the CSV.

Code
analysis_vars <- c("REN_ERG_CONS", "FDI_GDP", "GDP_billions",
                   "IND_VA_GDP", "NODA_RCV", "Trade_GDP")
regressors <- setdiff(analysis_vars, "REN_ERG_CONS")

load_sudan <- function() {
  candidates <- c("sudan_exercise7_forecasting_results.RData",
                  "sudan_exercise5_results.RData",
                  "sudan_exercise5_workspace.RData")
  for (f in candidates[file.exists(candidates)]) {
    e <- new.env(parent = baseenv())
    load(f, envir = e)
    if (exists("sudan_clean", envir = e, inherits = FALSE)) {
      return(list(data = get("sudan_clean", envir = e), source = f))
    }
  }
  csv <- c("udaje/LDC-Panel-Data.csv", "LDC-Panel-Data.csv")
  csv <- csv[file.exists(csv)]
  if (!length(csv)) {
    stop("No saved workspace and no LDC-Panel-Data.csv found. ",
         "Place one of them in the working directory or in 'udaje/'.")
  }
  raw <- read.csv(csv[1], na.strings = c("", "NA"), stringsAsFactors = FALSE)
  d <- raw |>
    filter(Country_Code == "SDN") |>
    mutate(GDP_billions = GDP_USD / 1e9) |>
    arrange(Year) |>
    filter(if_all(all_of(analysis_vars), ~ !is.na(.x)))
  list(data = d, source = csv[1])
}

loaded <- load_sudan()

udaje8 <- loaded$data |>
  mutate(Year = as.integer(as.character(Year))) |>
  arrange(Year) |>
  select(Year, all_of(analysis_vars)) |>
  as.data.frame()

stopifnot(
  all(is.finite(as.matrix(udaje8))),
  all(udaje8$GDP_billions > 0),          # needed for log(GDP)
  !anyDuplicated(udaje8$Year),
  nrow(udaje8) > length(regressors) + 5
)
n8 <- nrow(udaje8)

data.frame(
  Item = c("Country", "Data source", "Period", "Observations (n)",
           "Regressors in baseline (k)", "Observations per parameter"),
  Value = c("Sudan", loaded$source, paste(min(udaje8$Year), max(udaje8$Year), sep = "–"),
            n8, length(regressors), f3(n8 / (length(regressors) + 1), 1))
) |> brand_table("Analysis sample")
Analysis sample
Item Value
Country Sudan
Data source sudan_exercise7_forecasting_results.RData
Period 1995–2021
Observations (n) 27
Regressors in baseline (k) 5
Observations per parameter 4.5

2.2 Do the regressors move together over time?

Because the data are a time series, a common trend is the first thing to check.

Code
udaje8 |>
  select(Year, all_of(regressors)) |>
  tidyr::pivot_longer(-Year, names_to = "Variable", values_to = "Value") |>
  ggplot(aes(Year, Value)) +
  geom_line(colour = brand_blue, linewidth = 0.8) +
  geom_point(colour = brand, size = 1.4) +
  facet_wrap(~ Variable, scales = "free_y", ncol = 2) +
  labs(title = "Regressors over time", x = "Year", y = NULL) +
  theme_brand()

Sudan’s regressors over time (each panel has its own scale).
Code
trend_cor <- data.frame(
  Variable = regressors,
  `Correlation with Year` = sapply(regressors, function(v) cor(udaje8[[v]], udaje8$Year)),
  check.names = FALSE
) |> arrange(desc(abs(`Correlation with Year`)))

brand_table(trend_cor, "Correlation of each regressor with calendar time", 3)
Correlation of each regressor with calendar time
Variable Correlation with Year
GDP_billions 0.731
NODA_RCV 0.544
IND_VA_GDP 0.375
Trade_GDP -0.268
FDI_GDP 0.104
Code
strongest_trend <- trend_cor$Variable[1]
strongest_trend_r <- trend_cor$`Correlation with Year`[1]
NoteInterpretation

GDP_billions has the strongest time trend (correlation with Year = 0.73). Any two regressors that both trend strongly will be correlated with each other even if they are economically unrelated. This is “spurious” collinearity from common trends, and it is the main reason to expect an imprecise multiple regression with only 27 observations.

3 What multicollinearity does and does not do

For the coefficient of regressor \(x_j\) (fixed \(\mathbf X\), \(E(\mathbf u)=0\), \(Var(\mathbf u)=\sigma^2\mathbf I\)):

\[ Var(\hat\beta_j)=\frac{\sigma^2}{\sum_i (x_{ji}-\bar x_j)^2}\cdot VIF_j, \qquad VIF_j=\frac{1}{1-R_j^2}. \]

\(R_j^2\) comes from the auxiliary regression of \(x_j\) on all the other regressors. A \(VIF_j\) of 5 means the standard error is \(\sqrt5\approx2.2\) times larger than it would be if \(x_j\) were uncorrelated with the others.

TipCan cause
  • Large standard errors and wide confidence intervals for individual coefficients
  • Small \(|t|\) values and “insignificant” variables despite a good overall fit
  • Estimates that swing when one observation or one regressor is added or removed
ImportantDoes not cause
  • Bias: \(\hat{\boldsymbol\beta}=\boldsymbol\beta+(\mathbf X^\mathsf T\mathbf X)^{-1}\mathbf X^\mathsf T\mathbf u\), so \(E(\hat{\boldsymbol\beta})=\boldsymbol\beta\) whenever \(E(\mathbf u)=0\).
  • Heteroscedasticity or autocorrelation, or a low \(R^2\) or poor forecasts.

Bias comes from specification errors (omitted variables, endogeneity), not from collinearity. This distinction matters when choosing a remedy.

4 Baseline model

The baseline is the following multiple regression formula:

\[ REN_t=\beta_0+\beta_1FDI_t+\beta_2GDP_t+\beta_3Industry_t+\beta_4ODA_t+\beta_5Trade_t+u_t . \]

Code
m_base <- lm(REN_ERG_CONS ~ FDI_GDP + GDP_billions + IND_VA_GDP +
               NODA_RCV + Trade_GDP, data = udaje8)

brand_table(coef_table(m_base), "Baseline OLS estimates (full sample)", 4)
Baseline OLS estimates (full sample)
Variable Estimate Std. error t statistic p-value Sig. 95% CI
(Intercept) 102.5405 3.1545 32.5059 < 0.001 *** [95.980, 109.101]
FDI_GDP 0.6260 0.4307 1.4533 0.161 [-0.270, 1.522]
GDP_billions -1.0194 0.0881 -11.5690 < 0.001 *** [-1.203, -0.836]
IND_VA_GDP 0.2337 0.3081 0.7584 0.457 [-0.407, 0.874]
NODA_RCV -0.1287 0.3924 -0.3279 0.746 [-0.945, 0.687]
Trade_GDP 0.3548 0.1170 3.0339 0.006 ** [0.112, 0.598]
Code
brand_table(fit_table(list("Baseline (5 regressors)" = m_base)),
            "Baseline fit and overall F-test", 4)
Baseline fit and overall F-test
Model N R² Adj. R² Sigma F p (F) AIC BIC
Baseline (5 regressors) 27 0.9106 0.8893 2.9098 42.7728 < 0.001 141.5137 150.5845
Code
ct <- broom::tidy(m_base) |> filter(term != "(Intercept)")
n_sig <- sum(ct$p.value < 0.05)
k_reg <- nrow(ct)
gb <- broom::glance(m_base)
dw_p <- lmtest::dwtest(m_base)$p.value
symptom_text <- if (gb$r.squared >= 0.7 && n_sig < k_reg) {
  "A high joint fit combined with weaker individual t-tests is the classic symptom of multicollinearity. It is only a hint, so the next section checks it formally."
} else {
  "There is no obvious mismatch between the joint and individual tests, but collinearity can still be present, so we check it formally."
}
NoteInterpretation

The model explains 91.1% of the variation in renewable energy consumption (\(R^2\) = 0.911, adjusted \(R^2\) = 0.889), and the overall F-test p-value is < 0.001. Individually, 2 of 5 slope coefficients are significant at 5%. A high joint fit combined with weaker individual t-tests is the classic symptom of multicollinearity. It is only a hint, so the next section checks it formally.

Side note: the Durbin–Watson test on these residuals gives p = 0.008. Autocorrelation is a different problem from collinearity, but it would also make the standard errors above unreliable.

5 Diagnosing multicollinearity

5.1 Correlation matrix and heatmap

The heatmap shows the pairwise Pearson correlations (numbers are printed in the cells). Blue is negative, white is near zero, red is positive. It is just a graphical display of the correlation matrix, not a test.

Code
R8 <- cor(udaje8[, regressors])
heatmap_cor(R8, "Correlations among baseline regressors")

Correlations among the baseline regressors (no constant column).
Code
top_pairs <- as.data.frame(as.table(R8)) |>
  filter(as.character(Var1) < as.character(Var2)) |>
  transmute(`Variable 1` = as.character(Var1), `Variable 2` = as.character(Var2),
            Correlation = Freq) |>
  arrange(desc(abs(Correlation)))
brand_table(head(top_pairs, 3), "Three most correlated pairs of regressors", 3)
Three most correlated pairs of regressors
Variable 1 Variable 2 Correlation
GDP_billions IND_VA_GDP 0.712
IND_VA_GDP Trade_GDP 0.546
IND_VA_GDP NODA_RCV 0.508

Correlations among the baseline regressors (no constant column).

NoteInterpretation

The most correlated pair is GDP_billions and IND_VA_GDP (r = 0.71). Pairwise correlations are only a first look. A regressor can be almost a combination of two or three others without any single large pairwise correlation, which is why the VIF is the main tool.

5.2 Variance inflation factors (VIF)

Code
vif_base <- tabulka_vif(m_base)
brand_table(vif_base, "VIF in the baseline model", 3)
VIF in the baseline model
Variable VIF Assessment
FDI_GDP 1.308 Low (< 5)
GDP_billions 2.085 Low (< 5)
IND_VA_GDP 4.820 Low (< 5)
NODA_RCV 2.570 Low (< 5)
Trade_GDP 2.798 Low (< 5)
Code
max_vif_base     <- max(vif_base$VIF)
max_vif_base_var <- vif_base$Variable[which.max(vif_base$VIF)]
max_r2_aux       <- 1 - 1 / max_vif_base
verdict_base <- if (max_vif_base >= 10) {
  "This is severe by the usual rule of thumb. Standard errors for this variable are heavily inflated, but that alone is not a reason to drop it: first ask whether it is economically needed."
} else if (max_vif_base >= 5) {
  "This is moderate. Precision is clearly affected, so interpret that coefficient with care and check how stable it is."
} else {
  "This is below the usual thresholds. Collinearity is **not** a serious problem in the baseline model, so there is no case for dropping or transforming anything for this reason."
}
NoteInterpretation

The highest VIF belongs to IND_VA_GDP (VIF = 4.82). The other regressors explain 79.3% of its variation (\(R_j^2\) = 0.793), and its standard error is about 2.20 times larger than under orthogonality. This is below the usual thresholds. Collinearity is not a serious problem in the baseline model, so there is no case for dropping or transforming anything for this reason.

The VIF thresholds 5 and 10 are rules of thumb, not critical values of a test.

5.3 Eigenvalues and condition number

If the correlation matrix of the regressors has an eigenvalue close to zero, the regressors are close to a linear dependence. The condition index of component \(j\) is \(\sqrt{\lambda_{\max}/\lambda_j}\), and \(\kappa\) is the largest of them.

Code
ev <- eigen(R8, symmetric = TRUE)$values
kappa_base <- sqrt(max(ev) / min(ev))

data.frame(Component = seq_along(ev), Eigenvalue = ev,
           `Condition index` = sqrt(max(ev) / ev), check.names = FALSE) |>
  brand_table("Spectral diagnostics of the regressor correlation matrix", 3)
Spectral diagnostics of the regressor correlation matrix
Component Eigenvalue Condition index
1 2.509 1.000
2 1.330 1.374
3 0.627 2.000
4 0.415 2.460
5 0.119 4.598
NoteInterpretation

The smallest eigenvalue is 0.119 and the condition number is \(\kappa\) = 4.60. A commonly quoted guide is that values above about 30 signal serious near-dependence, but this cut-off is not universal and depends on the standardisation. Read \(\kappa\) together with the VIFs: here the two agree that the baseline is fine.

5.4 Supplementary: Farrar–Glauber test

Code
p8 <- ncol(R8)
fg_chi2 <- -(n8 - 1 - (2 * p8 + 5) / 6) * log(det(R8))
fg_df   <- p8 * (p8 - 1) / 2
fg_p    <- pchisq(fg_chi2, df = fg_df, lower.tail = FALSE)

data.frame(Test = "Farrar–Glauber (overall)", `Chi-square` = fg_chi2,
           df = fg_df, `p-value` = fmt_p(fg_p), check.names = FALSE) |>
  brand_table("Farrar–Glauber test (H0: the regressors are mutually uncorrelated)", 3)
Farrar–Glauber test (H0: the regressors are mutually uncorrelated)
Test Chi-square df p-value
Farrar–Glauber (overall) 53.408 10 < 0.001
WarningUse with care

The test assumes random regressors, which conflicts with our fixed-\(\mathbf X\) convention. It also tends to reject whenever correlations are non-zero, however small. Here p = < 0.001. A rejection means “not all uncorrelated”, not “dangerous multicollinearity”. Base decisions on the VIF and \(\kappa\).

6 Creating a stronger problem: the quadratic term

If the baseline VIFs are modest, a serious case can be built from real data by adding a quadratic term. We replace GDP by \(\ln(GDP)\) and add its square:

\[ REN_t=\beta_0+\beta_1FDI_t+\beta_2\ln GDP_t+\beta_3(\ln GDP_t)^2+\beta_4Industry_t+\beta_5ODA_t+\beta_6Trade_t+u_t . \]

The model is still linear in the parameters. The new regressors \(\ln GDP\) and \((\ln GDP)^2\) can nevertheless be almost perfectly correlated.

Code
udaje8$logGDP  <- log(udaje8$GDP_billions)
udaje8$logGDP2 <- udaje8$logGDP^2

m_nogdp <- lm(REN_ERG_CONS ~ FDI_GDP + IND_VA_GDP + NODA_RCV + Trade_GDP, data = udaje8)
m_log   <- lm(REN_ERG_CONS ~ FDI_GDP + logGDP + IND_VA_GDP + NODA_RCV + Trade_GDP, data = udaje8)
m_poly  <- lm(REN_ERG_CONS ~ FDI_GDP + logGDP + logGDP2 + IND_VA_GDP + NODA_RCV + Trade_GDP, data = udaje8)

poly_regressors <- c("FDI_GDP", "logGDP", "logGDP2", "IND_VA_GDP", "NODA_RCV", "Trade_GDP")
R8_poly <- cor(udaje8[, poly_regressors])
r_log_sq <- cor(udaje8$logGDP, udaje8$logGDP2)

vif_poly <- tabulka_vif(m_poly)
brand_table(vif_poly, "VIF in the quadratic model", 3)
VIF in the quadratic model
Variable VIF Assessment
FDI_GDP 2.964 Low (< 5)
logGDP 2606.271 Severe (≥ 10)
logGDP2 2544.767 Severe (≥ 10)
IND_VA_GDP 5.573 Moderate (5–10)
NODA_RCV 2.671 Low (< 5)
Trade_GDP 3.883 Low (< 5)
Code
heatmap_cor(R8_poly, "Correlations in the quadratic model")

Correlations after adding the quadratic term.
Code
max_vif_poly     <- max(vif_poly$VIF)
max_vif_poly_var <- vif_poly$Variable[which.max(vif_poly$VIF)]
NoteInterpretation

\(\ln GDP\) and \((\ln GDP)^2\) have a correlation of 0.9995. The largest VIF is now 2606.3 (logGDP), compared with 4.82 in the baseline. The collinearity was created by the functional form, because a variable and its own square are nearly the same series whenever the variable stays far from zero.

6.1 Joint fit versus individual t-tests

Code
brand_table(coef_table(m_poly), "Quadratic model: coefficient estimates", 4)
Quadratic model: coefficient estimates
Variable Estimate Std. error t statistic p-value Sig. 95% CI
(Intercept) -176.3403 243.7571 -0.7234 0.478 [-684.809, 332.128]
FDI_GDP 0.4204 0.6544 0.6425 0.528 [-0.945, 1.786]
logGDP 170.2329 131.2247 1.2973 0.209 [-103.497, 443.963]
logGDP2 -28.5515 17.4833 -1.6331 0.118 [-65.021, 7.918]
IND_VA_GDP 0.1734 0.3344 0.5187 0.610 [-0.524, 0.871]
NODA_RCV -0.0806 0.4038 -0.1996 0.844 [-0.923, 0.762]
Trade_GDP 0.3854 0.1391 2.7714 0.012 * [0.095, 0.676]
Code
brand_table(fit_table(list("No GDP terms" = m_nogdp,
                           "Log GDP only" = m_log,
                           "Log GDP + square" = m_poly)),
            "Fit of the nested specifications", 4)
Fit of the nested specifications
Model N R² Adj. R² Sigma F p (F) AIC BIC
No GDP terms 27 0.3407 0.2209 7.7196 2.8424 0.049 193.4564 201.2314
Log GDP only 27 0.9017 0.8783 3.0515 38.5110 < 0.001 144.0817 153.1526
Log GDP + square 27 0.9132 0.8872 2.9372 35.0844 < 0.001 142.7020 153.0687

The overall F-test cannot isolate the two GDP terms (other regressors may be significant). So we test them jointly, against the model without any GDP term:

\[H_0:\ \beta_{\ln GDP}=\beta_{(\ln GDP)^2}=0 .\]

Code
brand_table(f_table(m_nogdp, m_poly), "Partial F-test: joint contribution of ln GDP and (ln GDP)²", 4)
Partial F-test: joint contribution of ln GDP and (ln GDP)²
Model Res. df RSS df diff Sum of sq. F p-value
Restricted 22 1311.0274 – – – –
Unrestricted 20 172.5395 2 1138.488 65.9842 < 0.001
Code
a_joint <- anova(m_nogdp, m_poly)
p_joint <- a_joint$`Pr(>F)`[2]
cp <- broom::tidy(m_poly)
p_l1 <- cp$p.value[cp$term == "logGDP"]
p_l2 <- cp$p.value[cp$term == "logGDP2"]

signature_text <- if (p_joint < 0.05 && p_l1 >= 0.05 && p_l2 >= 0.05) {
  "This is the textbook multicollinearity signature: the two GDP terms are jointly significant, but neither is individually significant because their standard errors are inflated."
} else if (p_joint < 0.05) {
  "The GDP terms are jointly significant and at least one is also individually significant, so the inflated standard errors have not hidden their contribution here."
} else {
  "The GDP terms are not jointly significant either, so the weak t-tests are not only a collinearity artefact: once the controls are in, the data give little evidence for any GDP effect."
}
NoteInterpretation

Individual t-test p-values: \(\ln GDP\) = 0.209, \((\ln GDP)^2\) = 0.118. Joint F-test p-value: < 0.001. This is the textbook multicollinearity signature: the two GDP terms are jointly significant, but neither is individually significant because their standard errors are inflated.

The F-test and the t-tests do not contradict each other because they test different hypotheses. A t-test asks “is this term needed given all the others?”, and with nearly duplicate regressors the answer is hard to give. Therefore a high VIF is not proof that the quadratic term is wrong or irrelevant, and decisions should not rest on individual p-values alone.

7 Remedy I: drop the redundant term

We compare the model with the square (\(M_U\)) with the model without it (\(M_R\)), testing \(H_0:\beta_{(\ln GDP)^2}=0\).

Code
brand_table(f_table(m_log, m_poly), "Partial F-test: is the quadratic term needed?", 4)
Partial F-test: is the quadratic term needed?
Model Res. df RSS df diff Sum of sq. F p-value
Restricted 21 195.5471 – – – –
Unrestricted 20 172.5395 1 23.0076 2.6669 0.118
Code
brand_table(fit_table(list("Without square (M_R)" = m_log, "With square (M_U)" = m_poly)),
            "Fit comparison with and without the quadratic term", 4)
Fit comparison with and without the quadratic term
Model N R² Adj. R² Sigma F p (F) AIC BIC
Without square (M_R) 27 0.9017 0.8783 3.0515 38.5110 < 0.001 144.0817 153.1526
With square (M_U) 27 0.9132 0.8872 2.9372 35.0844 < 0.001 142.7020 153.0687
Code
brand_table(tabulka_vif(m_log), "VIF after dropping the quadratic term", 3)
VIF after dropping the quadratic term
Variable VIF Assessment
FDI_GDP 1.369 Low (< 5)
logGDP 2.263 Low (< 5)
IND_VA_GDP 5.005 Moderate (5–10)
NODA_RCV 2.577 Low (< 5)
Trade_GDP 2.848 Low (< 5)
Code
a_quad <- anova(m_log, m_poly)
p_quad <- a_quad$`Pr(>F)`[2]
aic_pair <- AIC(m_log, m_poly)$AIC
bic_pair <- BIC(m_log, m_poly)$BIC
aic_pick <- c("without the square", "with the square")[which.min(aic_pair)]
bic_pick <- c("without the square", "with the square")[which.min(bic_pair)]
vif_after_drop <- max(tabulka_vif(m_log)$VIF)
NoteInterpretation
  • F-test: p = 0.118. There is no significant evidence that the square is needed once log GDP is in the model.
  • Information criteria: AIC prefers the model with the square, and BIC prefers the model with the square. BIC penalises extra parameters more heavily, so it favours simpler models more often.
  • Collinearity after the drop: the largest VIF falls to 5.01.

Decision for the write-up: the simpler log specification is statistically defensible and removes the collinearity.

WarningNever drop a variable just because its VIF is high

If the variable is relevant, dropping it creates omitted-variable bias, which is worse than imprecision. An insignificant coefficient also does not prove the true effect is zero. Combine theory, tests, diagnostics and the purpose of the model.

8 Remedy II: transformation and centring

8.1 Log transformation of GDP

Code
brand_table(fit_table(list("Linear GDP" = m_base, "Log GDP" = m_log)),
            "Linear versus log GDP (same dependent variable, same sample)", 4)
Linear versus log GDP (same dependent variable, same sample)
Model N R² Adj. R² Sigma F p (F) AIC BIC
Linear GDP 27 0.9106 0.8893 2.9098 42.7728 < 0.001 141.5137 150.5845
Log GDP 27 0.9017 0.8783 3.0515 38.5110 < 0.001 144.0817 153.1526
Code
bind_rows(
  tabulka_vif(m_base) |> mutate(Model = "Linear GDP"),
  tabulka_vif(m_log)  |> mutate(Model = "Log GDP")
) |>
  select(Model, Variable, VIF, Assessment) |>
  brand_table("VIF: linear versus log GDP", 3)
VIF: linear versus log GDP
Model Variable VIF Assessment
Linear GDP FDI_GDP 1.308 Low (< 5)
Linear GDP GDP_billions 2.085 Low (< 5)
Linear GDP IND_VA_GDP 4.820 Low (< 5)
Linear GDP NODA_RCV 2.570 Low (< 5)
Linear GDP Trade_GDP 2.798 Low (< 5)
Log GDP FDI_GDP 1.369 Low (< 5)
Log GDP logGDP 2.263 Low (< 5)
Log GDP IND_VA_GDP 5.005 Moderate (5–10)
Log GDP NODA_RCV 2.577 Low (< 5)
Log GDP Trade_GDP 2.848 Low (< 5)
Code
d_aic <- AIC(m_log) - AIC(m_base)
gdp_vif_lin <- tabulka_vif(m_base)$VIF[tabulka_vif(m_base)$Variable == "GDP_billions"]
gdp_vif_log <- tabulka_vif(m_log)$VIF[tabulka_vif(m_log)$Variable == "logGDP"]
effect_1pct <- 0.01 * coef(m_log)["logGDP"]
NoteInterpretation

Moving from linear to log GDP changes AIC by 2.57 (no improvement), and the VIF of the GDP term goes from 2.09 to 2.26. A log transformation therefore does not automatically reduce VIF. Choose it for its economic meaning: here, a 1% rise in GDP is associated with a change of about -0.440 percentage points in the renewable share, holding the other regressors constant (natural log).

8.2 Centring the polynomial

Define \(z_t=\ln GDP_t-\overline{\ln GDP}\) and use \(z_t\) and \(z_t^2\) instead of \(\ln GDP_t\) and \((\ln GDP_t)^2\). This is only a re-parametrisation of the same regression function, so fitted values and residuals cannot change.

Code
udaje8$z  <- udaje8$logGDP - mean(udaje8$logGDP)
udaje8$z2 <- udaje8$z^2

m_poly_c <- lm(REN_ERG_CONS ~ FDI_GDP + z + z2 + IND_VA_GDP + NODA_RCV + Trade_GDP,
               data = udaje8)

vif_poly_c <- tabulka_vif(m_poly_c)
bind_rows(vif_poly   |> mutate(Model = "Before centring"),
          vif_poly_c |> mutate(Model = "After centring")) |>
  select(Model, Variable, VIF, Assessment) |>
  brand_table("VIF before and after centring", 3)
VIF before and after centring
Model Variable VIF Assessment
Before centring FDI_GDP 2.964 Low (< 5)
Before centring logGDP 2606.271 Severe (≥ 10)
Before centring logGDP2 2544.767 Severe (≥ 10)
Before centring IND_VA_GDP 5.573 Moderate (5–10)
Before centring NODA_RCV 2.671 Low (< 5)
Before centring Trade_GDP 3.883 Low (< 5)
After centring FDI_GDP 2.964 Low (< 5)
After centring z 3.355 Low (< 5)
After centring z2 5.065 Moderate (5–10)
After centring IND_VA_GDP 5.573 Moderate (5–10)
After centring NODA_RCV 2.671 Low (< 5)
After centring Trade_GDP 3.883 Low (< 5)
Code
data.frame(
  Check = c("Largest difference in fitted values", "Largest difference in residuals",
            "Difference in R²"),
  Value = c(max(abs(fitted(m_poly) - fitted(m_poly_c))),
            max(abs(residuals(m_poly) - residuals(m_poly_c))),
            abs(summary(m_poly)$r.squared - summary(m_poly_c)$r.squared))
) |> brand_table("Equivalence check: centred and uncentred models are the same fit", 12)
Equivalence check: centred and uncentred models are the same fit
Check Value
Largest difference in fitted values 0
Largest difference in residuals 0
Difference in R² 0
Code
r_z <- cor(udaje8$z, udaje8$z2)
max_vif_c <- max(vif_poly_c$VIF)
NoteInterpretation

Centring cuts the correlation between the two polynomial terms from 0.9995 to -0.7339, and the largest VIF drops from 2606.3 to 5.57. The equivalence table shows that fitted values, residuals and \(R^2\) are identical up to rounding.

How can VIF fall if the fit does not change? VIF measures the precision of individual coefficients, and centring changes what those coefficients mean. Before centring, \(\hat\beta_{\ln GDP}\) is the slope at \(\ln GDP=0\) (a GDP of 1 billion USD), at the edge of the data, where it is hard to pin down. After centring, \(\hat\alpha_z\) is the slope at the average log GDP, which the data identify much better. Centring improves interpretation and precision, but it adds no new information.

9 Remedy III: ridge regression

Ridge regression shrinks coefficients by penalising their size:

\[ \hat{\boldsymbol\beta}_{Ridge}=(\mathbf X^\mathsf T\mathbf X+\lambda\mathbf I)^{-1}\mathbf X^\mathsf T\mathbf y,\qquad \lambda\ge0 . \]

We use the quadratic model, standardised regressors and a centred dependent variable. The intercept is not penalised. For \(\lambda=0\) we recover OLS, and for \(\lambda>0\) the estimator is biased but has a smaller variance.

Code
Xmat <- as.matrix(udaje8[, poly_regressors])
y8   <- udaje8$REN_ERG_CONS

Xs   <- scale(Xmat)
x_mean <- attr(Xs, "scaled:center")
x_sd   <- attr(Xs, "scaled:scale")
yc   <- y8 - mean(y8)

ridge_beta <- function(lambda) {
  b <- as.numeric(solve(crossprod(Xs) + lambda * diag(ncol(Xs)), crossprod(Xs, yc)))
  names(b) <- colnames(Xs)
  b
}

lambda_grid <- c(0, 1, 5, 10, 30, 100, 300)
ridge_path <- sapply(lambda_grid, ridge_beta)       # rows: variables, columns: lambda
colnames(ridge_path) <- lambda_grid

data.frame(lambda = lambda_grid, t(ridge_path), check.names = FALSE) |>
  brand_table("Ridge coefficients on the standardised scale", 4)
Ridge coefficients on the standardised scale
lambda FDI_GDP logGDP logGDP2 IND_VA_GDP NODA_RCV Trade_GDP
0 0.6371 38.1487 -47.4540 0.7053 -0.1879 3.1457
1 1.5814 -4.4251 -4.9227 1.0259 -0.4326 2.2693
5 1.2305 -3.9333 -4.0672 0.3739 -0.5490 1.9801
10 0.9406 -3.4081 -3.4872 0.0071 -0.6727 1.6381
30 0.4105 -2.3279 -2.3606 -0.4306 -0.7645 0.8982
100 0.0478 -1.2076 -1.2182 -0.4543 -0.5294 0.2794
300 -0.0248 -0.5321 -0.5356 -0.2534 -0.2546 0.0681
Code
path_long <- data.frame(lambda = lambda_grid, t(ridge_path), check.names = FALSE) |>
  tidyr::pivot_longer(-lambda, names_to = "Variable", values_to = "Coefficient")

ggplot(path_long, aes(lambda, Coefficient, colour = Variable, shape = Variable)) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = "dashed") +
  geom_line(linewidth = 0.9) +
  geom_point(size = 2.4) +
  scale_x_continuous(trans = scales::pseudo_log_trans(base = 10), breaks = lambda_grid) +
  scale_colour_manual(values = brand_cols) +
  labs(title = "Ridge regression: coefficient paths", x = expression(lambda),
       y = "Standardised coefficient", colour = NULL, shape = NULL) +
  theme_brand()

Ridge coefficient paths (standardised regressors). The horizontal axis is on a pseudo-log scale.
Code
b_logGDP_0  <- ridge_path["logGDP",  "0"];  b_logGDP_30  <- ridge_path["logGDP",  "30"]
b_logGDP2_0 <- ridge_path["logGDP2", "0"];  b_logGDP2_30 <- ridge_path["logGDP2", "30"]
NoteInterpretation

At \(\lambda=0\) (OLS) the two GDP terms have large coefficients of 38.15 and -47.45. If these have opposite signs, they are cancelling each other, which is a typical collinearity pattern. At \(\lambda=30\) they shrink to -2.33 and -2.36. The more collinear a group of regressors, the faster ridge shrinks their coefficients, while well-identified regressors move much less.

9.1 Choosing \(\lambda\) by leave-one-out cross-validation

Ridge is a linear smoother, so the leave-one-out residual has a closed form, \(e_i/(1-h_{ii})\), where \(h_{ii}\) is the leverage from the ridge hat matrix.

Code
loo_rmse <- function(lambda) {
  A <- solve(crossprod(Xs) + lambda * diag(ncol(Xs)))
  H <- Xs %*% A %*% t(Xs)
  e <- as.numeric(yc - H %*% yc)
  h <- diag(H) + 1 / n8                # + leverage of the (unpenalised) intercept
  sqrt(mean((e / (1 - h))^2))
}

lambda_cv <- c(0, 0.5, 1, 2, 5, 10, 20, 30, 50, 100, 200, 300)
cv_table <- data.frame(lambda = lambda_cv, `LOO-CV RMSE` = sapply(lambda_cv, loo_rmse),
                       check.names = FALSE)
brand_table(cv_table, "Leave-one-out cross-validated RMSE (percentage points)", 4)
Leave-one-out cross-validated RMSE (percentage points)
lambda LOO-CV RMSE
0.0 3.3371
0.5 3.4043
1.0 3.3775
2.0 3.3601
5.0 3.4748
10.0 3.8466
20.0 4.5561
30.0 5.0894
50.0 5.8142
100.0 6.7719
200.0 7.5711
300.0 7.9326
Code
pos <- cv_table$lambda > 0
lambda_demo <- cv_table$lambda[pos][which.min(cv_table$`LOO-CV RMSE`[pos])]
rmse_ols   <- cv_table$`LOO-CV RMSE`[cv_table$lambda == 0]
rmse_ridge <- min(cv_table$`LOO-CV RMSE`[pos])
Code
beta_std  <- ridge_beta(lambda_demo)
beta_orig <- beta_std / x_sd
beta0     <- mean(y8) - sum(beta_orig * x_mean)
beta_ridge <- c("(Intercept)" = beta0, beta_orig)

data.frame(
  Variable = names(coef(m_poly)),
  OLS = as.numeric(coef(m_poly)),
  Ridge = as.numeric(beta_ridge[names(coef(m_poly))])
) |>
  mutate(`Ridge / OLS` = Ridge / OLS) |>
  brand_table(paste0("OLS and ridge (lambda = ", lambda_demo,
                     ") in original units"), 4)
OLS and ridge (lambda = 2) in original units
Variable OLS Ridge Ridge / OLS
(Intercept) -176.3403 171.3906 -0.9719
FDI_GDP 0.4204 0.9767 2.3230
logGDP 170.2329 -19.3519 -0.1137
logGDP2 -28.5515 -2.7755 0.0972
IND_VA_GDP 0.1734 0.1965 1.1329
NODA_RCV -0.0806 -0.1940 2.4063
Trade_GDP 0.3854 0.2706 0.7021
Code
fit_ridge <- beta0 + as.numeric(Xmat %*% beta_orig)
r2_ridge  <- 1 - sum((y8 - fit_ridge)^2) / sum((y8 - mean(y8))^2)
r2_ols    <- summary(m_poly)$r.squared
NoteInterpretation

Cross-validation picks \(\lambda\) = 2 (among positive values on the grid). Its LOO-CV RMSE is 3.360 against 3.337 for OLS, so shrinkage does not help here. In-sample \(R^2\) falls only from 0.913 to 0.899, which is the price of the bias.

WarningLimits of this ridge demonstration
  • Ridge coefficients are biased, so the usual t-tests and standard errors do not apply to them.
  • Leave-one-out CV treats observations as exchangeable. For a trending annual series it is optimistic, and a rolling-origin evaluation would be more honest.
  • Ridge is mainly a prediction tool. It does not answer whether “FDI has an effect”.
  • For serious use, take \(\lambda\) from a package such as glmnet, with standardisation done inside each cross-validation fold.

10 Key results and decision guide

Code
data.frame(
  Check = c("Baseline: largest VIF", "Baseline: condition number κ",
            "Quadratic model: largest VIF", "After centring: largest VIF",
            "Joint test of the GDP terms (p-value)", "Is the square needed? (p-value)",
            "Best ridge λ and LOO-CV RMSE vs OLS"),
  Result = c(paste0(f3(max_vif_base, 2), " (", max_vif_base_var, ")"),
             f3(kappa_base, 2),
             paste0(f3(max_vif_poly, 1), " (", max_vif_poly_var, ")"),
             f3(max_vif_c, 2),
             fmt_p(p_joint), fmt_p(p_quad),
             paste0("λ = ", lambda_demo, ": ", f3(rmse_ridge, 3), " vs ", f3(rmse_ols, 3)))
) |> brand_table("Key results of this exercise")
Key results of this exercise
Check Result
Baseline: largest VIF 4.82 (IND_VA_GDP)
Baseline: condition number κ 4.60
Quadratic model: largest VIF 2606.3 (logGDP)
After centring: largest VIF 5.57
Joint test of the GDP terms (p-value) < 0.001
Is the square needed? (p-value) 0.118
Best ridge λ and LOO-CV RMSE vs OLS λ = 2: 3.360 vs 3.337
Remedy When to consider it Main risk
Drop a variable It is economically redundant and its contribution is not significant Omitted-variable bias if it was relevant
Log transform Theory or the data support a multiplicative or percentage relationship Changes the functional form; VIF need not fall
Centre a polynomial The collinearity comes from using \(x\) and \(x^2\) Only re-parametrises; adds no information
Ridge regression The goal is prediction and coefficients are unstable Biased; no standard t-tests; needs a chosen \(\lambda\)
More informative data The sample lacks independent variation More rows do not help if the new rows move together too
TipTake-home message

With fixed \(\mathbf X\) and \(E(\mathbf u)=0\), OLS is unbiased even under imperfect multicollinearity, but individual coefficients may be imprecise. In Sudan’s short annual series, the baseline regressors are not seriously collinear; the real problem appears only when the quadratic term is added. Treat the cure with care: a remedy must not create a worse problem (specification error).

11 Short tasks:

Code
data.frame(
  Task = c("1. Manual VIF from auxiliary regressions",
           "2. VIF before/after centring; why R² does not change",
           "3. Is the quadratic term needed? (F-test and why p is not enough)",
           "4. Change the ridge λ grid; why higher λ is not always better",
           "5. High multicollinearity versus specification error"),
  `Where answered` = c("Task 1 below", "Task 2 below", "Task 3 below", "Task 4 below", "Task 5 below"),
  Status = "Done", check.names = FALSE
) |> brand_table("Checklist of the short tasks")
Checklist of the short tasks
Task Where answered Status
1. Manual VIF from auxiliary regressions Task 1 below Done
2. VIF before/after centring; why R² does not change Task 2 below Done
3. Is the quadratic term needed? (F-test and why p is not enough) Task 3 below Done
4. Change the ridge λ grid; why higher λ is not always better Task 4 below Done
5. High multicollinearity versus specification error Task 5 below Done

11.1 Task 1: VIF by hand

For each baseline regressor we run the auxiliary regression on the remaining ones and compute \(VIF_j=1/(1-R_j^2)\).

Code
aux_r2 <- sapply(regressors, function(v) {
  f <- reformulate(setdiff(regressors, v), response = v)
  summary(lm(f, data = udaje8))$r.squared
})
vif_manual <- 1 / (1 - aux_r2)
vif_car    <- car::vif(m_base)[regressors]

data.frame(Variable = regressors, `Auxiliary R²` = aux_r2, `VIF (manual)` = vif_manual,
           `VIF (car::vif)` = as.numeric(vif_car), check.names = FALSE) |>
  brand_table("Manual VIF versus car::vif()", 4)
Manual VIF versus car::vif()
Variable Auxiliary R² VIF (manual) VIF (car::vif)
FDI_GDP 0.2356 1.3082 1.3082
GDP_billions 0.5204 2.0851 2.0851
IND_VA_GDP 0.7925 4.8204 4.8204
NODA_RCV 0.6109 2.5699 2.5699
Trade_GDP 0.6426 2.7983 2.7983
Code
max_diff_vif <- max(abs(vif_manual - vif_car))
NoteInterpretation

The largest difference between the manual and the car::vif() values is 1.3e-15, so they agree up to rounding error. The VIF is nothing more than a transformation of the auxiliary \(R^2\).

11.2 Task 2: Centring and the VIF

The before/after VIF table is in the centring section. The largest VIF changes from 2606.3 to 5.57, while \(R^2\) is 0.9132 in both versions.

NoteWhy VIF changes but the regression \(R^2\) does not

\(R^2\) describes the overall fit, which depends only on the space spanned by the regressors, and centring does not change that space. VIF describes the precision of one coefficient, which depends on how that coefficient is defined. After centring, \(z\) and \(z^2\) measure different things than \(\ln GDP\) and \((\ln GDP)^2\), so their auxiliary regressions differ.

11.3 Task 3: Keep the quadratic term?

The decision is in the section “Remedy I”. The partial F-test gives p = 0.118, so the quadratic term is not needed statistically.

NoteWhy the p-value alone is not enough
  1. With severe collinearity, individual p-values are unreliable because standard errors are inflated.
  2. Statistical significance says nothing about economic relevance or functional-form theory.
  3. With about 27 observations, tests have low power, and “not significant” is not “no effect”. The F-test should be read together with AIC/BIC, theory, and the diagnostics.

11.4 Task 4: Different ridge penalties

Code
lambda_alt <- c(0, 0.01, 0.1, 1, 10, 100, 1000, 10000)
data.frame(
  lambda = lambda_alt,
  `Sum of squared std. coefficients` = sapply(lambda_alt, function(l) sum(ridge_beta(l)^2)),
  `LOO-CV RMSE` = sapply(lambda_alt, loo_rmse),
  check.names = FALSE
) |> brand_table("Effect of a much wider λ grid", 4)
Effect of a much wider λ grid
lambda Sum of squared std. coefficients LOO-CV RMSE
0e+00 3718.0435 3.3371
1e-02 469.8358 3.3927
1e-01 66.1523 3.4316
1e+00 52.7042 3.3775
1e+01 27.7966 3.8466
1e+02 3.5093 6.7719
1e+03 0.0841 8.5715
1e+04 0.0010 8.8758
Code
rmse_huge <- loo_rmse(max(lambda_alt))
sd_y <- sd(y8)
NoteInterpretation

As \(\lambda\) grows, all coefficients are pushed toward zero. At \(\lambda=10{,}000\) the model approaches the constant mean, with LOO-CV RMSE 8.876 against 8.745 for the sample standard deviation of the dependent variable. A larger \(\lambda\) is not better: it reduces variance but increases bias, so the error is U-shaped in \(\lambda\) and the best value lies in between (the CV table above shows where).

11.5 Task 5: Two sentences

NoteHigh multicollinearity versus specification error

High multicollinearity means the regressors are nearly linearly dependent, so OLS remains unbiased but coefficients are estimated imprecisely (large standard errors). A specification error (an omitted relevant variable, a wrong functional form or endogeneity) makes the model itself wrong, so the estimates are biased however precise they look.

12 Save the results

We save only the objects needed later.

Code
save(udaje8, m_base, m_nogdp, m_log, m_poly, m_poly_c,
     vif_base, vif_poly, vif_poly_c, ridge_path, lambda_demo,
     file = "sudan_exercise8_results.RData")
cat("Saved to sudan_exercise8_results.RData")
Saved to sudan_exercise8_results.RData
TipFinal checklist