Store parameters after looping MS_Regress_Fit

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 commentaires

dpb
dpb le 3 Sep 2018
Would need to have a copy of the actual struct to poke around at it to see; while written for Matlab, this isn't a TMW product so there isn't any specific documentation; read the MS_Regress_Package help and then the Matlab reference on how to dereference struct objects to figure out just how stuff is stored and the syntax to get to it...
Thanks for your reply. I also thought of achieving what I aim in two steps: first loop and get a cell array with all stored information of struct for the Spec_out estimates. Then run a second loop to extract the parameters of interest. It works until the fifth estimation, however, at the sixth I get the error message: 'Error using horzcat Dimensions of arrays being concatenated are not consistent' with reference to indep{2}.
Not sure how to solve it
dpb
dpb le 3 Sep 2018
Well, that's pretty self-evident from the error message--you're trying to paste something on to the end of an existing array that isn't the same size in the vertical dimension as the preceding ones.
Use the debugger and set a breakpoint to see just what each iteration returns for the structure fields of interest; clearly the sixth iteration returns something different than the preceding five for that particular parameter and that particular data set.
We've no way to have any klew just what that difference might be...
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 le 4 Sep 2018
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

Commenté :

dpb
le 4 Sep 2018

Community Treasure Hunt

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

Start Hunting!

Translated by