View source: R/flag.by.group.R
flag.by.group | R Documentation |
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.
flag.by.group(x, INDEX, sds = 3, print = TRUE, na.rm = FALSE)
x |
a numeric vector. |
INDEX |
list of one or more grouping variables, typically factors, each
of the same length as |
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. |
logical vector indicating whether each element of x is more than the specificed number of deviations away from the corresponding group mean.
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.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.