Assess the Monte Carlo error of the RoC estimates from
estimate_roc() and recommend the number of randomisation runs
(rand) that keeps it below a tolerance. Run estimate_roc() with a
moderate rand (for example 100) first, check the result, and repeat
the estimation with the recommended rand if it is larger.
Arguments
- data_source
data.frame. Output ofestimate_roc(), with the columnsWorking_Unit,ROC_up,ROC_dw,n_runs,ROC_mc_error,ROC_up_mc_error, andROC_dw_mc_error. Rows may be filtered, for example by age, if at least one WU pair with values from all runs remains (see Details). The output ofdetect_peak_points()can be used too.- tolerance
numeric. Single value above 0. Largest accepted Monte Carlo error ofROC,ROC_up, andROC_dw, as a proportion of the width of the 95 % interval (ROC_up - ROC_dw) of each Working Unit (WU) pair. Default0.10, as used by the warning ofestimate_roc().- silent
logical. IfTRUE, suppress the summary printed to the console.
Value
A list with two elements:
rand_recommended- singlenumericwhole number. Number of runs at which the Monte Carlo error is belowtolerancein 90 % of the assessed WU pairs, rounded up to the next 100 and at least 100.NAwhen the error could not be estimated (too few runs or no randomisation).data_mc_error-tibblewith one row per WU pair and columnsWorking_Unit,n_runs,mc_error_relative(largest Monte Carlo error of the three estimates divided by the interval width),runs_needed(runs needed for this WU pair), andis_assessed.
Details
The Monte Carlo error falls with the square root of the number of
runs, so a WU pair needs n_runs_max * (mc_error_relative / tolerance)^2 runs, where n_runs_max, the largest n_runs, is taken
as the number of runs used. The summary prints this number ("With ...
runs"). If filtered rows keep only WU pairs with values from some of
the runs, it is smaller than the runs used and the recommendation is
too low.
WU pairs with values from fewer than half of the runs (mostly at the
ends of the record, where a bin is filled only in some runs), with a
missing error, or with an interval width of 0 are not assessed. The
error of ROC_dw is missing for WU pairs with fewer than 60 values,
so with 100 runs, WU pairs with values from 50 to 59 runs are not
assessed either. The recommendation uses the 90th percentile across WU
pairs rather than the largest value, because the largest of many noisy
estimates overstates the runs needed.
The errors are the exact bootstrap standard errors of the order
statistics nearest to the median and to the 2.5 % and 97.5 % quantiles
across runs (Maritz and Jarrett, 1978); estimate_roc() reports
interpolated quantiles, so the errors refer to the nearest order
statistic rather than to the reported value. Estimates from fewer than
100 runs are unreliable, especially for ROC_up and ROC_dw.
References
Maritz, J. S., Jarrett, R. G., 1978. A note on estimating the variance of the sample median. Journal of the American Statistical Association 73, 194-196. doi:10.1080/01621459.1978.10480027
Examples
# \donttest{
data("example_data", package = "RRatepol")
data_pollen <-
purrr::chuck(example_data, "pollen_data", 1)
data_age <-
purrr::chuck(example_data, "sample_age", 1)
mat_age_uncertainty <-
purrr::chuck(example_data, "age_uncertainty", 1)
# 1. Pilot run with a moderate number of runs
data_roc_pilot <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
age_uncertainty = mat_age_uncertainty,
smooth_method = "shep",
dissimilarity_coefficient = "chisq",
rand = 100,
seed = 900723,
silent = TRUE
)
# 2. Recommended number of runs for a Monte Carlo error of at most 10 %
# of the width of the 95 % interval (the default `tolerance`)
list_rand <-
check_rand(data_source = data_roc_pilot)
#> ℹ Monte Carlo error assessed in 62 of 62 Working Units. With 100 runs, it
#> exceeds 10 % of the 95 % interval width in 59 of them. Recommended number of
#> randomisation runs (`rand`): 3900.
n_rand_recommended <-
purrr::chuck(list_rand, "rand_recommended")
n_rand_recommended
#> [1] 3900
# The Monte Carlo error and the runs needed for each WU pair
purrr::chuck(list_rand, "data_mc_error")
#> # A tibble: 62 × 5
#> Working_Unit n_runs mc_error_relative runs_needed is_assessed
#> <chr> <int> <dbl> <dbl> <lgl>
#> 1 392671-392672 100 0.182 333. TRUE
#> 2 392672-392673 100 0.0836 70.0 TRUE
#> 3 392673-392674 100 0.157 247. TRUE
#> 4 392674-392675 100 0.579 3357. TRUE
#> 5 392675-392676 100 0.308 947. TRUE
#> 6 392676-392677 100 0.429 1840. TRUE
#> 7 392677-392678 100 0.385 1481. TRUE
#> 8 392678-392679 100 0.392 1536. TRUE
#> 9 392679-392680 100 0.561 3147. TRUE
#> 10 392680-392681 100 0.257 660. TRUE
#> # ℹ 52 more rows
# A stricter tolerance of 5 % needs about four times as many runs
list_rand_strict <-
check_rand(
data_source = data_roc_pilot,
tolerance = 0.05
)
#> ℹ Monte Carlo error assessed in 62 of 62 Working Units. With 100 runs, it
#> exceeds 5 % of the 95 % interval width in 62 of them. Recommended number of
#> randomisation runs (`rand`): 15600.
# The output of detect_peak_points() can be checked too
list_rand_peaks <-
data_roc_pilot %>%
detect_peak_points(sel_method = "trend_non_linear") %>%
check_rand()
#> ℹ Monte Carlo error assessed in 62 of 62 Working Units. With 100 runs, it
#> exceeds 10 % of the 95 % interval width in 59 of them. Recommended number of
#> randomisation runs (`rand`): 3900.
# 3. Final run with the recommended number of runs, on all available
# cores. Not run here: on one core, it takes about a minute for this
# sequence.
# data_roc_final <-
# estimate_roc(
# data_source_community = data_pollen,
# data_source_age = data_age,
# age_uncertainty = mat_age_uncertainty,
# smooth_method = "shep",
# dissimilarity_coefficient = "chisq",
# rand = n_rand_recommended,
# use_parallel = TRUE,
# seed = 900723
# )
# }
