我有一组具有自变量 x 和 y 的数据。现在我正在尝试构建一个二维回归模型,该模型具有一个穿过我的数据点的回归曲面。但是,我找不到实现这一目标的方法。谁能给我一些帮助?
问问题
3567 次
2 回答
0
如果您正在执行线性回归,最好的工具是regress
函数。请注意,如果您要拟合形式的模型,y(x1,x2) = b1.f(x1) + b2.g(x2) + b3
这仍然是线性回归,只要您知道函数f
和g
。
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 回答