我正在尝试使用fitlm命令执行多元线性回归。为此,我有以下向量: FuelPrice(1 * 688矢量) TotalFuelCap(1 * 688矢量) 需求(1 * 688矢量) 这些是独立变量 CO2EMis(1 * 688矢量) 这是因变量。
我编码如下:
for i = 1: rScenarioCnt
if rScenario{i}.status == 1
Demand(i)= sum(rScenario{i}.YearAlloc.LoadAlloc);
ECostMax(i) = rScenario{i}.ECostMax;
CO2EmisMax(i) = rScenario{i}.CO2EmisMax;
ECost(i) = rScenario{i}.YearAlloc.ECost;
CO2Emis(i) = rScenario{i}.YearAlloc.CO2Emis ;
EmisCostYear(i) = rScenario{i}.YearAlloc.EmisCostYear ;
CO2EmisYear(i) = sum(rScenario{i}.YearAlloc.CO2EmisYear);
FuelCode(i) = rScenario{i}.randFuelCode ;
TotFuelCapacity(i) = sum(rScenario{i}.Gen.byFuelCap{FuelCode(i)})
FuelPrices(i) = rScenario{i}.Fuel.prices(FuelCode(i));
else
i
disp('Not able to store in table');
end
end
dsa = dataset(FuelPrices',TotFuelCapacity',Demand',CO2Emis','VarNames',{'FuelPrices','TotFuelCapacity','Demand','CO2Emis'});
T = eye(21);
X = CO2Emis;
mdl = fitlm(X,dsa,T);
我收到以下错误:
Not able to store in table
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{:});