Store parameters after looping MS_Regress_Fit

2 次查看(过去 30 天)
Hi, I have 25 portfolios and I use each of them in the MS_Regress_Fit package. After running each function, I need to store specific parameters. In the case of one portfolio the code is:
c = [lnavilliq milliq1];
idx = any(isnan(c),2);
new = c(~idx,:);
dep= new; % Defines the dependent variables in system
constVec=ones(length(dep),1);
indep{1}=constVec;
indep{2}=[constVec lnavilliq];
S{1}=[1 1];
S{2}=[1 1 1];
k=2; % Number of states/regimes
advOpt.distrib='Normal'; % The Distribution assumption
advOpt.std_method = 1; % Defining the method for calculation of standard errors.
advOpt.diagCovMat = 0; % Whether we will estimate by MLE also MS covariances (? feature)
advOpt.doPlots = 0; % Does not produce automatic plots (you are in charge of that!)
advOpt.printIter = 0; % When set to 0, does not print iterations to the screeen
[Spec_Out_1]=MS_Regress_Fit(dep,indep,k,S,advOpt);
c_high=Spec_Out_1.param(9);
c_low=Spec_Out_1.param(10);
beta2_high = Spec_Out_1.param(11);
beta2_low = Spec_Out_1.param(12);
beta2_p11=Spec_Out_1.Coeff.p(1);
beta2_p22=Spec_Out_1.Coeff.p(4);
While I'm able (at least I think I am) to loop over all the portfolios to get estimation results, I don't know how to extract in an array c_low, c_high, beta2_high, beta2_low, beta2_11, beta2_22. The code I use the following:
for k=1:length(milliq)
c = [lnavilliq milliq{1,k}];
idx = any(isnan(c),2);
new = c(~idx,:);
dep= new; % Defines the dependent variables in system
constVec=ones(length(dep),1);
indep{1}=constVec;
indep{2}=[constVec lnavilliq];
S{1}=[1 1];
S{2}=[1 1 1];
k=2; % Number of states/regimes
advOpt.distrib='Normal'; % The Distribution assumption
advOpt.std_method = 1; % Defining the method for calculation of standard errors.
advOpt.diagCovMat = 0; % Whether we will estimate by MLE also MS covariances (? feature)
advOpt.doPlots = 0; % Does not produce automatic plots (you are in charge of that!)
advOpt.printIter = 0; % When set to 0, does not print iterations to the screeen
[Spec_Out_{1,k}]=MS_Regress_Fit(dep,indep,k,S,advOpt);
c_high_{k}=Spec_Out_(k).param(9);
c_low_{k}=Spec_Out_(k).param(10);
beta2_high_{k} = Spec_Out_(k).param(11);
beta2_low_{k} = Spec_Out_(k).param(12);
beta2_p11_{k}=Spec_Out_(k).Coeff.p(1);
beta2_p2_{k}=Spec_Out_(k).Coeff.p(4);
end
Which gives me the error 'Dot indexing is not supported for variables of this type.' By dropping the last 6 lines of code, which exclude storing parameter, the estimation works fine.
Help please
Stefano
  5 个评论
Stefano Grillini
Stefano Grillini 2018-9-4
That's why I put the command lines:
idx = any(isnan(c),2);
new = c(~idx,:);
dep= new;
Therefore I was expecting that the loop adjusts the size of the matrix at every iteration, so that constVec changes based on dep.
dpb
dpb 2018-9-4
Well, clearly your expectations weren't realized... :)
All that is before the call to MS_Regress_Fit() which creates the output struct that you're trying to concatenate and that has mismatched dimensions.
Again, use the debugger and step through to see what actually is going on with the one data set that doesn't seem to match the others. There's nothing anybody here can tell you without the data.
If nothing else, use the command line and run two cases manually to see what is returned between the two.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by