Linear regression : How to take into account the quadratic term only and not the linear term ?

조회 수: 4 (최근 30일)
Hello everyone,
I am currently working on a linear regression using the fitlm tool. I collect my datas from a table name "newT2" that has 3 columns.
Here is my code :
modelaction = 'Var1 ~ Var2 + Var3^2';
mdlaction = fitlm(newT2, modelaction);
The problem is that the regression is done according this equation : 'Var1 ~ Var2 + Var3+ Var3^2'. But it's not what I asked, I don't want the linear term Var3.
In fact, if I run with the equation 'Var1 ~ Var2 + Var3^3', the regression is done according : 'Var1 ~ Var2 + Var3+ Var3^2 + Var3^3' and so on.
Thanks for your help !
  댓글 수: 1
Torsten
Torsten 2022년 4월 22일
편집: Torsten 2022년 4월 22일
If nothing helps, square Var3 in newT2 and use a linear model:
modelaction = 'Var1 ~ Var2 + Var3_squared';

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2022년 4월 22일
Suppress the intercept term and the linear ‘Var3’ by negating them —
newT2 = array2table(rand(7,3)) % Create Data Table
newT2 = 7×3 table
Var1 Var2 Var3 _______ _______ ________ 0.9339 0.56678 0.7716 0.86767 0.18461 0.039493 0.95488 0.51097 0.95676 0.53864 0.8246 0.86486 0.23089 0.41095 0.76704 0.93338 0.12252 0.19638 0.91871 0.38145 0.6025
modelaction = 'Var1 ~ - 1 + Var2 - Var3 + Var3^2'; % Specify Model
mdlaction = fitlm(newT2, modelaction)
mdlaction =
Linear regression model: Var1 ~ Var2 + Var3^2 Estimated Coefficients: Estimate SE tStat pValue ________ ______ ________ _______ Var2 1.7668 1.4213 1.2431 0.26895 Var3^2 -0.38241 1.2132 -0.31521 0.76534 Number of observations: 7, Error degrees of freedom: 5 Root Mean Squared Error: 0.572
.

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by