Learn R Programming

api2lm (version 0.2)

leverage_test: Identify leverage points

Description

leverage_test returns the observations identified as a leverage point based on a threshold.

Usage

leverage_test(model, n = stats::nobs(model), ttype = "half", threshold = NULL)

Value

A vector of statistics

Arguments

model

A fitted model object from the lm function.

n

The number of leverage points to return. The default is all leverage points.

ttype

Threshold type. The default is "half". The other options are "2mean" and "custom". See Details.

threshold

A number between 0 and 1. Any observation with a leverage value above this number is declared a leverage point. This is automatically determined unless ttype = "custom".

Details

If ttype = "half", the threshold is 0.5.

If ttype = "2mean", the threshold is \(2p/n\), where \(p = \)length(stats::coef(model)) and \(n = \)stats::nobs(model), which is double the mean leverage value.

If ttype = "custom" then the user must manually specify threshold.

See Also

Examples

Run this code
lmod <- lm(price ~ sqft_living, data = home_sales)
# comparison of results using different threshold types
leverage_test(lmod)
leverage_test(lmod, ttype = "2mean", n = 7)
leverage_test(lmod, ttype = "custom", threshold = 0.1)

Run the code above in your browser using DataLab