Fitting nonlinear regression model

2 views (last 30 days)
Md. Golam Mostafa
Md. Golam Mostafa on 19 Aug 2015
Answered: Star Strider on 19 Aug 2015
I have 5 input variables organized in a table:
dt, sinday, cosday, sinhour, coshour
The dependent variable is Q (number of observations).
I wrote the following script:
tbl = table(dt,sinhour,coshour,sinday,cosday);
beta0 = [0;0;0;0;0;0];
modelfun = @(b,x) b(1) + b(2)*dt + b(3)*sinhour + b(4)*coshour + b(5)*sinday + b(6)*cosday;
md1 = fitnlm(tbl,Q,modelfun,beta0);
But it is giving the following error message while running:
Error using internal.stats.parseArgs (line 42)
Wrong number of arguments.
Error in NonLinearModel.fit (line 1379)
[coefNames,predictorVars,responseVar,weights, ...
Error in fitnlm (line 94)
model = NonLinearModel.fit(X,varargin{:});
Error in nlmfitoccu (line 57)
md1 = fitnlm(tbl,Q,modelfun,beta0);
I am not been able to sort it out.

Answers (1)

Star Strider
Star Strider on 19 Aug 2015
Two observations:
  1. ‘Q’ is not defined, and does not appear to be necessary in your argument list in any event;
  2. Your regression is actually linear, so you could use the regress or fitlm functions to get the parameters and statistics.

Community Treasure Hunt

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

Start Hunting!