Learn R Programming

dlnm (version 2.4.7)

poly: Generate a Basis Matrix of Polynomials

Description

The function generates a basis matrix of polynomial transformations. It is meant to be used internally by onebasis and crossbasis and not directly run by the users.

Usage

poly(x, degree=1, scale, intercept=FALSE)

Arguments

x

the predictor variable. Missing values are allowed.

degree

numerical scalar defining the degree of the polynomial.

scale

scaling factor. Default to the maximum of the absolute value of x.

intercept

logical. If TRUE, an intercept is included in the basis matrix. See Details below.

Value

A matrix object of class "poly". It contains the attributes degree, scale and intercept, with values which can be different than the arguments provided due to internal reset.

Details

The predictor vector is scaled by default through the argument scale to avoid numerical problem with powers of very high/low values.

If intercept=TRUE, an intercept is included in the model, namely an additional variable with a constant value of 1.

See Also

onebasis to generate basis matrices and crossbasis to generate cross-basis matrices.

See dlnm-package for an introduction to the package and for links to package vignettes providing more detailed information.

Examples

Run this code
# NOT RUN {
### simple use (accessing non-exported function through ':::')
dlnm:::poly(1:5, degree=3)
dlnm:::poly(1:5, degree=3, intercept=TRUE)

### use as an internal function in onebasis
b <- onebasis(chicagoNMMAPS$pm10, "poly", degree=3)
summary(b)
model <- glm(death ~ b, family=quasipoisson(), chicagoNMMAPS)
pred <- crosspred(b, model, at=0:60)
plot(pred, xlab="PM10", ylab="RR", main="RR for PM10")
# }

Run the code above in your browser using DataLab