簡體   English   中英

MATLAB-如何基於x和y計算二維最小二乘回歸。 (回歸面)

[英]MATLAB - How to calculate 2D least squares regression based on both x and y. (regression surface)

我有一組具有獨立變量x和y的數據。 現在,我正在嘗試構建一個二維回歸模型,該模型的回歸點貫穿我的數據點。 但是,我找不到實現此目的的方法。 誰能給我些幫助?

您可以將我最喜歡的polyfitn用於線性或多項式模型。 如果您想要其他型號,請編輯您的問題或添加評論。 HTH!

編輯

另外,在“多元回歸”下查看此處 ,可能也可以為您提供幫助。

再次編輯

抱歉,我對此太感興趣了,這是一個使用最小二乘與股票 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

如果要執行線性回歸,最好的工具是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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM