This function carries out an hypothesis test where the null hypothesis is that the sample is governed by a generative probability distribution which is centered and symmetric against the alternative hypothesis that they are governed by a probability distribution that is either not centered or not symmetric.
Usage
one_sample_test(
x,
stats = list(stat_max),
B = 1000L,
M = NULL,
alternative = "two_tail",
combine_with = "tippett",
type = "exact",
seed = NULL,
...
)
Arguments
- x
A numeric vector or a numeric matrix or a list representing the sample from which the user wants to make inference.
- stats
A list of functions produced by
as_function
specifying the chosen test statistic(s). A number of test statistic functions are implemented in the package and can be used as such. Alternatively, one can provide its own implementation of test statistics that (s)he deems relevant for the problem at hand. See the section User-supplied statistic function for more information on how these user-supplied functions should be structured for compatibility with the flipr framework. Default islist(stat_t)
.- B
The number of sampled permutations. Default is
1000L
.- M
The total number of possible permutations. Defaults to
NULL
, which means that it is automatically computed from the given sample size(s).- alternative
A single string or a character vector specifying whether the p-value is right-tailed, left-tailed or two-tailed. Choices are
"right_tail"
,"left_tail"
and"two_tail"
. Default is"two_tail"
. If a single string is provided, it is assumed that it should be applied to all test statistics provided by the user. Alternative, the length ofalternative
should match the length of thestats
parameter and it is assumed that there is a one-to-one correspondence.- combine_with
A string specifying the combining function to be used to compute the single test statistic value from the set of p-value estimates obtained during the non-parametric combination testing procedure. For now, choices are either
"tippett"
or"fisher"
. Default is"tippett"
, which picks Tippett's function.- type
A string specifying which formula should be used to compute the p-value. Choices are
exact
(default),upper_bound
andestimate
. See Phipson & Smith (2010) for details.- seed
An integer specifying the seed of the random generator useful for result reproducibility or method comparisons. Default is
NULL
.- ...
Extra parameters specific to some statistics.
Value
A list
with three components: the value of the
statistic for the original two samples, the p-value of the resulting
permutation test and a numeric vector storing the values of the permuted
statistics.
User-supplied statistic function
A user-specified function should have at least two arguments:
the first argument is
data
which should be a list of then
observations from the sample;the second argument is
flips
which should be an integer vector giving the signs by which each observation indata
should be multiplied.
It is possible to use the use_stat
function with nsamples = 1
to have flipr automatically generate a template file for writing down
your own test statistics in a way that makes it compatible with the flipr
framework.
See the stat_max
function for an example.
Examples
n <- 10L
mu <- 3
sigma <- 1
# Sample under the null distribution
x1 <- rnorm(n = n, mean = 0, sd = sigma)
t1 <- one_sample_test(x1, B = 100L)
t1$pvalue
#> [1] 0.712383
# Sample under some alternative distribution
x2 <- rnorm(n = n, mean = mu, sd = sigma)
t2 <- one_sample_test(x2, B = 100L)
t2$pvalue
#> [1] 0