lm.holdout: Linear Regression Holdouts

View source: R/holdout.R

lm.holdoutR Documentation

Linear Regression Holdouts

Description

Repeatedly remove the observation whose removal will move a model term most strongly to zero, until it is either no longer significant or has changed its sign.

Usage

lm.holdout(
  model,
  goal = c("nsig", "flip"),
  terms = NULL,
  alpha = 0.05,
  verbose = FALSE
)

## S3 method for class 'lm.holdout'
print(x, ...)

## S3 method for class 'lm.holdout'
plot(x, ...)

Arguments

model

A lm model.

goal

Objective of observation removal: "nsig" (no longer significant) or "flip" (change of sign).

terms

Names of model terms to compute holdout statistics for. When NULL, it defaults to all model terms.

alpha

Maximum p value for significance (only relevant when aiming to make value insignificant).

verbose

Should the function generate verbose output? Defaults to FALSE.

x

A lm.holdout object.

...

Additional plotting parameters for [base::plot()]; ignored for print.

Details

Datapoints to exclude are found with the function [stats::lm.influence()].

The plot function displays a scatterplot of each predictor with the dependent variable, with the excluded datapoints colored differently.

Value

A list, containing

  • holdouts: a data.frame where each row is a predictor; as for the columns:

  • h - the number of observations needed to reach the goal

  • h.prop - the percentage of excludable observations that were excluded to reach the goal

  • final.beta - the final beta value of the predictor after exclusions

  • final.p - the final p value of the predictor after exclusions

  • exclusion.matrix

  • model

Author(s)

Sercan Kahveci

Examples


Sigma <- diag(1,nrow=3)
Sigma[1,-1] <- Sigma[-1,1]<- -.5
fakedata <- MASS::mvrnorm(n=1000,mu=c(0,0,0),Sigma=Sigma,empirical=TRUE)
fakedata <- as.data.frame(fakedata)

lmmod <- lm(V1~V2*V3,data=fakedata)

lmmod.h <- lm.holdout(lmmod,goal="nsig")
print(lmmod.h)

lmmod.h2 <- lm.holdout(lmmod,goal="flip")
print(lmmod.h2)

plot(lmmod.h)


Spiritspeak/skMisc documentation built on April 12, 2025, 5:40 a.m.