Non-linear regression

5 views (last 30 days)
Keegan Carvalho
Keegan Carvalho on 8 Oct 2018
Reopened: Walter Roberson on 22 Dec 2018
I have come across the documentations for regression but am a little confused. I wanted to obtain a non-linear regression model using the following: 'sea', 'sst' and 'at'. (See files attached). I wanted to check how sst and at affect sea levels. (something similar like: 'sea' = 'sst' + 'at')
I came across this sample code:
load carbig
tbl = table(Horsepower,Weight,MPG);
modelfun = @(b,x)b(1) + b(2)*x(:,1).^b(3) + ...
b(4)*x(:,2).^b(5);
beta0 = [-50 500 -1 500 -1];
mdl = fitnlm(tbl,modelfun,beta0)
However, when I tried it on my data, I got a bad result. I would be grateful if someone could help me obtain the non-lin reg model for my data. If possible, could you send me the code too.
Thanks!
  5 Comments
Keegan Carvalho
Keegan Carvalho on 8 Oct 2018
The link is not available. The number of variables is 3 so I used the code:
beta0 = [100 100 100];
But i still get an error:
Error using internal.stats.parseArgs (line 42) Wrong number of arguments.
Error in NonLinearModel.fit (line 1385) internal.stats.parseArgs(paramNames, paramDflts, otherArgs{:});
Error in fitnlm (line 99) model = NonLinearModel.fit(X,varargin{:});
Kevin Chng
Kevin Chng on 8 Oct 2018
Edited my comment. Sorry for the missing.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 8 Oct 2018
I think you're being overly optimistic if you think that data can be modeled -- predicted by some analytical function.
data = readtable('ban1.csv')
years = data.year;
sea = data.sea;
sst = data.sst;
at = data.at;
subplot(2, 2, 1);
plot(years, sea, 'b-', 'LineWidth', 2);
grid on;
title('sea vs. year', 'FontSize', 20);
xlabel('Year', 'FontSize', 20);
ylabel('sea', 'FontSize', 20);
subplot(2, 2, 2);
plot(years, sst, 'b-', 'LineWidth', 2);
xlabel('Year', 'FontSize', 20);
grid on;
hold on;
plot(years, at, 'r-', 'LineWidth', 2);
grid on;
title('sst and at vs. year', 'FontSize', 20);
legend('sst', 'at', 'location', 'west');
subplot(2, 2, 3)
scatter(sst, sea, 'filled');
grid on;
title('sea vs. sst', 'FontSize', 20);
xlabel('sea', 'FontSize', 20);
ylabel('sst', 'FontSize', 20);
subplot(2, 2, 4)
scatter(sst, at, 'filled');
grid on;
title('at vs. sst', 'FontSize', 20);
xlabel('sea', 'FontSize', 20);
ylabel('at', 'FontSize', 20);

Categories

Find more on Linear and Nonlinear 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!