Azzera filtri
Azzera filtri

Linear and quadratic trend surface formula get the same R

3 visualizzazioni (ultimi 30 giorni)
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 Commento
Mathieu NOE
Mathieu NOE il 10 Ott 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

Accedi per commentare.

Risposta accettata

SOUMNATH PAUL
SOUMNATH PAUL il 16 Nov 2023
Hi,
I also got the same results as @Mathieu NOE, without any change to your code.
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

Più risposte (0)

Categorie

Scopri di più su Quadratic Programming and Cone Programming in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by