Created
September 28, 2016 12:53
-
-
Save guidocor/726291e786edce11d2cffb60184f3bfd to your computer and use it in GitHub Desktop.
Gets the IQR and 1.5 range of the distribution of each member or of class
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
iqr_1.5 <- function(df, rt, conds, FUN = function(x) { | |
c(iqr = IQR(x), | |
lower = quantile(x, c(0.25))-1.5*(quantile(x, c(0.75))-quantile(x, c(0.25))), | |
upper = quantile(x, c(0.75))+1.5*(quantile(x, c(0.75))-quantile(x, c(0.25)))) | |
}){ | |
# This function calculates the 1.5 * IQR of each participant and condition | |
# returns a dataframe with the columns formatted. | |
# Is used to detect outliers in reaction times at participant per condition level. | |
# Also, yo can use it with custom functions | |
require(doBy) | |
if(!require("doBy")){stop("The doBy package is needed")} | |
by_conds <- paste(conds, collapse = " + ") | |
formula_specificated <-as.formula(paste0( rt, "~", by_conds ) ) | |
new_df <- summaryBy( | |
formula = formula_specificated, | |
data = df, | |
FUN = FUN) | |
new_df<-merge(df, new_df, conds) | |
return(new_df) | |
} | |
convert_factor <- function(df, columns){ | |
df[,columns] <- lapply(df[,columns], as.factor) | |
return(df) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment