필터 지우기
필터 지우기

linear regession with 3 Independent variables

조회 수: 23 (최근 30일)
Isaac
Isaac 2013년 3월 4일
Hi guys,
I have only been using matlab for three weeks and will never look at an excel sheet in the same way.
However, i have been trying to do a multiple regression test and have tried:
y = data3(:,1); x = data3(:,2:3 ); p = polyfit(x,y,1)
which does not work and have also tried: [foo gof] = fit([x1, x2,x3], y, 'poly11')
Just short of going insane, i thought maybe some of you could lend your wisdom.
Truly grateful Isaac

답변 (2개)

Wayne King
Wayne King 2013년 3월 4일
편집: Wayne King 2013년 3월 4일
It looks like you are trying to construct a linear model with 2 predictor variables and 1 response variable. In the typical linear regression model you would try to fit a model of the form:
Y = beta0+beta1*X1+beta2*X2
Do you have the Statistics Toolbox installed?
If so use regress()
y = data3(:,1);
X = ones(length(y),3);
X(:,2:3) = data3(:,2:3);
[B,BINT,R,RINT,STATS] = regress(y,X);
The first column of the design matrix, X, is a vector of ones for fitting the constant term in the model.
If you do not have the Statistics Toolbox installed, you can obtain the least squares estimates with
beta = X\y;
The B vector (or beta) vector gives you the coefficients in the model
Y = B(1)+B(2)*X(:,2)+B(3)*X(:,3)

Shashank Prasanna
Shashank Prasanna 2013년 3월 4일
Issac, the simplest way is to use \ as Wayne mentioned:
>> [ones(length(x),1) x]\y
This will give you the three coefficients you want where the first column of ones is for the intercept terms.
There are numerous ways to do this in MATLAB.
If you want to use the curve fitting toolbox:
fit(x,y,'poly11')
You can see that the answers match. You can also use the statistics toolbox or the optimization toolbox to do the same.

카테고리

Help CenterFile Exchange에서 Gaussian Process Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by