필터 지우기
필터 지우기

How to use the regress function for more than 2 predictors?

조회 수: 2 (최근 30일)
Lucas Barboza
Lucas Barboza 2017년 8월 8일
댓글: Lucas Barboza 2017년 8월 8일
I need to make a multiple linear regression with 4 predictor, like x1, x2, x3 and x4. So, i discovered the function regress.
In the doc, there is the example bellow:
load carsmall
x1 = Weight;
x2 = Horsepower; % Contains NaN data
y = MPG;
X = [ones(size(x1)) x1 x2 x1.*x2];
b = regress(y,X) % Removes NaN data
But, in my case, i have x1, x2, x3 and x4. I don´t know how to use correct for this case, and i don't know how create the array X (showed in the doc of Matlab).

채택된 답변

the cyclist
the cyclist 2017년 8월 8일
Does this example using 3 variables help?
% Load the data
load carsmall
% Redefine names, to look more like your problem
% Explanatory variables
x1 = Weight;
x2 = Horsepower;
x3 = Displacement;
% Response variable
y = MPG;
% Put all the explanatory variables (including a constant term) into one matrix
X = [ones(size(x1)) x1 x2 x3];
% Estimate the parameters
b = regress(y,X);
  댓글 수: 1
Lucas Barboza
Lucas Barboza 2017년 8월 8일
Yes, thanks.
In my case, with 4 predictors, I need to use:
X = [ones(size(x1)) x1 x2 x3 x4]; .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by