首页 > 解决方案 > Matlab Stepwiselm:如何从最优回归规范中提取变量(即规范最小化 BIC)?

问题描述

我有一个数据集,包含大约 1800 个宏变量和大约 350 个观察值。该数据集构成矩阵 X,其方差可能预测美国国债收益率曲线的变化。为了获得简约性,我们使用 X 的前 10 个主成分来预测建模收益率曲线参数的变化(这种方法称为“扩散指数预测”)。但是,我们希望通过删除几乎没有边际解释力的变量来减小 X 的大小。我们通过使用不同的阈值来做到这一点。第一个阈值是基于每个单独变量在收益率曲线变化上的单独显着性(即删除每个 t-stat >1.65 的变量)。这种方法很简单,但忽略了联合意义。因此,我们还在 Matlab 中使用了具有不同标准的 stepwiselm 函数,包括最小化一些信息标准(例如BIC)和最大化R2adjusted。stepwiselm 函数搜索可能的模型规格,并根据某些标准选择最佳规格。

stepwiselm 函数的问题在于,从最优规范中提取变量似乎很困难。例如,假设 stepwiselm 选择 Yt = a + b1X1t + b2X10t + b3X23t 的规格。这意味着在 X 中的 1800 个变量中,使用 X1、X2 和 X23 可以最小化 BIC。然后我们希望提取 X1、X2 和 X23,以便我们可以创建一个新矩阵 X_reduced,其列由 X1、X2 和 X23 组成。然后我们找到 X_Reduced 的主成分,并使用最高阶(就方差而言)PC 来预测 Yt。在实际问题中,X_Reduced 将包含多于 3 个变量。

总结问题:如何从最优 stepwiselm 规范中提取和保存变量?

mdl_thresholding = stepwiselm(X, b1_change,...
    'Upper', 'linear', 'Criterion', 'BIC') %Run stepwiselm 
mdl_thresholding.ModelCriterion.BIC %Print the BIC
%Choose variables that minimizes BIC manually, be careful not to include
%the lags of beta1:
i = [8 9 12 15 21 22 24 26 27 28 29 30 33 35 36 38 39 46 49 ...
    58 60 64 65 71 77 78 84 85 87 88 90 91 94 97 98 99 100 ...
    101 102 103 104 106 107 111 117 122 126 127 139 140 ...
    147 153 160 167 183 196 199 202 204 214 216 226 227 ...
    228 236 239 240 243 246 251 255 257 259 264 267 268 ...
    280 281 282 283 288 289 292 295 296 298 302 304 306 ...
    308 310 313 315 316 318 319 321 323 324 325 327 328 ...
    329 332 335 336 337 338 362 372 373 376 378 390 399 ...
    413 414 415 430 445 450 454 459]; %Here I have manually saved the column numbers of the 
%variables chosen by stepwiselm. This is way too time consuming when X becomes larger. 
X_reduced = X(:,i); %Here I extract the chosen variables from X and save them in X_reduced. 
[coeff,score,latent] = pca(X_reduced) %We run PCA on X_reduced

标签: matlabforecasting

解决方案


所以我找到了一种实现所需输出的方法。通过运行 mdl_thresholding .Formula.InModel 我获得了一个指示变量,其中 stepwiselm 函数选择了哪些变量包含在最佳模型规范中。然后我使用这个指示变量从 X 中提取所需的列。

ind = mdl_thresholding.Formula.InModel; %This is an indicator of the variables used in the
%model.
X_reduced = X(:,ind); %Extract the variables from X and obtain X_reduced

推荐阅读