Matlab Stepwiselm:如何从最佳回归规范中提取变量(即,规范最小化BIC)?

问题描述 投票:1回答:1

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

总结问题:如何从最佳逐步规范中提取并保存变量?

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
matlab forecasting
1个回答
0
投票

因此,我找到了一种实现所需输出的方法。通过运行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
© www.soinside.com 2019 - 2024. All rights reserved.