Linear and quadratic trend surface formula get the same R
2 次查看(过去 30 天)
显示 更早的评论
I want to analyze the relation of location and the population of a city. When I try linear and quadratic trend surface model, it strikes me that the two model has the same R^2:0.4590. Why does this happen .Data are in the attachment
My program is here:
% read data
fid = readtable('trend_surface.xlsx'); % 题目中的表1
POP = table2array(fid(1:50,2)); % 人口
x = table2array(fid(1:50,3)); % x坐标
y = table2array(fid(1:50,4)); % y坐标
% draw 3-D scatter
scatter3(x,y,POP,"blue",'+');
% Linear trend surface
X = [ones(50,1) x y]; % coeffecient matrix
Z = POP; % solution matrix
A = (X'*Z)\(X'*X); % result
% examine the model
SS_D = sum((A(1)+A(2).*x+A(3).*y-Z).^2);
SS_R = sum((A(1)+A(2).*x+A(3).*y-mean(Z)).^2);
SS_T = SS_D+SS_R;
R_2 = SS_R/SS_T; % R_2 = 0.4590
F = (SS_R/2)/(SS_D/47); % F = 19.9399
% Quadratic trend surface
X_1 = [ones(50,1) x y x.*x x.*y y.*y]; % coeffecient matrix
Z_1 = POP; % solution matrix
A_1 = (X_1'*Z)\(X_1'*X_1); % result
% examine the model
SS_D1 = sum((A_1(1)+A_1(2).*x+A_1(3).*y+A_1(4).*x.*x+A_1(5).*x.*y+A_1(6)*y.*y-Z_1).^2);
SS_R1 = sum((A_1(1)+A_1(2).*x+A_1(3).*y+A_1(4)*x.*x+A_1(5)*x.*y+A_1(6)*y.*y-mean(Z_1)).^2);
SS_T1 = SS_D1+SS_R1;
R_2_1 = SS_R1/SS_T1; % R_2_1=0.4590
F_1 = (SS_R1/5)/(SS_D1/44); % F_1=7.4668
1 个评论
Mathieu NOE
2023-10-10
hello
without any change to your code , I get following results :
R_2 = 0.4486
F = 19.1212
R_2_1 = 0.5000
F_1 = 8.8000
采纳的回答
SOUMNATH PAUL
2023-11-16
Hi,
R_2 = 0.4486
R_2_1 = 0.5000
But, it is fairly possible to encounter a situation where both linear and quadratic trend surface models yield the same result.
Here are some situations where the results can be same:
1) The dataset you are working with may have characteristics that make it equally well-suited for both linear and quadratic models.
2) With a limited sample size, the ability to detect differences in model performance may be constrained. A larger dataset might reveal distinctions between the linear and quadratic models.
3) The underlying relationship between location and population might genuinely be adequately described by a linear model. Adding quadratic terms could be unnecessary complexity if it does not significantly improve the model fit.
Hope it helps!
Regards,
Soumnath
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Quadratic Programming and Cone Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!