r - Error with lapply and robust regression - Cross Validated


first let me start off saying know consequences come removing/ignoring outliers.. particular case looking @ weekly trends in equipment collect data (a little on 100 sensors). need ignore "leverage points" ruin r sqd values. need see if of sensors trending out of normal operating limits on time using simple regressions.

rm(list=ls()) mtcars <- mtcars mylist <- lapply(mtcars, function(x) summary(lm(mtcars$wt ~ x))$r.squared) mylist  ## example, rsqd value .75 without outliers added data set  ##$mpg ##[1] 0.7528328 ##works great!   ##now add outliers  mtcars$mpg[c(5,10,15,20)] <- 100  ## without lmrob value mpg mylist$mpg [1] 0.001461735 ##using robust regression require(robustbase) summary(lmrob(mtcars$wt ~ mtcars$mpg))$r.squared  ##summary(lmrob(mtcars$wt ~ mtcars$mpg))$r.squared ## [1] 0.7187418 ##gives me representative r squared value data set , "leverage" ##points/extreme outliers don't ruin relationships trying see.  #but if try this...  mylist <- lapply(mtcars, function(x) summary(lmrob(mtcars$wt ~ x))$r.squared)  #it doesn't work , mean receive error #warning messages: #1: in lmrob.s(x, y, control = control, mf = mf) : # s-estimated scale == 0:  exact fit; check data #2: in seq_len(ar) : first element used of 'length.out' argument  #error in summary(lmrob(mtcars$wt ~ x)) :  # error in evaluating argument 'object' in selecting method     function 'summary': error in numeric(seq_len(ar)) : invalid 'length' argument  

i have tried removing data points in each column outside of +-3 sigma wasn't able working...

i persist in belief not meaningful exercise, method of allowing avoid error thrown when try regress wt on wt. error has nothing outliers, rather choice of functions, btw, need amend title.

mylist <- lapply( names(mtcars)[!grepl("wt", names(mtcars))],                    function(x) summary(lmrob(mtcars[['wt']] ~ mtcars[[x]]))$r.squared) mylist 

i thought warning "probably exact fit; check data" more helpful actual error message.


Comments