R:nls()公式中的多项式快捷方式表示法 [英] R: polynomial shortcut notation in nls() formula
本文介绍了R:nls()公式中的多项式快捷方式表示法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用线性模型函数lm(),多项式公式可以包含这样的快捷表示法:
With the linear model function lm() polynomial formulas can contain a shortcut notation like this:
m <- lm(y ~ poly(x,3))
这是一种快捷方式,使用户不必创建x ^ 2和x ^ 3变量或在类似于I(x^2) + I(x^3)
的公式中键入它们.非线性函数nls()
有可比较的符号吗?
this is a shortcut that keeps the user from having to create x^2 and x^3 variables or typing them in the formula like I(x^2) + I(x^3)
. Is there comparable notation for the nonlinear function nls()
?
推荐答案
poly(x, 3)
不仅仅是x + I(x ^ 2) + I(x ^ 3)
的快捷方式-它实际上产生了
poly(x, 3)
is rather more than just a shortcut for x + I(x ^ 2) + I(x ^ 3)
- it actually produces legendre polynomials which have the nice property of being uncorrelated:
options(digits = 2)
x <- runif(100)
var(cbind(x, x ^ 2, x ^ 3))
# x
# x 0.074 0.073 0.064
# 0.073 0.077 0.071
# 0.064 0.071 0.067
zapsmall(var(poly(x, 3)))
# 1 2 3
# 1 0.01 0.00 0.00
# 2 0.00 0.01 0.00
# 3 0.00 0.00 0.01
这篇关于R:nls()公式中的多项式快捷方式表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文