Skip to contents

Computes the linear regression slope for a numeric response variable y.

Usage

slope(y, x = seq_along(y))

Arguments

y

A numeric vector of the response variable.

x

A numeric vector of the predictor variable, defaults to using the index of x = seq_along(y).

Value

A numeric slope value of y/x.

Details

Uses the least squares formula on complete case analysis. A single valid observation will return NA.

Examples

if (FALSE) { # \dontrun{
y <- c(1, 3, 2, 5, 8, 7, 9, 12, 11, 15, 14, 17, 18)
slope(y)

y <- c(1, 3, NA, 5, 8, 7, 9, 12, NA, NA, NA, 17, NA)
slope(y)
} # }