R:为什么这两个不同的结果(拟合曲线)来自两个不同的软件对于相同的点?
R: Why this two different results (fit curve) from two different software for the same points?
我有这个等式问题。我想绘制和拟合(多项式 2°)这个点数据框 df.1
:
df.1
x y
1902 0.01
1930 0.1
1950 0.5
1980 1
2014 1.8
代码是:
lm(df.1[,2] ~ poly(df.1[,1],2))
结果是:
Call:
lm(formula = df.1[, 2] ~ poly(df.1[, 1], 2))
Coefficients:
(Intercept) poly(df.1[, 1], 2)1 poly(df.1[, 1], 2)2
0.6620 1.4660 0.3339
方程图是:
ggplot(df.1, aes(x=x,y=y))+
geom_point(size = 4)+
geom_smooth(aes(y=df.1[,2],x=df.1[,1]),show.legend = T,linetype="dashed",method = "lm", formula = y ~ poly(x, 2), size = 0.4,se=T)+
stat_poly_eq(aes(label = paste(..eq.label..,..rr.label..,sep = "~")),formula =y ~ poly(x, 2),parse = TRUE)+
theme(panel.background = element_rect(fill = "white", colour = "grey50"))
现在,如果我使用其他软件,如 excel 或 STATISTICA 10,2° 拟合多项式曲线的系数结果为:
intercept 366.199
poly x 0.389864
poly x^2 0.000103743
y 中的值(如果我想找到所有拟合曲线的值)与 excel 方程是正确的,但问题是:为什么 R 拟合会导致不同的值(而且只有正数系数值)?
lm(df.1[,2] ~ poly(df.1[,1], 2, raw = T))
将 return 与 Excel.
中的值相同
poly {stats} raw if true, use raw and not orthogonal polynomials.
The orthogonal polynomial is summarized by the coefficients, which can
be used to evaluate it via the three-term recursion given in Kennedy &
Gentle (1980, pp. 343–4), and used in the predict part of the code.
我有这个等式问题。我想绘制和拟合(多项式 2°)这个点数据框 df.1
:
df.1
x y
1902 0.01
1930 0.1
1950 0.5
1980 1
2014 1.8
代码是:
lm(df.1[,2] ~ poly(df.1[,1],2))
结果是:
Call:
lm(formula = df.1[, 2] ~ poly(df.1[, 1], 2))
Coefficients:
(Intercept) poly(df.1[, 1], 2)1 poly(df.1[, 1], 2)2
0.6620 1.4660 0.3339
方程图是:
ggplot(df.1, aes(x=x,y=y))+
geom_point(size = 4)+
geom_smooth(aes(y=df.1[,2],x=df.1[,1]),show.legend = T,linetype="dashed",method = "lm", formula = y ~ poly(x, 2), size = 0.4,se=T)+
stat_poly_eq(aes(label = paste(..eq.label..,..rr.label..,sep = "~")),formula =y ~ poly(x, 2),parse = TRUE)+
theme(panel.background = element_rect(fill = "white", colour = "grey50"))
现在,如果我使用其他软件,如 excel 或 STATISTICA 10,2° 拟合多项式曲线的系数结果为:
intercept 366.199
poly x 0.389864
poly x^2 0.000103743
y 中的值(如果我想找到所有拟合曲线的值)与 excel 方程是正确的,但问题是:为什么 R 拟合会导致不同的值(而且只有正数系数值)?
lm(df.1[,2] ~ poly(df.1[,1], 2, raw = T))
将 return 与 Excel.
poly {stats} raw if true, use raw and not orthogonal polynomials.
The orthogonal polynomial is summarized by the coefficients, which can be used to evaluate it via the three-term recursion given in Kennedy & Gentle (1980, pp. 343–4), and used in the predict part of the code.