Error while performing multiple linear regression using fitlm.

조회 수: 2 (최근 30일)
Aditi Bhalerao
Aditi Bhalerao 2017년 9월 21일
편집: Aditi Bhalerao 2017년 9월 26일
Hi, I am trying to perform multiple linear regression using fitlm command. For that, I have the following vectors: FuelPrice ( 1*10 vector) TotalFuelCap (1 * 10 vector) Demand (1 * 688 vector) These are the Independent variables CO2EMis ( 1 * 688 vector) This is the dependent variable.
I have coded as below:
dsa = dataset(CO2Emis ,demand, FuelPrices,TotalFuelCap','VarNames',{'CO2Emis','demand','FuelPrices','TotalFuelCap'});
T = [0 0 0 0;0 1 0 0;0 0 1 0;0 0 0 1];
X = [CO2Emis , ECost];
mdl = fitlm(X,dsa,T);
I am getting the error below: Error using dataset (line 329) All variables must have the same number of rows.
Can you please help me out.
  댓글 수: 2
Image Analyst
Image Analyst 2017년 9월 21일
It would help if you attached a mat file with your variables in it.
Aditi Bhalerao
Aditi Bhalerao 2017년 9월 26일
편집: Aditi Bhalerao 2017년 9월 26일
Hi, I have resolved the sizes of the vectors to be of equal length. I have also attached my code file. Can you please help me out. I want to perform multiple linear regression using fitlm but I am getting the error below:
Error using classreg.regr.TermsRegression.createFormula (line 728)
The terms matrix must have one column for each predictor variable, and the last column for the response variable.
Error in LinearModel.createFormula (line 1376)
formula = classreg.regr.TermsRegression.createFormula(supplied,modelDef, ...
Error in LinearModel.fit (line 1212)
model.Formula = LinearModel.createFormula(supplied,modelDef,X, ...
Error in fitlm (line 117)
model = LinearModel.fit(X,varargin{:});

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by