trimmed_test performs the two-sample trimmed t-test.
trimmed_test(
x,
y,
gamma = 0.2,
alternative = c("two.sided", "less", "greater"),
method = c("asymptotic", "permutation", "randomization"),
delta = ifelse(scale.test, 1, 0),
n.rep = 1000,
na.rm = FALSE,
scale.test = FALSE,
wobble.seed = NULL
)A named list with class "htest" containing the following components:
the value of the test statistic.
the degrees of freedom for the test statistic.
the p-value for the test.
the trimmed means of x and y
(if scale.test = FALSE) or of log(x^2) and
log(y^2) (if scale.test = TRUE).
the specified hypothesized value of the mean difference/squared scale ratio.
a character string describing the alternative hypothesis.
a character string indicating how the p-value was computed.
a character string giving the names of the data.
a (non-empty) numeric vector of data values.
a (non-empty) numeric vector of data values.
a numeric value in [0, 0.5] specifying the fraction of observations to be trimmed from each end of the sample before calculating the mean. The default value is 0.2.
a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater", or "less".
a character string specifying how the p-value is computed with
possible values "asymptotic" for an asymptotic test
based on a normal approximation, "permutation" for a
permutation test, and "randomization" for a randomization
test. The permutation test uses all splits of the joint sample
into two samples of sizes m and n, while the
randomization test draws n.rep random splits with
replacement. The values m and n denote the
sample sizes.
If not specified explicitly, defaults to
"permutation" if m < 30, n < 30 and
n.rep >= choose(m + n, m),
"randomization" if m < 30, n < 30 and
n.rep < choose(m + n, m), and
"asymptotic" if m >= 30 and n >= 30.
a numeric value indicating the true difference in the location or
scale parameter, depending on whether the test should be performed
for a difference in location or in scale. The default is
delta = 0 for a location test and delta = 1 for a scale
test. In case of scale.test = TRUE, delta represents
the ratio of the squared scale parameters.
an integer value specifying the number of random splits used to
calculate the randomization distribution if method = "randomization".
This argument is ignored if method = "permutation" or method = "asymptotic".
The default is n.rep = 10000.
a logical value indicating whether NA values in x and
y should be stripped before the computation proceeds. The
default is na.rm = FALSE.
a logical value to specify if the samples should be compared
for a difference in scale. The default is scale.test = FALSE.
an integer value used as a seed for the random number
generation in case of wobble = TRUE or when
scale.test = TRUE with one of the vectors x and
y containing zeros. When no seed is specified, it
is chosen randomly and printed in a message. The argument
is ignored if scale.test = FALSE and/or wobble = FALSE.
The function performs Yuen's t-test based on the trimmed mean and winsorized
variance YueDix73apprrobnptests.
The amount of trimming/winsorization is set in gamma and
defaults to 0.2, i.e. 20% of the values are removed/replaced.
In addition to the asymptotic distribution a permutation and a
randomization version of the test are implemented.
When computing a randomization distribution based on randomly drawn splits
with replacement, the function permp PhiSmy10permrobnptests
is used to calculate the p-value.
For scale.test = TRUE, the test compares the two samples for a difference
in scale. This is achieved by log-transforming the original squared observations,
i.e. x is replaced by log(x^2) and y by log(y^2).
A potential scale difference then appears as a location difference between
the transformed samples, see Fri12onli;textualrobnptests.
Note that the samples need to have equal locations. The sample should not
contain zeros to prevent problems with the necessary log-transformation. If
it contains zeros, uniform noise is added to all variables in order to remove
zeros and a message is printed.
If the sample has been modified because of zeros when scale.test = TRUE,
the modified samples can be retrieved using
set.seed(wobble.seed); wobble(x, y)
Both samples need to contain at least 5 non-missing values.
YueDix73apprrobnptests
Yue74trimrobnptests
Fri12onlirobnptests
# Generate random samples
set.seed(108)
x <- rnorm(20); y <- rnorm(20)
# Trimmed t-test
trimmed_test(x, y, gamma = 0.1)
Run the code above in your browser using DataLab