flag.by.group: Identify Extreme Values Based on Group Means and Standard...

View source: R/flag.by.group.R

flag.by.groupR Documentation

Identify Extreme Values Based on Group Means and Standard Deviations

Description

Identifies, within subsets defined by the combination one or more grouping variables, which elements of x are a certain number of standard deviations from the mean of that group (e.g., values more than 3 standard deviations from the mean). For example, identify GRE scores more than 3 standard deviations from the mean within each university (rather than the overall mean), or identify response times more than 2.5 standard deviations from the mean within a particular subject x condition cell in an experimental design.

Usage

flag.by.group(x, INDEX, sds = 3, print = TRUE, na.rm = FALSE)

Arguments

x

a numeric vector.

INDEX

list of one or more grouping variables, typically factors, each of the same length as x.

sds

number of standard deviations away from the mean at which "extreme" values should be identified.

print

a logical value indicating whether to display the number and percentage of identified elements.

na.rm

a logical value indicating whether NA values should be ignored when computing the mean and standard deviation.

Value

logical vector indicating whether each element of x is more than the specificed number of deviations away from the corresponding group mean.

See Also

fence.by.group to replace such elements with the boundary value.

trim.by.group to treat such observations as missing data.

flag.by.sds to identify values a certain number of standard deviations away from the overall mean.

Examples

data(sleepstudy, package='lme4')
sleepstudy$Possible.Outlier <- flag.by.group(sleepstudy$Reaction,
  sleepstudy$Subject, sds=3) # RTs 3 std devs from subject mean

data(VerbAgg, package='lme4')
VerbAgg$Possible.Outlier <- flag.by.group(VerbAgg$Anger,
  list(VerbAgg$btype, VerbAgg$situ), sds=3)
# 3 std devs from behavior type x situation type cell mean

sfraundorf/psycholing documentation built on April 23, 2022, 2:50 a.m.