Learn R Programming

softwareRisk (version 0.1.0)

slope_fun: Compute the linear slope of a numeric sequence

Description

Computes the slope of a simple linear regression of a numeric vector against its index (seq_along(x)). Non-finite (NA, NaN, Inf) values are removed prior to computation. If fewer than two finite values remain, the function returns 0.

Usage

slope_fun(x)

Value

A numeric scalar giving the slope of the fitted linear trend.

Arguments

x

Numeric vector.

Details

The slope is estimated from the model \(x_i = \beta_0 + \beta_1 i + \varepsilon_i\), where \(i = 1, \dots, n\). The function returns the estimated slope \(\beta_1\).

This summary is useful for characterizing monotonic trends in ordered risk values along a path.

Examples

Run this code
slope_fun(c(1, 2, 3, 4))
slope_fun(c(4, 3, 2, 1))
slope_fun(c(NA, 1, 2, Inf, 3))

Run the code above in your browser using DataLab