Exclude outliers from a data set
exclude_outliers.Rd
Excludes outliers from a data set using the "1.5 interquartile range" rule.
Usage
exclude_outliers(x, col_for_analysis, INDICES)
# S3 method for class 'data.frame'
exclude_outliers(x, col_for_analysis, INDICES)
# S3 method for class 'exdf'
exclude_outliers(x, col_for_analysis, INDICES)
Details
exclude_outliers
is generic, with methods defined for data frames and
exdf
objects. This function uses a simple rule to detect outliers,
where any point that deviates from the mean by more than 1.5 * IQR
,
where IQR
is the interquartile range, is said to be an outlier. This
method is also sometimes referred to as "Tukey's Fences," as seen in the
Wikipedia page about outliers.
For data sets with extreme outliers, it may be necessary to exclude outliers more than once to actually remove them all.
Examples
# Read a Licor file included with the PhotoGEA package; this file includes
# several light response curves that can be identified by the 'species' and
# 'plot' columns.
licor_file <- read_gasex_file(
PhotoGEA_example_file_path('ball_berry_1.xlsx')
)
# Exclude points from each response curve in the data where the leaf temperature
# is determined to be an outlier
licor_file_clean <- exclude_outliers(
licor_file,
'TleafCnd',
list(licor_file[, 'species'], licor_file[, 'plot'])
)
# Check to see how many points remain after removing outliers
str(list('original' = nrow(licor_file), 'clean' = nrow(licor_file_clean)))
#> List of 2
#> $ original: int 28
#> $ clean : int 24