How can I compute regression coefficients for three or more predictor variables?

3 views (last 30 days)
How can I obtain the coefficients (b) of multiple linear regression between mean free joint angles (ankle, hip, knee angles time-normalised to 101 data points) as predictor variables (X = x1, x2, x3) and changes in the mean-free foot COM as an outcome variable (y)

Accepted Answer

Star Strider
Star Strider on 28 Aug 2012
Edited: Star Strider on 28 Aug 2012
Assuming your expression is:
y = X * B
where B is the parameter vector, the easiest way to calculate B is:
B = X\y;
Also see regress, since it provides statistics on the fit and confidence intervals on the estimated parameters.
  6 Comments
Tim  Bennett
Tim Bennett on 6 Sep 2012
Thanks for getting back to me. I just need a bit of help breaking this down.
(1) I have a [20 x 3] matrix of predictor variable data (X) (i.e. column 1 = mean free hip angles, column 2 = mean free knee angles etc) and a [20 x 2] of outcome variable data (Y) (i.e. column 1 = mean free foot centre of mass in the x-axis and column 2 = mean free foot centre of mass in the y-axis). Therefore, do I need to calculate Y when the data is available or still use the equation Y = [X*B(:,1) X*B(:,2)];? I'm just trying to understand how the Y and X variables are linked together using this code to produce the estimated coefficients?
(2) Where you have 'B = [[1; 3; 5] [2; 4; 6]];' would the equation B = X\Y'; not automatically give the coefficient estimates (B)in a [2 x 3 ] matrix?
(3) Do I still need to calculate X using the following equation:
X = [ones(length(x1),1) x1' x2' x3'];
I'm trying to compare the multiple linear regression coefficients with the output from a geometric model that linked the hip to the foot centre of mass giving the following values in a [2 x 3] matrix:
-0.1008, 0.1717, -0.0103
-0.7806, -0.4124 , -0.0788
where the first and second rows consisted of partial derivatives of the hip, knee, and ankle in relation to the X and Y positions of the COM of the foot respectively.
Star Strider
Star Strider on 6 Sep 2012
Edited: Star Strider on 6 Sep 2012
As I mentioned in my response in your other thread —
1. I created my example code as an illustration that you could indeed have two dependent variables and regress them against your independent variables. You do not have to calculate Y if you have already defined it with your data as your matrix of dependent variables.
2. It should give you your coefficients in a [4 x 2] matrix as I have it coded here.
3. Yes.
Multiple linear regression is appropriate if your model assumes a linear relationship between the independent and dependent variables. If that assumption is not valid, you will likely have to use a nonlinear regression model.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!