One factor model calibration

5 ビュー (過去 30 日間)
Giacomo  Mureddu
Giacomo Mureddu 2018 年 6 月 30 日
回答済み: Max Wyse 2019 年 12 月 19 日
How can I add more common factors in a One factor model?
I have implemented the code from here (https://it.mathworks.com/help/risk/examples/one-factor-model-calibration.html) . I tried to modify the "fitlm" arguments in the for loop adding another time series for a second common factor:
for i = 1:4
lm = fitlm(commonfactor1,commonfactor2,dependentVar(:,i));
w_regress_std(i) = lm.Coefficients{'x1','x2','Estimate'};
end
I get this error.
"Error using classreg.regr.TermsRegression.createFormula (line 758) The model definition must be a formula character vector, a terms matrix, a model alias, or a LINEARFORMULA."
Thank you

回答 (1 件)

Max Wyse
Max Wyse 2019 年 12 月 19 日
Hi Giacomo,
It looks like you are trying to fit a linear regression model using two independent variables. I can adjust your for loop to make this work like so:
rng(1,'twister')
commonfactor1 = rand(200,1);
commonfactor2 = rand(200,1);
dependentVar = rand(200,4);
%this should work
for i=1:4
lm = fitlm([commonfactor1, commonfactor2],dependentVar(:,i));
Coeffs(i,:) = lm.Coefficients{{'x1','x2'},'Estimate'};
end
The changes I made to your code are as follows:
1.) I initialzed your variables (I don't have your data)
2.) I passed in all the dependent variables as a matrix, rather than each variable as a separate vector. This is the format expected by fitlm.
3.) I changed 'x1','x2' to {'x1','x2'}. The idea is that the first input in lm.Coefficients are the rows that are to be selected, the second input are the columns. As such, {'x1','x2'} both need to be given in the first input.
4.) I changed w_regress_std(i) to Coeffs(i,:). I did this for two reasons. The first is that you are now pulling out two coeffiecents instead of one, so I want the Coeffs output to be 2 dimensional. The second is that I am not sure what assumptions are going into the calculation of w_regress_std. All I have done is change this code to succesfully compute a multilinear regression, the mathematics in the example you link to may not hold in the 2 dimensional case (I haven't checked).

カテゴリ

Help Center および File ExchangeGaussian Process Regression についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by