[R] remove outlier

Methekar, Pushpa (GE Transportation, Non-GE) pushpa.methekar at ge.com
Fri Jan 2 13:58:19 CET 2015


Hi ,
I am working on a function .

rm.outliers = function(dataset,model){
     dataset$predicted = predict(model)
    dataset$stdres = rstudent(model)
     m = 1
     for(i in 1:length(dataset$stdres)){
       dataset$outlier_counter[i] = if(dataset$stdres[i] >= 3 |
                                             dataset$stdres[i] <= -3) {m}
                                     else{0}
      }
   j = length(which(dataset$outlier_counter >= 1))
    while(j>=1){
       print(dataset[which(dataset$outlier_counter >= 1),])
        dataset = dataset[which(dataset$outlier_counter == 0),]
        dataset$predicted = predict(model)
      dataset$stdres = rstudent(model)
          m = m+1
          for(k in 1:length(dataset$stdres)){
              dataset$outlier_counter[k] = if(dataset$stdres[k] >= 3 |
                                                    dataset$stdres[k] <= -3) {m} else{0}
           }
       j = length(which(dataset$outlier_counter >= 1))
     }
   return(dataset)
  }
When I pass
rm.outliers(xsys,fitted.modely1.temp.l)
fitted.modely1 .temp.l  is mylinear model.
It shows me error like

Error in `$<-.data.frame`(`*tmp*`, "predicted", value = c(0.306726561735386,  :

  replacement has 731 rows, data has 717

Called from: `$<-`(`*tmp*`, "predicted", value = c(0.306726561735386, 0.306726561)



Help me out


Xsys data has 331 rows and 18 column

	[[alternative HTML version deleted]]



More information about the R-help mailing list