Filter löschen
Filter löschen

Error in non-linear regression

3 Ansichten (letzte 30 Tage)
Keegan Carvalho
Keegan Carvalho am 8 Okt. 2018
Kommentiert: Keegan Carvalho am 8 Okt. 2018
I am trying to prepare a non-linear reg model with the following variables in the following way: sea ~ sst + at
I am receiving an error when applying the beta) function and the fitnlm function. So far, this is what I've done:
t=readtable('ban1.csv')
sea=t(:,2)
sst=t(:,3)
at=t(:,4)
tbl=table(sea,sst,at)
modelfun = @(b,x)b(1) + b(2)*sst + b(3)*at;
When i try to apply the beta0:
beta0 = 10*rand(var,1);
I get the error:
Not enough input arguments.
Error in var (line 65) if isinteger(x)
And when i tried beta0 = [-50 500 -1 500 -1]; mdl = fitnlm(tbl,modelfun,beta0);
I get the following errors:
Error using classreg.regr.FitObject/selectVariables (line 289) Predictor variables must be numeric vectors or matrices.
Error in NonLinearModel/selectVariables (line 1157) model = selectVariables@classreg.regr.ParametricRegression(model);
Error in classreg.regr.FitObject/doFit (line 91) model = selectVariables(model);
Error in NonLinearModel.fit (line 1434) model = doFit(model);
Error in fitnlm (line 99) model = NonLinearModel.fit(X,varargin{:});
I would be grateful if someone could help me with this problem, preferably with the code. I have attached the csv file. Thanks!

Antworten (1)

Torsten
Torsten am 8 Okt. 2018
t = readtable('ban1.csv')
sea = t(:,2)
sst = t(:,3)
at = t(:,4)
A = [ones(numel(sea),1),sst,at];
rhs = sea;
b = A\rhs
give you the parameters you are looking for.
Best wishes
Torsten.
  1 Kommentar
Keegan Carvalho
Keegan Carvalho am 8 Okt. 2018
Thanks @Torsten. I still am getting some errors.
>> A = [ones(numel(sea),1),sst,at]; All input arguments must be tables.
>> rhs = sea; >> b = A\rhs Undefined function or variable 'A'.
Also, how do I know what the equation?
Please excuse my questions, as I am a beginner in this.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by