Learn R Programming

pense (version 1.2.9)

prinsens: Principal Sensitivity Components

Description

Compute the principal sensitivity components (PSC) for regression.

Usage

prinsens(
  x,
  y,
  method = c("ols", "en"),
  intercept = TRUE,
  alpha,
  lambda,
  en_options = en_options_aug_lars()
)

Arguments

x

data matrix with predictors

y

response vector

method

use ordinary least squares ("ols") or elastic net ("en") to compute the PSCs.

intercept

Should an intercept be added or not.

alpha, lambda

The values for the parameters controlling the penalization for elastic net.

en_options

additional options for the EN algorithm. See en_options for details.

Value

A numeric matrix with as many rows as x and as many columns as PSCs found (at most the number of columns in x plus one for the intercept). Each column is a PSC.

References

Pena, D., and Yohai, V.J. (1999). A Fast Procedure for Outlier Diagnostics in Large Regression Problems. Journal of the American Statistical Association, 94(446), 434-445. http://doi.org/10.2307/2670164

Examples

Run this code
# NOT RUN {
set.seed(12345)
n <- 50
n_out <- 6
p <- 500
beta <- c(2:5, numeric(p - 4))
x <- 1 + matrix(rnorm(n * p), ncol = p)
y <- x %*% beta  + rnorm(n)

# add outliers to y
y[seq_len(n_out)] <- rnorm(n_out, -100, 0.5)

# Compute Principal Sensitivity Components
pscs <- prinsens(
    x, y,
    alpha = 0.8,
    method = "en",
    lambda = 10
)

# The 6 outlying observations are reflected in the 15th PSC
colors <- rep.int(c(2, 1), times = c(n_out, n - n_out))
ord <- order(abs(pscs[, 15L]))
plot(abs(pscs[ord, 15L]), col = colors[ord], xlab = "Sorted Index",
     ylab = "Absolute PSC score")

# }

Run the code above in your browser using DataLab