[R] studentized deleted residuals and NA's
John Miyamoto
jmiyamot at u.washington.edu
Mon Apr 5 21:24:50 CEST 2004
Dear R-Help,
I am using the studres function from the MASS package to compute
studentized deleted residuals in a oneway anova. I'm having trouble
interpreting the results in situations where a factor level has only one
observation. Sometimes studres yields an NaN and sometimes it produces a
numeric value for cases where a factor level has only one observation. I
would think it should always produce NaN for this case. The following
example illustrates this point.
library(MASS)
Data <- c(3,6,3,4,1,5,6,2)
Group <- factor(c(1,1,2,3,3,4,5,5))
lm.out <- lm(Data ~ Group)
data.frame(Data, Group,
hat=lm.influence(lm.out)$hat,
std.res=stdres(lm.out),
stu.del.res=studres(lm.out))
OUTPUT:
Data Group hat std.res stu.del.res
1 3 1 0.5 -8.9113279e-01 -8.4852814e-01
2 6 1 0.5 8.9113279e-01 8.4852814e-01
3 3 2 1.0 Inf NaN
4 4 3 0.5 8.9113279e-01 8.4852814e-01
5 1 3 0.5 -8.9113279e-01 -8.4852814e-01
6 5 4 1.0 -1.5208938e-08 -1.2418046e-08
7 6 5 0.5 1.1881771e+00 1.3333333e+00
8 2 5 0.5 -1.1881771e+00 -1.3333333e+00
Warning messages:
1: NaNs produced in: sqrt((n - p - sr^2)/(n - p - 1))
2: NaNs produced in: sqrt((n - p - sr^2)/(n - p - 1))
Groups 2 and 4 both have only one observation. Both the standardized
residual (std.res) and studentized deleted residual (stu.del.res) are NaN
for Group = 2 but both have a value for Group = 4. I would think that
std.res and stu.del.res should be NaN for Group 2 and for Group 4 because
1 - h_ii = 0 for the corresponding cases. Can someone tell me why the
std.res and stu.del.res are different for Group = 2 and Group = 4?
I am running R 1.8.1 on a Windows XP machine.
John
--------------------------------------------------------------------
John Miyamoto, Dept. of Psychology, Box 351525
University of Washington, Seattle, WA 98195-1525
Phone 206-543-0805, Fax 206-685-3157, Email jmiyamot at u.washington.edu
Homepage http://faculty.washington.edu/jmiyamot/
More information about the R-help
mailing list