| PlausibilityFunction {flipr} | R Documentation |
R6 Class representing a plausibility function
Description
A plausibility function is...
Public fields
nparamsAn integer specifying the number of parameters to be inferred. Default is
1L.npermsAn integer specifying the number of permutations to be sampled. Default is
1000L.nperms_maxAn integer specifying the total number of distinct permutations that can be made given the sample sizes.
alternativeA string specifying the type of alternative hypothesis. Choices are
"two_tail","left_tail"and"right_tail. Defaults to"two_tail".aggregatorA string specifying which function should be used to aggregate test statistic values when non-parametric combination is used (i.e. when multiple test statistics are used). Choices are
"tippett"and"fisherfor now. Defaults to"tippett".pvalue_formulaA string specifying which formula to use for computing the permutation p-value. Choices are either
probability(default) orestimator. The former provides p-values that lead to exact hypothesis tests while the latter provides an unbiased estimate of the traditional p-value.max_conf_levelA numeric value specifying the maximum confidence level that we aim to achieve for the confidence regions. This is used to compute bounds on each parameter of interest in order to fit a Kriging model that approximates the expensive plausibility function on a hypercube. Defaults to
0.99.point_estimateA numeric vector providing point estimates for the parameters of interest.
parametersA list of functions of class
paramproduced vianew_quant_paramthat stores the parameters to be inferred along with important properties such as their name, range, etc. Defaults toNULL.gridA tibble storing evaluations of the plausibility function on a regular centered grid of the parameter space. Defaults to
NULL.
Methods
Public methods
Method new()
Create a new plausibility function object.
Usage
PlausibilityFunction$new( null_spec, stat_functions, stat_assignments, ..., seed = NULL )
Arguments
null_specA function or an R object coercible into a function (via
rlang::as_function()). For one-sample problems, it should transform thexsample (provided as first argument) using the parameters (as second argument) to make its distribution centered symmetric. For two-sample problems, it should transform theysample (provided as first argument) using the parameters (as second argument) to make it exchangeable with thexsample under a null hypothesis.stat_functionsA vector or list of functions (or R objects coercible into functions via
rlang::as_function()) specifying the whole set of test statistics that should be used.stat_assignmentsA named list of integer vectors specifying which test statistic should be associated with each parameter. The length of this list should match the number of parameters under investigation and is thus used to set it. Each element of the list should be named after the parameter it identifies.
...Vectors, matrices or lists providing the observed samples.
seedA numeric value specifying the seed to be used. Defaults to
NULLin which caseseed = 1234is used and the user is informed of this setting.
Returns
A new PlausibilityFunction object.
Method set_nperms()
Change the value of the nperms field.
Usage
PlausibilityFunction$set_nperms(val)
Arguments
valNew value for the number of permutations to be sampled.
Examples
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {purrr::map(y, ~ .x - parameters[1])}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$nperms
pf$set_nperms(10000)
pf$nperms
Method set_nperms_max()
Change the value of the nperms_max field.
Usage
PlausibilityFunction$set_nperms_max(val)
Arguments
valNew value for the total number of of possible distinct permutations.
Examples
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {purrr::map(y, ~ .x - parameters[1])}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$nperms_max
pf$set_nperms_max(10000)
pf$nperms_max
Method set_alternative()
Change the value of the alternative field.
Usage
PlausibilityFunction$set_alternative(val)
Arguments
valNew value for the type of alternative hypothesis.
Examples
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {purrr::map(y, ~ .x - parameters[1])}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$alternative
pf$set_alternative("right_tail")
pf$alternative
Method set_aggregator()
Change the value of the aggregator field.
Usage
PlausibilityFunction$set_aggregator(val)
Arguments
valNew value for the string specifying which function should be used to aggregate test statistic values when non-parametric combination is used (i.e. when multiple test statistics are used).
Examples
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {purrr::map(y, ~ .x - parameters[1])}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$aggregator
pf$set_aggregator("fisher")
pf$aggregator
Method set_pvalue_formula()
Change the value of the pvalue_formula field.
Usage
PlausibilityFunction$set_pvalue_formula(val)
Arguments
valNew value for the string specifying which formula should be used to compute the permutation p-value.
Examples
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$pvalue_formula
pf$set_pvalue_formula("estimate")
pf$pvalue_formula
Method get_value()
Computes an indicator of the plausibility of specific values for the parameters of interest in the form of a p-value of an hypothesis test against these values.
Usage
PlausibilityFunction$get_value( parameters, keep_null_distribution = FALSE, keep_permutations = FALSE, ... )
Arguments
parametersA vector whose length should match the
nparamsfield providing specific values of the parameters of interest for assessment of their plausibility in the form of a p-value of the corresponding hypothesis test.keep_null_distributionA boolean specifying whether the empirical permutation null distribution should be returned as well. Defaults to
FALSE.keep_permutationsA boolean specifying whether the list of sampled permutations used to compute the empirical permutation null distribution should be returned as well. Defaults to
FALSE....Extra parameters specific to some statistics.
Examples
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {purrr::map(y, ~ .x - parameters[1])}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$set_nperms(50)
pf$get_value(2)
Method set_max_conf_level()
Change the value of the max_conf_level field.
Usage
PlausibilityFunction$set_max_conf_level(val)
Arguments
valNew value for the maximum confidence level that we aim to achieve for the confidence regions.
Examples
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$max_conf_level
pf$set_max_conf_level(0.999)
pf$max_conf_level
Method set_point_estimate()
Change the value of the point_estimate field.
Usage
PlausibilityFunction$set_point_estimate( point_estimate = NULL, lower_bound = -10, upper_bound = 10, ncores = 1L, estimate = FALSE, overwrite = FALSE )
Arguments
point_estimateA numeric vector providing rough point estimates for the parameters under investigation.
lower_boundA scalar or numeric vector specifying the lower bounds for each parameter under investigation. If it is a scalar, the value is used as lower bound for all parameters. Defaults to
-10.upper_boundA scalar or numeric vector specifying the lower bounds for each parameter under investigation. If it is a scalar, the value is used as lower bound for all parameters. Defaults to
10.ncoresAn integer specifying the number of cores to use for maximizing the plausibility function to get a point estimate of the parameters. Defaults to
1L.estimateA boolean specifying whether the rough point estimate provided by
valshould serve as initial point for maximizing the plausibility function (estimate = TRUE) or as final point estimate for the parameters (estimate = FALSE). Defaults toFALSE.overwriteA boolean specifying whether to force the computation if it has already been set. Defaults to
FALSE.
Examples
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$point_estimate
pf$set_point_estimate(mean(y) - mean(x))
pf$point_estimate
Method set_parameter_bounds()
Change the value of the parameters field.
Updates the range of the parameters under investigation.
Usage
PlausibilityFunction$set_parameter_bounds(point_estimate, conf_level)
Arguments
point_estimateA numeric vector providing a point estimate for each parameter under investigation. If no estimator is known by the user, (s)he can resort to the
$set_point_estimate()method to get a point estimate by maximizing the plausibility function.conf_levelA numeric value specifying the confidence level to be used for setting parameter bounds. It should be in (0,1).
Examples
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$set_nperms(50)
pf$set_point_estimate(point_estimate = mean(y) - mean(x))
pf$parameters
pf$set_parameter_bounds(
point_estimate = pf$point_estimate,
conf_level = 0.8
)
pf$parameters
Method set_grid()
Computes a tibble storing a regular centered grid of the parameter space.
Usage
PlausibilityFunction$set_grid(parameters, npoints = 20L)
Arguments
parametersA list of
new_quant_paramobjects containing information about the parameters under investigation. It should contain the fieldspoint_estimateandrange.npointsAn integer specifying the number of points to discretize each dimension. Defaults to
20L.
Examples
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$set_nperms(50)
pf$set_point_estimate(mean(y) - mean(x))
pf$set_parameter_bounds(
point_estimate = pf$point_estimate,
conf_level = 0.8
)
pf$set_grid(
parameters = pf$parameters,
npoints = 2L
)
Method evaluate_grid()
Updates the grid field with a pvalue column storing
evaluations of the plausibility function on the regular centered grid
of the parameter space.
Usage
PlausibilityFunction$evaluate_grid(grid, ncores = 1L)
Arguments
gridA
tibblestoring a grid that spans the space of parameters under investigation.ncoresAn integer specifying the number of cores to run evaluations in parallel. Defaults to
1L.
Examples
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$set_nperms(50)
pf$set_point_estimate(mean(y) - mean(x))
pf$set_parameter_bounds(
point_estimate = pf$point_estimate,
conf_level = 0.8
)
pf$set_grid(
parameters = pf$parameters,
npoints = 2L
)
pf$evaluate_grid(grid = pf$grid)
Method clone()
The objects of this class are cloneable with this method.
Usage
PlausibilityFunction$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
## ------------------------------------------------
## Method `PlausibilityFunction$set_nperms`
## ------------------------------------------------
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {purrr::map(y, ~ .x - parameters[1])}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$nperms
pf$set_nperms(10000)
pf$nperms
## ------------------------------------------------
## Method `PlausibilityFunction$set_nperms_max`
## ------------------------------------------------
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {purrr::map(y, ~ .x - parameters[1])}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$nperms_max
pf$set_nperms_max(10000)
pf$nperms_max
## ------------------------------------------------
## Method `PlausibilityFunction$set_alternative`
## ------------------------------------------------
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {purrr::map(y, ~ .x - parameters[1])}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$alternative
pf$set_alternative("right_tail")
pf$alternative
## ------------------------------------------------
## Method `PlausibilityFunction$set_aggregator`
## ------------------------------------------------
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {purrr::map(y, ~ .x - parameters[1])}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$aggregator
pf$set_aggregator("fisher")
pf$aggregator
## ------------------------------------------------
## Method `PlausibilityFunction$set_pvalue_formula`
## ------------------------------------------------
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$pvalue_formula
pf$set_pvalue_formula("estimate")
pf$pvalue_formula
## ------------------------------------------------
## Method `PlausibilityFunction$get_value`
## ------------------------------------------------
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {purrr::map(y, ~ .x - parameters[1])}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$set_nperms(50)
pf$get_value(2)
## ------------------------------------------------
## Method `PlausibilityFunction$set_max_conf_level`
## ------------------------------------------------
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$max_conf_level
pf$set_max_conf_level(0.999)
pf$max_conf_level
## ------------------------------------------------
## Method `PlausibilityFunction$set_point_estimate`
## ------------------------------------------------
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$point_estimate
pf$set_point_estimate(mean(y) - mean(x))
pf$point_estimate
## ------------------------------------------------
## Method `PlausibilityFunction$set_parameter_bounds`
## ------------------------------------------------
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$set_nperms(50)
pf$set_point_estimate(point_estimate = mean(y) - mean(x))
pf$parameters
pf$set_parameter_bounds(
point_estimate = pf$point_estimate,
conf_level = 0.8
)
pf$parameters
## ------------------------------------------------
## Method `PlausibilityFunction$set_grid`
## ------------------------------------------------
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$set_nperms(50)
pf$set_point_estimate(mean(y) - mean(x))
pf$set_parameter_bounds(
point_estimate = pf$point_estimate,
conf_level = 0.8
)
pf$set_grid(
parameters = pf$parameters,
npoints = 2L
)
## ------------------------------------------------
## Method `PlausibilityFunction$evaluate_grid`
## ------------------------------------------------
x <- rnorm(10)
y <- rnorm(10, mean = 2)
null_spec <- function(y, parameters) {
purrr::map(y, ~ .x - parameters[1])
}
stat_functions <- list(stat_t)
stat_assignments <- list(mean = 1)
pf <- PlausibilityFunction$new(
null_spec = null_spec,
stat_functions = stat_functions,
stat_assignments = stat_assignments,
x, y
)
pf$set_nperms(50)
pf$set_point_estimate(mean(y) - mean(x))
pf$set_parameter_bounds(
point_estimate = pf$point_estimate,
conf_level = 0.8
)
pf$set_grid(
parameters = pf$parameters,
npoints = 2L
)
pf$evaluate_grid(grid = pf$grid)