trimmed_test {robnptests} | R Documentation |
Two-sample trimmed t-test (Yuen's t-Test)
Description
trimmed_test
performs the two-sample trimmed t-test.
Usage
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
)
Arguments
x |
a (non-empty) numeric vector of data values. |
y |
a (non-empty) numeric vector of data values. |
gamma |
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. |
alternative |
a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater", or "less". |
method |
a character string specifying how the p-value is computed with
possible values |
delta |
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
|
n.rep |
an integer value specifying the number of random splits used to
calculate the randomization distribution if |
na.rm |
a logical value indicating whether NA values in |
scale.test |
a logical value to specify if the samples should be compared
for a difference in scale. The default is |
wobble.seed |
an integer value used as a seed for the random number
generation in case of |
Details
The function performs Yuen's t-test based on the trimmed mean and winsorized
variance (Yuen and Dixon 1973).
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
(Phipson and Smyth 2010)
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 Fried (2012).
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.
Value
A named list with class "htest
" containing the following components:
statistic |
the value of the test statistic. |
parameter |
the degrees of freedom for the test statistic. |
p.value |
the p-value for the test. |
estimate |
the trimmed means of |
null.value |
the specified hypothesized value of the mean difference/squared scale ratio. |
alternative |
a character string describing the alternative hypothesis. |
method |
a character string indicating how the p-value was computed. |
data.name |
a character string giving the names of the data. |
References
Yuen KK, Dixon WT (1973). “The approximate behaviour and performance of the two-sample trimmed t.” Biometrika, 60(2), 369–374. doi:10.2307/2334550.
Yuen KK (1974). “The two-sample trimmed t for unequal population variances.” Biometrika, 61(1), 165–170. doi:10.2307/2334299.
Fried R (2012). “On the online estimation of piecewise constant volatilities.” Computational Statistics & Data Analysis, 56(11), 3080–3090. doi:10.1016/j.csda.2011.02.012.
Examples
# Generate random samples
set.seed(108)
x <- rnorm(20); y <- rnorm(20)
# Trimmed t-test
trimmed_test(x, y, gamma = 0.1)