Non-linear regression

5 次查看(过去 30 天)
Keegan Carvalho
Keegan Carvalho 2018-10-8
重新打开: Walter Roberson 2018-12-22
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 个评论
Keegan Carvalho
Keegan Carvalho 2018-10-8
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 2018-10-8
Edited my comment. Sorry for the missing.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2018-10-8
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);

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by