# Simulate the margin of error for an overall survey or a single question

`simu_moe.Rd`

For the overall survey: given weights and/or a sample size, the maximum margin of error gives us the upper bound on the margin of error for all y/n questions across the entire survey – by estimating it for a hypothetical y/n question with 50/50 (the inherently most uncertain population estimand).

## Usage

```
simu_moe(
.data = NULL,
weights = NULL,
n = NULL,
x = NULL,
conf = 0.95,
sims = 5000,
random = FALSE
)
```

## Arguments

- .data
data frame to optionally pipe in

`dplyr`

-style (see example).- weights
vector of sample weights used to adjust the sample (optional if

`n`

or`x`

is specified).- n
the sample size of the suvrey (not needed if

`weights`

or`x`

is specified).- x
the particular question to estimate margin of error for (if not specified, estimate the survey's MOE instead).

- conf
the level of statistical confidence to estimate the error.

- sims
number of bootstrap re-samples to perform in order to simulate the sampling distribution.

- random
whether or not to return different, random estimates every time.

## Value

The survey margin of error (MOE) or "modeled error" for the overall survey or question of interest.

## Details

For a single question: given a vector of sample responses and/or weights, the margin of error estimates the margin of error by simulating the sampling distribution.

Estimates via simulation tend to be more conservative (larger) than
using the formulaic margin of error (`est_modeled_error`

) as it incorporates
more variance from the weights.

This method is recommended for non-probability surveys with unknown sampling mechanisms (e.g. river samples).

## Examples

```
data(ev22)
if (FALSE) { ## not run
# Unweighted maximum margin of error
simu_moe(n = nrow(ev22))
simu_moe(weights = rep(1, nrow(ev22)))
# Weighted maximum margin of error
simu_moe(weights = ev22$weight_genpop)
# Unweighted margin of error for specific question
simu_moe(x = ev22$ev_heard_1)
# Weighted margin of error for specific question
ev22 %>%
filter(!is.na(weight_genpop)) %>%
simu_moe(x = ev_heard_1, weights = weight_genpop)
}
```