Title: | Informative Nonparametric Bootstrap Test with Pooled Resampling |
Version: | 0.2.0 |
Description: | Sample sizes are often small due to hard to reach target populations, rare target events, time constraints, limited budgets, or ethical considerations. Two statistical methods with promising performance in small samples are the nonparametric bootstrap test with pooled resampling method, which is the focus of Dwivedi, Mallawaarachchi, and Alvarado (2017) <doi:10.1002/sim.7263>, and informative hypothesis testing, which is implemented in the 'restriktor' package. The 'npboottprmFBar' package uses the nonparametric bootstrap test with pooled resampling method to implement informative hypothesis testing. The bootFbar() function can be used to analyze data with this method and the persimon() function can be used to conduct performance simulations on type-one error and statistical power. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
URL: | https://github.com/mightymetrika/npboottprmFBar |
BugReports: | https://github.com/mightymetrika/npboottprmFBar/issues |
Imports: | DT, fGarch, lmPerm, mmints, npboottprm, restriktor, shiny |
Suggests: | testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2024-09-08 16:05:06 UTC; Administrator |
Author: | Mackson Ncube [aut, cre], mightymetrika, LLC [cph, fnd] |
Maintainer: | Mackson Ncube <macksonncube.stats@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2024-09-08 16:20:06 UTC |
Append Input Parameters to persimon_app Simulation Results
Description
This internal function combines simulation results with success rates and input parameters. It prepares the data for storage in the database by appending all relevant information from a single simulation run.
Usage
appendInputParams(df_results, df_success, input)
Arguments
df_results |
A data frame containing the main simulation results. |
df_success |
A data frame containing the counts of successful model runs. |
input |
A list of input values from the Shiny app, including simulation parameters. |
Details
This function performs several steps:
Appends '_success' to the column names of df_success (except n1, n2, n3).
Combines df_results with the modified df_success.
Generates a unique run code for the simulation.
Creates a data frame of input parameters.
Repeats the input parameters to match the number of rows in the results.
Combines all the above into a single data frame.
Value
A data frame combining simulation results, success rates, and input parameters. The returned data frame includes:
All columns from df_results
Success rate columns from df_success (appended with '_success')
Input parameters (M1, S1, M2, S2, M3, S3, Sk1, Sk2, Sk3, n_simulations, nboot, conf_level)
A unique RunCode for the simulation
Nonparametric Bootstrap Test with Pooled Resampling for Informative Hypothesis Testing
Description
Performs a nonparametric bootstrap test with pooled resampling based on the methods
described by Dwivedi et al. (2017) and using the restriktor::iht
function as
proposed by Vanbrabant and Rosseel (2020).
Usage
bootFbar(
data,
formula,
grp,
constraints,
nboot = 1000,
conf.level = 0.95,
seed = NULL,
na_rm = FALSE
)
Arguments
data |
A data frame containing the dataset for analysis. |
formula |
An object of class |
grp |
A string specifying the grouping variable in the data. |
constraints |
A matrix or data frame of constraints for the hypothesis test. |
nboot |
An integer indicating the number of bootstrap resamples (default is 1000). |
conf.level |
A numeric value specifying the confidence level for the interval (default is 0.95). |
seed |
An optional integer setting the seed for random number generation (default is NULL). |
na_rm |
A logical value indicating whether NA values should be removed (default is FALSE). |
Value
A list containing the following components:
-pvalueA, pvalueB, pvalueF: P-values for the different test types.
-ciA, ciB, ciF: Confidence intervals for the test statistics.
-TsA, TsB, TsF: Bootstrap test statistics.
-modelo: The linear model object.
-ihto: The initial iht computation result.
References
Dwivedi, A. K., Mallawaarachchi, I., & Alvarado, L. A. (2017). Analysis of small sample size studies using nonparametric bootstrap test with pooled resampling method. Statistics in Medicine, 36(14), 2187–2205. https://doi.org/10.1002/sim.7263
Vanbrabant, L., & Rosseel, Y. (2020). An Introduction to Restriktor: Evaluating informative hypotheses for linear models. In R. van de Schoot & M. Miocevic (Eds.), Small Sample Size Solutions: A Guide for Applied Researchers and Practitioners (1st ed., pp. 157 -172). Routledge. https://doi.org/10.4324/9780429273872-14
Examples
bootFbar(data = iris, formula = Sepal.Length ~ -1 + Species,
grp = "Species",
constraints = 'Speciessetosa < Speciesversicolor < Speciesvirginica',
nboot = 10, conf.level = 0.95, seed = NULL, na_rm = FALSE)
Internal Bootstrap Resampling for F-bar Test
Description
This internal function performs bootstrap resampling specific to the F-bar test
within the context of the nonparametric bootstrap test with pooled resampling.
It is used by bootFbar
to generate bootstrap samples and compute intermediate
statistics.
Usage
bootstrap_fbar_sample(
data,
formula,
grp,
constraints,
grp_val,
grp_sizes,
pre_calc,
only_equality_constraints
)
Arguments
data |
A data frame containing the dataset for analysis. |
formula |
An object of class |
grp |
A string specifying the grouping variable in the data. |
constraints |
A matrix or data frame of constraints for the hypothesis test. |
grp_val |
A vector containing the values of the group variable. |
grp_sizes |
A table object containing the sizes of each group. |
pre_calc |
A list containing pre-calculated original test statistics. |
only_equality_constraints |
A logical indicating whether only equality constraints are used. |
Details
The function creates bootstrap samples for each group in the data, then binds
these samples together. It applies the restriktor::iht
function on these
samples to compute the test statistics. Error handling is implemented to manage
potential issues in iht
computation.
Value
A list containing the test statistics for each constraint type (B, A, F) based on the bootstrap sample. Returns NA values if the iht computation fails.
Generate UI Parameters for persimon_app Simulation
Description
This internal function creates a list of 'shiny' input elements for the simulation parameters. It defines the UI components for means, standard deviations, skewness, sample sizes, number of simulations, number of bootstrap iterations, and confidence level.
Usage
getUIParams()
Details
This function is used internally by the 'shiny' app to generate the UI elements for parameter input.
Value
A list of 'shiny' input elements including:
M1 , M2 , M3 |
Numeric inputs for means of the three groups |
S1 , S2 , S3 |
Numeric inputs for standard deviations of the three groups |
Sk1 , Sk2 , Sk3 |
Numeric inputs for skewness of the three groups |
n1 , n2 , n3 |
Text inputs for sample sizes of the three groups |
n_simulations |
Numeric input for number of simulation iterations |
nboot |
Numeric input for number of bootstrap iterations |
conf.level |
Numeric input for confidence level |
Performance Simulation On Type I Error or Statistical Power
Description
Simulates performance (Type I Error or Statistical Power) for a range of statistical tests, including bootFbar, default setting restriktor::iht, and parametric bootstrap restriktor::iht. The function is set up to replicate the table structure in Dwivedi et al. (2017) Supplemental Tables 2 & 3.
Usage
persimon(
M1 = 5,
S1 = 1,
M2 = 5,
S2 = 1,
M3 = 5,
S3 = 1,
Sk1 = NULL,
Sk2 = NULL,
Sk3 = NULL,
n1 = c(2, 3, 4, 5, 6, 7, 8, 9, 10, 15),
n2 = c(2, 3, 4, 5, 6, 7, 8, 9, 10, 15),
n3 = c(2, 3, 4, 5, 6, 7, 8, 9, 10, 15),
n_simulations = 10000,
nboot = 1000,
conf.level = 0.95
)
Arguments
M1 |
Mean value for group 1. |
S1 |
Standard deviation for group 1. |
M2 |
Mean value for group 2. |
S2 |
Standard deviation for group 2. |
M3 |
Mean value for group 3. |
S3 |
Standard deviation for group 3. |
Sk1 |
Skewness parameter for group 1; NULL for normal distribution. |
Sk2 |
Skewness parameter for group 2; NULL for normal distribution. |
Sk3 |
Skewness parameter for group 3; NULL for normal distribution. |
n1 |
Vector of sample sizes for group 1. |
n2 |
Vector of sample sizes for group 2. |
n3 |
Vector of sample sizes for group 3. |
n_simulations |
Number of simulations to run (default is 10000). |
nboot |
Number of bootstrap samples (default is 1000). |
conf.level |
Confidence level for the tests (default is 0.95). |
Details
The persimon
function generates data for three groups with specified mean, standard deviation,
and skewness, and then applies a range of statistical tests to this data, simulating the process
across a specified number of iterations to assess performance in terms of Type I Error or
Statistical Power. The output mirrors the format of the supplemental tables in Dwivedi et al. (2017).
Value
A list of data frames. One with the proportions of rejecting the null hypothesis for each test and sample size combination, and the other with the number of models which did not produce errors for each combination.
References
Dwivedi, A. K., Mallawaarachchi, I., & Alvarado, L. A. (2017). Analysis of small sample size studies using nonparametric bootstrap test with pooled resampling method. Statistics in Medicine, 36(14), 2187–2205. https://doi.org/10.1002/sim.7263
Examples
set.seed(135)
persimon(M1 = 5, S1 = 1, M2 = 5, S2 = 1, M3 = 5, S3 = 1,
n1 = 6, n2 = 6, n3 = 6, n_simulations = 2, nboot = 4,
conf.level = 0.95)
Run Shiny Application for bootFbar Performance Simulation
Description
This function launches a 'shiny' application that allows users to run performance simulations for the bootFbar method and other statistical tests. The app provides an interface to set simulation parameters, run simulations, view results, and store them in a 'PostgreSQL' database.
Usage
persimon_app(dbname, datatable, host, port, user, password)
Arguments
dbname |
A string specifying the name of the 'PostgreSQL' database to connect to. |
datatable |
A string specifying the name of the table in the database where results will be stored. |
host |
A string specifying the host name or IP address of the 'PostgreSQL' server. |
port |
An integer specifying the port number on which the 'PostgreSQL' server is listening. |
user |
A string specifying the username for the 'PostgreSQL' database connection. |
password |
A string specifying the password for the 'PostgreSQL' database connection. |
Details
The 'shiny' application provides a user interface for setting simulation
parameters, running simulations using the persimon
function, and visualizing
the results. It allows users to:
Set parameters for the simulation (means, standard deviations, sample sizes, etc.)
Run simulations with the specified parameters
View simulation results and success rates in interactive tables
Store simulation results in a PostgreSQL database
Download stored results from the database
View relevant citations for the methods used
The application uses the mmints
package for database interactions and
citation handling.
Value
A 'shiny' application object.
See Also
persimon
for the underlying simulation function.
Examples
if(interactive()){
persimon_app(dbname = "my_database", datatable = "simulation_results",
host = "localhost", port = 5432,
user = "username", password = "password")
}
Run Persimon Simulation with User Inputs
Description
This internal function executes the persimon simulation using parameters provided by the user through the persimon_app 'shiny' app interface.
Usage
runSimulation(input)
Arguments
input |
A list of input values from the 'shiny' app. |
Details
This function serves as a wrapper around the persimon
function, translating
user inputs from the persimon_app 'shiny' app into the format required by
persimon
. It uses helper functions from the mmints
package to process
certain inputs.
Value
A list containing two data frames:
results |
Data frame with proportions of rejecting the null hypothesis |
success |
Data frame with counts of successful model runs |
See Also
persimon
for the underlying simulation function.