Skip to contents

An R6 class for accessing and summarizing the results of a SimulationFramework run. It can be constructed either from a completed SimulationFramework object (via SimulationFrameworkReport$new(sim)) or by loading results from a previously saved CSV / CSV.BZ2 file (via SimulationFrameworkReport$new("path/to/results.csv")).

Details

When constructed from a SimulationFramework object all design/inference parameter metadata is preserved, so $summarize() can annotate each row with human-readable parameter strings. When constructed from a file only the raw results are available; parameter annotation columns will be empty strings.

Methods


SimulationFrameworkReport$new()

Create a new SimulationFrameworkReport object that stores simulation results, captured errors, and summary helpers returned by SimulationFramework.

Usage

SimulationFrameworkReport$new(sim_or_filename, alpha = NULL)

Arguments

sim_or_filename

Either a completed SimulationFramework object or a character string giving the path to a .csv or .csv.bz2 results file written by SimulationFramework.

alpha

Numeric in \((0,1)\). Significance level for the power and size calculations (a p-value below alpha rejects). When sim_or_filename is a SimulationFramework object and alpha is NULL (default), the framework's own alpha is used. Coverage (and coverage_pval, the test of coverage \(= 1 - \alpha\)) always uses the alpha the confidence intervals were built at, the framework's, whatever alpha is given here. When loading from a file, defaults to 0.05 and is used for both.


SimulationFrameworkReport$get_results()

Get the raw per-replication results.

Usage

SimulationFrameworkReport$get_results()

Returns

A data.table with one row per (replication, design, inference class, inference type). Its simulation_mode column records which custom data-generating hooks of the SimulationFramework were active for that row: "standard" (none), "custom_dgp", or a "+"-joined combination of "crdg" (custom_replication_data_generator), "catn" (custom_apply_treatment_and_noise) and "cte" (make_estimand_fn), e.g. "crdg+catn+cte". $summarize() groups by this column, and for any mode other than "standard" it decides whether a cell is a null (size) or an alternative (power) cell from the mean true_estimand instead of from betaT.


SimulationFrameworkReport$get_errors()

Return all errors captured during the simulation run.

Usage

SimulationFrameworkReport$get_errors()

Returns

A list of named lists, one per captured error. Each element includes the simulation cell metadata, replication number, design / inference path, user-supplied parameters, error stage, and error message. Empty when constructed from a file.


SimulationFrameworkReport$summarize()

Aggregate and summarize simulation results.

Usage

SimulationFrameworkReport$summarize()

Returns

A data.table with one row per unique (response_type, cond_exp_func_model, n, p, betaT, design, inference, inference_type, simulation_mode) combination (simulation_mode only when the results carry that column; see $get_results()). Columns include MSE, coverage, ci_length, and coverage_pval (when CI types were run; coverage_pval is the exact two-sided binomial test p-value of H0: true coverage = 1 - alpha), power (when betaT != 0 and p-value types were run), size and size_pval (when betaT == 0 and p-value types were run; size_pval is the exact two-sided binomial test p-value of H0: true size = alpha, suitable for multiplicity-corrected calibration checks across settings), and parameter annotation strings.


SimulationFrameworkReport$print()

Print a concise summary of the report.

Usage

SimulationFrameworkReport$print()


SimulationFrameworkReport$clone()

The objects of this class are cloneable with this method.

Usage

SimulationFrameworkReport$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

sim <- SimulationFramework$new(
  response_type = "continuous",
  design_classes_and_params = list(DesignFixedBernoulli),
  inference_classes_and_params = list(InferenceAllSimpleAverageDiff),
  inference_types_and_params = list(
    asymp_ci = list(),
    asymp_pval = list(),
    boot_ci = list(type = "percentile"),
    boot_pval = list(type = "percentile")
  ),
  n = 20L, Nrep_W = 5L, betaT = 1,
  results_filename = tempfile(fileext = ".csv"),
  verbose = FALSE, continue_from_last_result_row = FALSE
)
# \donttest{
sim$run()
report <- SimulationFrameworkReport$new(sim)
report$get_results()
#>     response_type   rep cond_exp_func_model     n     p betaT
#>            <char> <int>              <char> <int> <int> <num>
#>  1:    continuous     1              linear    20     5     1
#>  2:    continuous     1              linear    20     5     1
#>  3:    continuous     1              linear    20     5     1
#>  4:    continuous     1              linear    20     5     1
#>  5:    continuous     2              linear    20     5     1
#>  6:    continuous     2              linear    20     5     1
#>  7:    continuous     2              linear    20     5     1
#>  8:    continuous     2              linear    20     5     1
#>  9:    continuous     3              linear    20     5     1
#> 10:    continuous     3              linear    20     5     1
#> 11:    continuous     3              linear    20     5     1
#> 12:    continuous     3              linear    20     5     1
#> 13:    continuous     4              linear    20     5     1
#> 14:    continuous     4              linear    20     5     1
#> 15:    continuous     4              linear    20     5     1
#> 16:    continuous     4              linear    20     5     1
#> 17:    continuous     5              linear    20     5     1
#> 18:    continuous     5              linear    20     5     1
#> 19:    continuous     5              linear    20     5     1
#> 20:    continuous     5              linear    20     5     1
#>     response_type   rep cond_exp_func_model     n     p betaT
#>            <char> <int>              <char> <int> <int> <num>
#>                   design                     inference inference_type  estimate
#>                   <char>                        <char>         <char>     <num>
#>  1: DesignFixedBernoulli InferenceAllSimpleAverageDiff     asymp_pval 0.9914813
#>  2: DesignFixedBernoulli InferenceAllSimpleAverageDiff       asymp_ci 0.9914813
#>  3: DesignFixedBernoulli InferenceAllSimpleAverageDiff      boot_pval 0.9914813
#>  4: DesignFixedBernoulli InferenceAllSimpleAverageDiff        boot_ci 0.9914813
#>  5: DesignFixedBernoulli InferenceAllSimpleAverageDiff     asymp_pval 1.2364129
#>  6: DesignFixedBernoulli InferenceAllSimpleAverageDiff       asymp_ci 1.2364129
#>  7: DesignFixedBernoulli InferenceAllSimpleAverageDiff      boot_pval 1.2364129
#>  8: DesignFixedBernoulli InferenceAllSimpleAverageDiff        boot_ci 1.2364129
#>  9: DesignFixedBernoulli InferenceAllSimpleAverageDiff     asymp_pval 1.2675312
#> 10: DesignFixedBernoulli InferenceAllSimpleAverageDiff       asymp_ci 1.2675312
#> 11: DesignFixedBernoulli InferenceAllSimpleAverageDiff      boot_pval 1.2675312
#> 12: DesignFixedBernoulli InferenceAllSimpleAverageDiff        boot_ci 1.2675312
#> 13: DesignFixedBernoulli InferenceAllSimpleAverageDiff     asymp_pval 1.5153061
#> 14: DesignFixedBernoulli InferenceAllSimpleAverageDiff       asymp_ci 1.5153061
#> 15: DesignFixedBernoulli InferenceAllSimpleAverageDiff      boot_pval 1.5153061
#> 16: DesignFixedBernoulli InferenceAllSimpleAverageDiff        boot_ci 1.5153061
#> 17: DesignFixedBernoulli InferenceAllSimpleAverageDiff     asymp_pval 0.2936115
#> 18: DesignFixedBernoulli InferenceAllSimpleAverageDiff       asymp_ci 0.2936115
#> 19: DesignFixedBernoulli InferenceAllSimpleAverageDiff      boot_pval 0.2936115
#> 20: DesignFixedBernoulli InferenceAllSimpleAverageDiff        boot_ci 0.2936115
#>                   design                     inference inference_type  estimate
#>                   <char>                        <char>         <char>     <num>
#>          ci_lo    ci_hi        pval true_estimand simulation_mode
#>          <num>    <num>       <num>         <num>          <char>
#>  1:         NA       NA 0.128770011             1        standard
#>  2: -0.3202002 2.303163          NA             1        standard
#>  3:         NA       NA 0.099502488             1        standard
#>  4: -0.2007123 2.111874          NA             1        standard
#>  5:         NA       NA 0.009598123             1        standard
#>  6:  0.3445678 2.128258          NA             1        standard
#>  7:         NA       NA 0.009950249             1        standard
#>  8:  0.4647273 2.009181          NA             1        standard
#>  9:         NA       NA 0.098766174             1        standard
#> 10: -0.2627970 2.797859          NA             1        standard
#> 11:         NA       NA 0.079601990             1        standard
#> 12: -0.2800753 2.638321          NA             1        standard
#> 13:         NA       NA 0.029897976             1        standard
#> 14:  0.1723705 2.858242          NA             1        standard
#> 15:         NA       NA 0.029850746             1        standard
#> 16:  0.2138072 2.862189          NA             1        standard
#> 17:         NA       NA 0.758136577             1        standard
#> 18: -1.8570756 2.444299          NA             1        standard
#> 19:         NA       NA 0.666666667             1        standard
#> 20: -1.5637843 2.004022          NA             1        standard
#>          ci_lo    ci_hi        pval true_estimand simulation_mode
#>          <num>    <num>       <num>         <num>          <char>
report$summarize()
#> Key: <response_type, cond_exp_func_model, n, p, betaT, design, inference, inference_type, simulation_mode>
#>    response_type cond_exp_func_model     n     p betaT               design
#>           <char>              <char> <int> <int> <num>               <char>
#> 1:    continuous              linear    20     5     1 DesignFixedBernoulli
#> 2:    continuous              linear    20     5     1 DesignFixedBernoulli
#> 3:    continuous              linear    20     5     1 DesignFixedBernoulli
#> 4:    continuous              linear    20     5     1 DesignFixedBernoulli
#>                        inference inference_type simulation_mode       MSE n_est
#>                           <char>         <char>          <char>     <num> <int>
#> 1: InferenceAllSimpleAverageDiff       asymp_ci        standard 0.1784123     5
#> 2: InferenceAllSimpleAverageDiff     asymp_pval        standard 0.1784123     5
#> 3: InferenceAllSimpleAverageDiff        boot_ci        standard 0.1784123     5
#> 4: InferenceAllSimpleAverageDiff      boot_pval        standard 0.1784123     5
#>    coverage n_cov ci_length coverage_pval power n_pow  size n_size size_pval
#>       <num> <int>     <num>         <num> <num> <int> <num>  <int>     <num>
#> 1:        1     5  2.890991             1    NA     0    NA      0        NA
#> 2:       NA     0        NA            NA   0.4     5    NA      0        NA
#> 3:        1     5  2.598325             1    NA     0    NA      0        NA
#> 4:       NA     0        NA            NA   0.4     5    NA      0        NA
#>    design_params inference_params        inference_type_params
#>           <char>           <char>                       <char>
#> 1:                                                            
#> 2:                                                            
#> 3:                                  boot_ci(type="percentile")
#> 4:                                boot_pval(type="percentile")
# }