Case statistics for regression analysis.
case.lm calculates the statistics.
plot.case plots the cases, one statistic per panel, and
illustrates and flags all observations for which the standard
thresholds are exceeded. plot.case returns an object with
class c("trellis.case", "trellis")
containing the plot and the row.names of the
flagged observations. The object is printed by a method which
displays the set of graphs and prints the list of flagged cases.
panel.case is a panel function for plot.case.
Usage
case(fit, ...)
## S3 method for class 'lm'
case(fit, lms = summary.lm(fit), lmi = lm.influence(fit), ...)
## S3 method for class 'case'
plot(x, fit,
which=c("stu.res","si","h","cook","dffits",
dimnames(x)[[2]][-(1:8)]), ##DFBETAS
between.in=list(y=4, x=9),
cex.threshold=1.2,
main.in=list(
paste(deparse(fit$call), collapse=""),
cex=main.cex),
sigma.in=summary.lm(fit)$sigma,
p.in=summary.lm(fit)$df[1]-1,
main.cex=NULL,
...)
panel.case(x, y, subscripts, rownames, group.names,
thresh, case.large,
nn, pp, ss, cex.threshold,
...)
Arguments
fit
"lm" object computed with x=TRUE
lms
summary.lm(fit)
lmi
lm.influence(fit)
x
In plot.case, the matrix output from case.lm
containing case diagnostics on each observation in the original
dataset.
In panel.case, the x variable to be plotted
which
In plot.case, the names of the columns of x
that are to be graphed.
between.in
between trellis/lattice argument.
cex.threshold
Multiplier for cex for the threshold values.
main.in
main title for xyplot. The default main title
displays the linear model formula from fit.
sigma.in
standard error for the fit.
p.in
The number of degrees of freedom associated with the fitted
model.
main.cex
cex for main title.
...
other arguments to xyplot
y
the y variable to be plotted.
thresh
Named list of lists. Each list contains the components
threshold ($y$-locations where a reference line will be drawn),
thresh.label (the right-axis labels for the reference lines), thresh.id
(the bounds defining "Noteworthy Observations").
case.large
Named list of "Noteworthy Observations".
nn
Number of rows in original dataset.
pp
The number of degrees of freedom associated with the fitted model.
ss
Standard error for the fit.
subscripts
trellis/lattice argument, position in the reshaped
dataset constructed by plot.case before calling xyplot.
rownames
row name in the original data.frame.
group.names
names of the individual statistics.
Details
lm.influence is part of S-Plus and R
case.lm and plot.case are based on:
Section 4.3.3 "Influence of Individual Obervations
in Chambers and Hastie", Statistical Models in S.
Value
case.lm returns a matrix, with one row for each observation
in the original dataset. The columns contain the diagnostic statistics:
e (residuals),
h* (hat diagonals),
si* (deleted standard deviation),
sta.res (standardized residuals),
stu.res* (Studentized deleted resididuals),
dffit (difference in fits, change in predicted y when
observation i is deleted),
dffits* (standardized difference in fits, standardized change
in predicted y when observation i is deleted),
cook* (Cook's distance),
and DFBETAs* (standardized difference in regression coefficients when
observation i is deleted, one for each column of the x-matrix,
including the intercept).
plot.case returns a c("trellis.case", "trellis") object
containing the plot
(including the starred columns by default) and also retains the
row.names of the flagged observations in the
$panel.args.common$case.large
component. The print method for the c("trellis.case",
"trellis")
object prints the graph and the list of flagged observations.
panel.case is a panel function for plot.case.
Author(s)
Richard M. Heiberger <rmh@temple.edu>
References
Heiberger, Richard M. and Holland, Burt (2004b).
Statistical Analysis and Data Display: An Intermediate Course
with Examples in S-Plus, R, and SAS.
Springer Texts in Statistics. Springer.
ISBN 0-387-40270-5.
See Also
lm.influence.
Examples
data(kidney)
kidney2.lm <- lm(clearance ~ concent + age + weight + concent*age,
data=kidney,
na.action=na.exclude) ## recommended
kidney2.case <- case(kidney2.lm)
## this picture looks much better in portrait, specification is device dependent
plot(kidney2.case, kidney2.lm, par.strip.text=list(cex=.9),
layout=c(2,3))
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(HH)
Loading required package: lattice
Loading required package: grid
Loading required package: latticeExtra
Loading required package: RColorBrewer
Loading required package: multcomp
Loading required package: mvtnorm
Loading required package: survival
Loading required package: TH.data
Loading required package: MASS
Attaching package: 'TH.data'
The following object is masked from 'package:MASS':
geyser
Loading required package: gridExtra
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/HH/lm.case.Rd_%03d_medium.png", width=480, height=480)
> ### Name: lm.case
> ### Title: case statistics for regression analysis
> ### Aliases: case case.lm plot.case panel.case
> ### Keywords: hplot regression
>
> ### ** Examples
>
> data(kidney)
>
> kidney2.lm <- lm(clearance ~ concent + age + weight + concent*age,
+ data=kidney,
+ na.action=na.exclude) ## recommended
>
> kidney2.case <- case(kidney2.lm)
>
> ## this picture looks much better in portrait, specification is device dependent
>
> plot(kidney2.case, kidney2.lm, par.strip.text=list(cex=.9),
+ layout=c(2,3))
Noteworthy Observations
Student del resid
deleted std dev 21 26
h 16
Cook's distance
dffits 20 21 26
DFBETAS (Intercept)
DFBETAS concent 26
DFBETAS age
DFBETAS weight 12 21
DFBETAS concent:age 26
>
>
>
>
>
> dev.off()
null device
1
>