bootstrap {fastei} | R Documentation |
Runs a Bootstrap to Estimate the Standard Deviation of Predicted Probabilities
Description
This function computes the Expected-Maximization (EM) algorithm "nboot
" times. It then computes the standard deviation from the nboot
estimated probability matrices on each component.
Usage
bootstrap(
object = NULL,
X = NULL,
W = NULL,
json_path = NULL,
nboot = 100,
allow_mismatch = TRUE,
seed = NULL,
...
)
Arguments
object |
An object of class |
X |
A |
W |
A |
json_path |
A path to a JSON file containing |
nboot |
Integer specifying how many times to run the EM algorithm. |
allow_mismatch |
Boolean, if |
seed |
An optional integer indicating the random seed for the randomized algorithms. This argument is only applicable if |
... |
Additional arguments passed to the run_em function that will execute the EM algorithm. |
Value
Returns an eim
object with the sd
field containing the estimated standard deviations of the probabilities and the amount of iterations that were made. If an eim
object is provided, its attributes (see run_em) are retained in the returned object.
Note
This function can be executed using one of three mutually exclusive approaches:
By providing an existing
eim
object.By supplying both input matrices (
X
andW
) directly.By specifying a JSON file (
json_path
) containing the matrices.
These input methods are mutually exclusive, meaning that you must provide exactly one of these options. Attempting to provide more than one or none of these inputs will result in an error.
When called with an eim
object, the function updates the object with the computed results.
If an eim
object is not provided, the function will create one internally using either the
supplied matrices or the data from the JSON file before executing the algorithm.
See Also
The eim object and run_em implementation.
Examples
# Example 1: Using an 'eim' object directly
simulations <- simulate_election(
num_ballots = 200,
num_candidates = 5,
num_groups = 3,
)
model <- eim(X = simulations$X, W = simulations$W)
model <- bootstrap(
object = model,
nboot = 30,
method = "mult",
maxiter = 500,
verbose = FALSE,
)
# Access standard deviation throughout 'model'
print(model$sd)
# Example 2: Providing 'X' and 'W' matrices directly
model <- bootstrap(
X = simulations$X,
W = simulations$W,
nboot = 15,
method = "mvn_pdf",
maxiter = 100,
maxtime = 5,
param_threshold = 0.01,
allow_mismatch = FALSE
)
print(model$sd)
# Example 3: Using a JSON file as input
## Not run:
model <- bootstrap(
json_path = "path/to/election_data.json",
nboot = 70,
method = "mult",
)
print(model$sd)
## End(Not run)