R: polynomial short notation in the nls () formula

With the linear model function lm (), polynomial formulas can contain labels such as:

m <- lm(y ~ poly(x,3))

it is a shortcut that forces the user to create variables x ^ 2 and x ^ 3 or enter them into a type formula I(x^2) + I(x^3). Is there a comparable notation for a nonlinear function nls()?

+3
source share
2 answers

poly(x, 3)rather than just a shortcut to x + I(x ^ 2) + I(x ^ 3)- it actually produces legendary polynomials that have the good ability to be 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
+6
source

The short answer is yes.

: . example(nls), , poly().

: lm() poly(), , . , , nls() ... poly().

, : , Rells Harrell?

+5

Source: https://habr.com/ru/post/1763256/


All Articles