0

我有一组具有自变量 x 和 y 的数据。现在我正在尝试构建一个二维回归模型,该模型具有一个穿过我的数据点的回归曲面。但是,我找不到实现这一目标的方法。谁能给我一些帮助?

4

2 回答 2

1

您可以将我最喜欢的polyfitn用于线性或多项式模型。如果您想要不同的模型,请编辑您的问题或添加评论。!

编辑

另外,在多重回归下查看这里,可能也可以帮助您。

再次编辑

抱歉,我对此玩得太开心了,这是使用股票Matlab的最小二乘法进行多元回归的示例:

t = (1:10)';
x = t;
y = exp(-t);
A = [ y x ];
z = 10*y + 0.5*x;
A\z
ans =

   10.0000
    0.5000
于 2013-06-27T15:54:24.143 回答
0

如果您正在执行线性回归,最好的工具是regress函数。请注意,如果您要拟合形式的模型,y(x1,x2) = b1.f(x1) + b2.g(x2) + b3这仍然是线性回归,只要您知道函数fg

Nsamp = 100;  %number of samples
X1 = randn(Nsamp,1);  %regressor 1 (could also be some computed f(x1) )
X2 = randn(Nsamp,1);  %regressor 2 (could also be some computed g(x2) )
Y  = X1 + X2 + randn(Nsamp,1);  %generate some data to be regressed

%now run the regression
[b,bint,r,rint,stats] = regress(Y,[X1 X2 ones(Nsamp,1)]);

% 'b' contains the coefficients, b1,b2,b3 of the fit; can be used to plot regression surface)
% 'r' contains residuals of the fit
% 'stats' contains the overall regression R^2, F stat, p-value and error variance
于 2013-06-27T18:17:39.790 回答