Add constants and time trends to multivariate regression Matlab
Ältere Kommentare anzeigen
Hi Matlab,
I'm want to add a constant for each indepedent variable and a time trend for each independent variable in a multivariate regression.
Any suggestions how to do this?
Follwing this link https://se.mathworks.com/help/stats/mvregress.html it says 'to add a constant to a model, should use a col of ones.' Clearly,
we cannot add more than one col of ones.
Code follows below:
A = rand(200,1);
B = rand(200,1);
vX = [A B];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%define independent and dependent variables
K1 = lagmatrix(diff(vX),1)
K3 = lagmatrix(vX,1)
K4 = diff(vX)
%make same size
K1(any(isnan(K1), 2), :) = [];
K3(any(isnan(K3), 2), :) = [];
K4(any(isnan(K4), 2), :) = [];
K3(1,:) = [];
K4(1,:) = [];
%one trend for each series
%one constant for each series
%constant
con = [ones(198,1) ]
%trend
trend = [(1:198)' ]
[beta,Sigma,E,CovB] = mvregress([con K3 K1 trend], K4, 'vartype', 'fisher');
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Gaussian Process Regression finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!