如何使用 lm() 检索 3D 拟合方程?

How do I retrieve the equation of a 3D fit using lm()?

假设我有以下代码来拟合双曲抛物线:

# attach(mtcars)    
hp_fit <- lm(mpg ~ poly(wt, disp, degree = 2), data = mtcars)

其中wt是x变量,disp是y变量,mpg是z变量。 (summary(hp_fit))$coefficients 输出如下:

   >(summary(hp_fit))$coefficients
                                     Estimate Std. Error    t value     Pr(>|t|)
    (Intercept)                     22.866173   3.389734  6.7457122 3.700396e-07
    poly(wt, disp, degree = 2)1.0  -13.620499   8.033068 -1.6955539 1.019151e-01
    poly(wt, disp, degree = 2)2.0   15.331818  17.210260  0.8908534 3.811778e-01
    poly(wt, disp, degree = 2)0.1   -9.865903   5.870741 -1.6805208 1.048332e-01
    poly(wt, disp, degree = 2)1.1 -100.022013 121.159039 -0.8255431 4.165742e-01
    poly(wt, disp, degree = 2)0.2   14.719928   9.874970  1.4906301 1.480918e-01

我不明白如何解释 (Intercept) 列下 poly() 右侧的不同数字。这些数字的意义是什么?我将如何根据该摘要构建双曲抛物面拟合方程?

比较时

with(mtcars, poly(wt, disp, degree=2))
with(mtcars, poly(wt, degree=2))
with(mtcars, poly(disp, degree=2))

1.02.0wt一二度,0.10.2指一二度disp1.1 是一个交互项。您可以通过比较来检查:

summary(lm(mpg ~ poly(wt, disp, degree=2, raw=T), data=mtcars))$coe
#                                         Estimate  Std. Error    t value     Pr(>|t|)
# (Intercept)                         4.692786e+01 7.008139762  6.6961935 4.188891e-07
# poly(wt, disp, degree=2, raw=T)1.0 -1.062827e+01 8.311169003 -1.2787937 2.122666e-01
# poly(wt, disp, degree=2, raw=T)2.0  2.079131e+00 2.333864211  0.8908534 3.811778e-01
# poly(wt, disp, degree=2, raw=T)0.1 -3.172401e-02 0.060528241 -0.5241191 6.046355e-01
# poly(wt, disp, degree=2, raw=T)1.1 -2.660633e-02 0.032228884 -0.8255431 4.165742e-01
# poly(wt, disp, degree=2, raw=T)0.2  2.019044e-04 0.000135449  1.4906301 1.480918e-01

summary(lm(mpg ~ wt*disp + I(wt^2) + I(disp^2) , data=mtcars))$coe[c(1:2, 4:3, 6:5), ]
#                  Estimate  Std. Error    t value     Pr(>|t|)
# (Intercept)  4.692786e+01 7.008139762  6.6961935 4.188891e-07
# wt          -1.062827e+01 8.311169003 -1.2787937 2.122666e-01
# I(wt^2)      2.079131e+00 2.333864211  0.8908534 3.811778e-01
# disp        -3.172401e-02 0.060528241 -0.5241191 6.046355e-01
# wt:disp     -2.660633e-02 0.032228884 -0.8255431 4.165742e-01
# I(disp^2)    2.019044e-04 0.000135449  1.4906301 1.480918e-01

这会产生相同的值。请注意,我使用 raw=TRUE 进行比较。