Linear and quadratic trend surface formula get the same R
Show older comments
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 Comment
Mathieu NOE
on 10 Oct 2023
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
Accepted Answer
More Answers (0)
Categories
Find more on Inertias and Loads in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!