Can't get fitnlm to work?
4 views (last 30 days)
Show older comments
I want to run a nonlinear regression on two variables, x_1 and y_1. Both are the same length (n=1461). My code looks like this:
tbl_1 = table(x_1,y_1);
modelfun_1 = 'y_1~b1*x_1^2 + b2*x_1 + b3';
beta0 = randn(3,1);
mdl_1 = fitnlm(tbl_1,modelfun_1,beta0);
I keep getting this error: "Error in fitnlm (line 99) model = NonLinearModel.fit(X,varargin{:});"
I have no idea what I'm doing wrong, can anyone help me? I am using matlab 2018b. Also, I don't know how to insert code into these questions.
2 Comments
Steven Lord
on 28 Sep 2018
That doesn't look like it's the full text of the error message. There should have been a piece before the "Error in fitnlm" part. Can you post everything printed in red text when you receive that error?
Answers (1)
Steven Lord
on 28 Sep 2018
"Input data, specified as a table or dataset array. If you do not specify the predictor and response variables, the last variable is the response variable and the others are the predictor variables by default."
Try adding the 'PredictorVars' and 'ResponseVar' parameters to your fitnlm call to explicitly state which variables you want to use as the predictors and which the response.
If that doesn't work, can you show a summary of your table tbl_1? That will clearly show the sizes and types of the variables in the table.
0 Comments
See Also
Categories
Find more on Linear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!