Learn R Programming

iNZightRegression (version 1.3.5)

Poly: Polynomial Matrix

Description

A modified `poly()` function that allows for missing values.

Usage

Poly(x, degree = 1, coefs = NULL, raw = FALSE, ...)

Value

a matrix, with NAs in the missing rows

Arguments

x

variable to convert to matrix

degree

degree of polynomial

coefs

pass to poly() function

raw

pass to poly() function

...

more arguments for the poly() function

Author

Tom Elliott

Details

Credit goes to whoever posted this online first (google search if you must find it!)

Examples

Run this code
Poly(rnorm(100), degree = 2L)

# handles missing values:
iris.na <- iris
iris.na$Sepal.Length[c(5, 10)] <- NA
lm(Sepal.Width ~ Poly(Sepal.Length, 2L), data = iris.na)

# stats::poly() produces an error in this case:
# lm(Sepal.Width ~ poly(Sepal.Length, 2L), data = iris.na)

Run the code above in your browser using DataLab