Skip to content

really puzzled by this R script

2 messages · johnzli at comcast.net, R. Michael Weylandt

#
This isn't really a finance question...

Your problem is that you use names() instead of just getting the row
numbers from outlierTest but then, when you convert the names to an
integer, your attempts to remove the row by that number and so doesn't
actually get the right row, then an outlier remains and the infinite
loop is triggered.

To put it concretely, add a browser() at the top of the while loop and
note this:

x <- 1:20
y <- x; y[c(3, 14)] <- 1000*c(1, 1.05); y <- jitter(y);

dat <- data.frame(x = x, y = y)

rmOutlier(y ~ x, dat[-1,])


## Once in browser note this:
ret # should give "14" because the 14th spot is a problem by construction
fullData[ - ret, ] # Still has the outlier at "14" because it's not in
the 14th row!

If you just use the names and index appropriately, you should be fine.
Further help is more suited to R-help though as this isn't very
financial...just a heads up though: you'll also probably get told off
for mentioning outlier removal on R-help: it's something of a rite of
passage

Michael
On Sat, Feb 25, 2012 at 1:27 AM, <johnzli at comcast.net> wrote: