Last active
February 27, 2017 12:20
-
-
Save smithdanielle/7c45fe0fcf29b43fa1f0 to your computer and use it in GitHub Desktop.
Outlier removal in R with MAD criterion: equations taken from [Leys et al (2013)](http://www.sciencedirect.com/science/article/pii/S0022103113000668).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(plyr) | |
require(dplyr) | |
data.outliersRemoved<-ddply(data, .(withinIV1, withinIV2), function(d){ | |
limits.outliers = median(d$DV) + 2.5*c(-1, 1)*mad(d$DV)) | |
d$DV[which(((d$DV - limits.outliers[1])*(limits.outliers[2] - d$DV)) <= 0)]<-NA | |
return(d) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment