# Remove specific observation id outlier from multiple regression

First I ran the outlier test with data as is:

 outlier <- lm(Y~. , data=train))


outlierTest:

outlierTest(outlier, cutoff=0.05, digits = 1)


Result is as follows

rstudent unadjusted p-value Bonferonni p
4904 4.792999         1.6909e-06    0.0084478
367  4.633191         3.6926e-06    0.0184480


So I tried to remove these variables from the regression model using below To set up selection of observation id I did the following:

X <- train
X$id <- row.names(train)  Then reran regression with subset no.outlier <- lm(Y~. , data=subset(train, X$id!=c(367,4904))

When I reran outlier test I got the following and am unsure why the observations are still there:

outlierTest(no.outlier, cutoff=0.05, digits = 1)


Results in one of the outliers still being there:

rstudent unadjusted p-value Bonferonni p
367 4.647852         3.4408e-06     0.017187


I've read through the following documentation, but it doesn't refer to how to extract the observation. In many of the examples I've found that the name of a variable rather than a numeral appears in the results. What am I doing incorrectly?

• X$id != c(367,4904) is your problem. If X$id equals 367, it still won't equal c(367, 4904). Try data = train[-c(367,4904),], which will work if train is a data frame. – jbowman Nov 28 '17 at 23:37
• Thanks @jbowman but I tried: no.outlier <- lm(Y~. , data = train[-c(367,4904),]) and got the same outcome using outlierTest – user637251 Nov 28 '17 at 23:51
• Running an outlier test after removing "outliers" usually identifies new outliers. These test are not designed to be applied recursively. – Roland Nov 29 '17 at 13:10
• Thanks, it's returning the same values. Is the observed returned value, ie 367 the same as a rowid when I do a subset? I'm thinking that somehow the rowid doesn't match the observation output in the outliertest perhaps? Or I'm doing something else wrong. If I've removed the outlier, why would it appear again? The observations are based on the lm, not on the underlying table, how can I make sure that it matches? Or is it something else? – user637251 Nov 30 '17 at 0:30
• I believe the test returns the row numbers. These are not necessarily the same as row names, in particular after subsetting. – Roland Nov 30 '17 at 9:18