multiple linear regression, n-by-n vector of observed responses

Hi everyone,
I’m new to MATLAB and I need some help.
I have a sample data set containing retunes of companies as well as two predictors variables collected along 5years. Now I need to run a multiple linear regression for the returns of each company. I am using b=regress(Y,X) but it works only with a vector Y (nx1). Having a matrix Y (nxn) (N companies x N time), how can I do it? Do I need a b=regress(Y,X) for every single vector Y or does it exist another way? Thank you very much for your help

回答 (2 件)

dpb
dpb 2014 年 4 月 9 日
編集済み: dpb 2014 年 4 月 9 日

0 投票

The loop over columns is one way, yes, but you can also do it in "one swell foop" using the "\" backslash operator mldivide for matrix left-divide.
For a set of underdetermined equations, it solves the least squares problem with good internal numerics. Set up your model as in regress excepting write it on an element-by-element basis (meaning use the dot operators) and then write
b=X\Y;
and you'll get a set of coefficients for each column in Y as each column of b.
For example, if your model were just a first order polynomial,
X=[x ones(size(x))];
b=X\Y
Shashank Prasanna
Shashank Prasanna 2014 年 4 月 9 日

0 投票

Floriano, it appears that you are trying to perform multivariate linear regression. There are several ways to specify this problem. You can use dpb's approach for X\y where X(nxm) y(nxd) for any n,m and d. However if you want full covariance matrix for y (not diagonal) you can use mvregress:

5 件のコメント

Star Strider
Star Strider 2014 年 4 月 10 日
Floriano has an objective function that returns a matrix output. To the best of my knowledge, the Statistics Toolbox fitting functions require a vector output. This is part of dpb and my frustrations with it.
Shashank Prasanna
Shashank Prasanna 2014 年 4 月 10 日
From Floriano's question it appears that there is a vector valued response variable for each observation OR a matrix of response values (Ynxn) for matrix of observations (Xnxm). This can be defined as a Multivariate regression problem: http://www.mathworks.com/help/stats/mvregress.html
It is not entirely clear the type of problem Floriano is trying to solve. With more information we can make the better recommendations. If this is a repeated measures study (which it could be based on the description) Floriano may employ fitrm:
Or a more general mixed-model:
Star Strider
Star Strider 2014 年 4 月 10 日
As dpb’s post demonstrates, Floriano may not have the fitlm, mvregress, or some of the other more recent functions. We don’t know.
Shashank Prasanna
Shashank Prasanna 2014 年 4 月 10 日
Floriano can confirm. Just to note, mvregress was added in R2006b:
dpb
dpb 2014 年 4 月 10 日
Presuming, of course, one had the right toolbox at the time...

サインインしてコメントする。

質問済み:

2014 年 4 月 9 日

コメント済み:

dpb
2014 年 4 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by