This function performs a bootstrap procedure on a fitted RRi model (as produced by
estimate_RRi_curve()
) to assess the uncertainty of the parameter estimates. It
resamples the original data (using either a specified number of samples or a proportion of
the available data) and re-estimates the dual-logistic model parameters for each bootstrap
sample. The approach leverages the speed and efficiency of the data.table package.
Usage
boot_RRi_parameters(
fit = NULL,
n_samples = nrow(fit$data),
prop_of_samples = NULL,
nboot = 100
)
Arguments
- fit
An object of class
"RRi_fit"
produced byestimate_RRi_curve()
. This fitted object must contain adata
component with the original time and RRi values as well as the fitted values.- n_samples
A numeric value specifying the number of data points to sample for each bootstrap replicate. The default is
nrow(fit$data)
(all data points). Must not exceed the total number of rows in the data.- prop_of_samples
A numeric value (between 0 and 1) specifying the proportion of data to use in each bootstrap sample. If specified, it overrides
n_samples
by computing the number asfloor(nrow(fit$data) * prop_of_samples)
.- nboot
A numeric value indicating the number of bootstrap replicates to perform. The default is
100
.
Value
An object of class "boot_RRi_fit"
, which is a data.table with one row per bootstrap replicate.
Each row contains the estimated parameters from that bootstrap sample.
Details
The bootstrap procedure returns a data.table with a row for each bootstrap replicate, containing the estimated parameters. This enables users to construct confidence intervals and assess the variability of the fitted model parameters.
The function first checks that the input fit
object is not NULL and that n_samples
and nboot
are numeric and valid. If prop_of_samples
is provided, it is used to compute the number of samples
per replicate. The data from the fit
object is converted to a data.table for efficient subsetting.
Bootstrap indices are generated by sampling with replacement, and for each bootstrap replicate, the function
re-estimates the model parameters using estimate_RRi_curve()
. The output is a data.table where each row
corresponds to a bootstrap replicate.
Examples
# \donttest{
library(CardioCurveR)
library(data.table)
# Simulate an example RRi signal:
set.seed(123)
t <- seq(0, 20, by = 0.01)
true_params <- c(alpha = 800, beta = -350, c = 0.80,
lambda = -3, phi = -2, tau = 6, delta = 3)
RRi_true <- dual_logistic(t, true_params)
RRi_sim <- RRi_true + rnorm(n = length(t), sd = 30)
# Estimate the model parameters:
fit <- estimate_RRi_curve(time = t, RRi = RRi_sim)
# Bootstrap the parameter estimates using 50% of the data per replicate and 100 replicates
boot_fit <- boot_RRi_parameters(fit = fit, prop_of_samples = 0.5, nboot = 100)
# View the bootstrap estimates
print(boot_fit)
#> Bootstrap RRi Parameter Estimates
#> Number of bootstrap replicates: 100
#> Preview of estimated parameters (first 6 replicates):
#> nboot alpha beta c lambda phi tau delta
#> 1 1 800.5251 -353.5449 0.8870946 -3.062566 -1.622490 5.968664 3.120885
#> 2 2 800.4201 -339.0531 0.7224601 -3.243566 -2.183843 5.952733 2.974459
#> 3 3 800.4500 -346.2715 0.7425458 -3.314643 -2.128720 5.971596 2.973739
#> 4 4 799.3835 -337.8819 0.6500205 -3.020092 -2.984357 5.951567 2.904101
#> 5 5 801.1221 -347.4734 0.7006175 -3.203447 -2.364417 5.969239 2.886365
#> 6 6 803.9053 -346.8873 0.7399056 -3.253758 -2.202961 5.961412 2.990922
# }