Learn R Programming

skedastic

The purpose of the skedastic package is to make a suite of old and new methods for detecting and correcting for heteroskedasticity in linear regression models accessible to R users.

Installation

# Install from CRAN
install.packages("skedastic", dependencies = c("Depends", "Imports"))

# Or the development version from GitHub:
install.packages("devtools")
devtools::install_github("tjfarrar/skedastic")

Usage

Heteroskedasticity (sometimes spelt 'heteroscedasticity') is a violation of one of the assumptions of the classical linear regression model (the Gauss-Markov Assumptions). This assumption, known as homoskedasticity, holds that the variance of the random error term remains constant across all observations. Under heteroskedasticity, the Ordinary Least Squares estimator is no longer the Best Linear Unbiased Estimator (BLUE) of the parameter vector, while the classical t-tests for testing significance of the parameters are invalid. Thus, heteroskedasticity-robust methods are required.

The most novel functionality of this package is provided by the alvm.fit and anlvm.fit functions, which fit an Auxiliary Linear Variance Model or an Auxiliary Nonlinear Variance Model, respectively. These are new models for estimating error variances in heteroskedastic linear regression models, developed as part of the author's doctoral research.

The hccme function computes heteroskedasticity-consistent covariance matrix estimates for the $\hat{\beta}$ Ordinary Least Squares estimator using ten different methods found in the literature.

25 distinct functions in the package implement hypothesis testing methods for detecting heteroskedasticity that have been previously published in academic literature. Other functions implement graphical methods for detecting heteroskedasticity or perform supporting tasks for the tests such as computing transformations of the Ordinary Least Squares (OLS) residuals that are useful in heteroskedasticity detection, or computing probabilities from the null distribution of a nonparametric test statistic. Certain functions have applications beyond the problem of heteroskedasticity in linear regression. These include pRQF, which computes cumulative probabilities from the distribution of a ratio of quadratic forms in normal random vectors, twosidedpval, which implements three different approaches for calculating two-sided $p$-values from asymmetric null distributions, and dDtrend and pdDtrend, which compute probabilities from Lehmann's nonparametric trend statistic.

Most of the exported functions in the package take a linear model as their primary argument (which can be passed as an lm object). Thus, to use this package a user must first be familiar with how to fit linear regression models using the lm function from package stats.

Here is an example of implementing the Breusch-Pagan Test for heteroskedasticity on a linear regression model fit to the cars dataset, with distance (cars$dist) as the response (dependent) variable and speed (cars$speed) as the explanatory (independent) variable.

library(skedastic)
mylm <- lm(dist ~ speed, data = cars)
breusch_pagan(mylm)

To compute BLUS residuals for the same model:

myblusres <- blus(mylm, omit = "last")
myblusres

To create customised residual plots for the same model:

hetplot(mylm, horzvar = c("explanatory", "log_explanatory"), vertvar = c("res", "res_stud"), vertfun = "2", filetype = NA)

To fit an auxiliary linear variance model to the same linear regression model, assuming that the error variances are a linear function of the speed predictor, and extract the resulting variance estimates:

myalvm <- alvm.fit(mylm, model = "linear")
myalvm$var.est

To fit an auxiliary linear variance model to the same linear regression model, assuming that the error variances are a quadratic function of the speed predictor, and extract the resulting variance estimates:

myanlvm <- anlvm.fit(mylm, g = function(x) x ^ 2)
mynalvm$var.est

Learn More

No vignettes have been created yet for this package. Watch this space.

Copy Link

Version

Install

install.packages('skedastic')

Monthly Downloads

1,998

Version

2.0.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Thomas Farrar

Last Published

January 8th, 2024

Functions in skedastic (2.0.2)

GSS

Golden Section Search for Minimising Univariate Function over a Closed Interval
alvm.fit

Auxiliary Linear Variance Model
carapeto_holt

Carapeto-Holt Test for Heteroskedasticity in a Linear Regression Model
bootlm

Nonparametric Bootstrapping of Heteroskedastic Linear Regression Models
diblasi_bowman

Diblasi and Bowman's Test for Heteroskedasticity in a Linear Regression Model
breusch_pagan

Breusch-Pagan Test for Heteroskedasticity in a Linear Regression Model
dDtrend

Probability mass function of nonparametric trend statistic \(D\)
dpeakdat

Probability distribution for number of peaks in a continuous, uncorrelated stochastic series
cook_weisberg

Cook-Weisberg Score Test for Heteroskedasticity in a Linear Regression Model
blus

Compute Best Linear Unbiased Scalar-Covariance (BLUS) residuals from a linear model
dpeak

Probability mass function of number of peaks in an i.i.d. random sequence
countpeaks

Count peaks in a data sequence
hetplot

Graphical Methods for Detecting Heteroskedasticity in a Linear Regression Model
godfrey_orme

Godfrey and Orme's Nonparametric Bootstrap Test for Heteroskedasticity in a Linear Regression Model
harvey

Harvey Test for Heteroskedasticity in a Linear Regression Model
honda

Honda's Test for Heteroskedasticity in a Linear Regression Model
glejser

Glejser Test for Heteroskedasticity in a Linear Regression Model
goldfeld_quandt

Goldfeld-Quandt Tests for Heteroskedasticity in a Linear Regression Model
harrison_mccabe

Harrison and McCabe's Test for Heteroskedasticity in a Linear Regression Model
hccme

Heteroskedasticity-Consistent Covariance Matrix Estimators for Linear Regression Models
dufour_etal

Dufour et al.'s Monte Carlo Test for Heteroskedasticity in a Linear Regression Model
szroeter

Szroeter's Test for Heteroskedasticity in a Linear Regression Model
simonoff_tsai

Simonoff-Tsai Tests for Heteroskedasticity in a Linear Regression Model
evans_king

Evans-King Tests for Heteroskedasticity in a Linear Regression Model
pDtrend

Cumulative distribution function of nonparametric trend statistic \(D\)
twosidedpval

Computation of Conditional Two-Sided \(p\)-Values
rackauskas_zuokas

Rackauskas-Zuokas Test for Heteroskedasticity in a Linear Regression Model
ppeak

Cumulative distribution function of number of peaks in an i.i.d. random sequence
pRQF

Probabilities for a Ratio of Quadratic Forms in a Normal Random Vector
wilcox_keselman

Wilcox and Keselman's Test for Heteroskedasticity in a Linear Regression Model
horn

Horn's Test for Heteroskedasticity in a Linear Regression Model
li_yao

Li-Yao ALRT and CVT Tests for Heteroskedasticity in a Linear Regression Model
white

White's Test for Heteroskedasticity in a Linear Regression Model
yuce

Yüce's Test for Heteroskedasticity in a Linear Regression Model
verbyla

Verbyla's Test for Heteroskedasticity in a Linear Regression Model
zhou_etal

Zhou, Song, and Thompson's Test for Heteroskedasticity in a Linear Regression Model
bamset

Ramsey's BAMSET Test for Heteroskedasticity in a Linear Regression Model
bickel

Bickel's Test for Heteroskedasticity in a Linear Regression Model
avm.fwls

Apply Feasible Weighted Least Squares to a Linear Regression Model
T_alpha

Pseudorandom numbers from Asymptotic Null Distribution of Test Statistic for Method of Rackauskas07;textualskedastic
avm.ci

Bootstrap Confidence Intervals for Linear Regression Error Variances
anlvm.fit

Auxiliary Nonlinear Variance Model
avm.vcov

Estimate Covariance Matrix of Ordinary Least Squares Estimators Using Error Variance Estimates from an Auxiliary Variance Model
anscombe

Anscombe's Test for Heteroskedasticity in a Linear Regression Model