# Optical density solution


Find this notebook on the web at
<a class="quarto-xref" href="https://resampling-stats.github.io/edition-3-r/exercise_solutions.html#nte-optical_density_solution">Note <span>A.5</span></a>.

Suppose we have 10 measurements of Optical Density on a batch of HIV
negative control samples:

```{r}
density <- c(.02, .026, .023, .017, .022, .019, .018, .018, .017, .022)
```

Derive a 95 percent confidence interval for the sample mean. Are there
enough measurements to produce a satisfactory answer?

```{r}
n_density <- length(density)

n_trials <- 10000
results <- numeric(n_trials)

for (i in 1:n_trials) {
    fake_density <- sample(density, size=n_density, replace=TRUE)
    results[i] <- mean(fake_density)
}

hist(results, breaks=25,
    main='Bootstrap distribution of density means',
    xlab='Bootstrap density means')

mean_limits <- quantile(results, c(0.025, 0.975))
rounded <- round(mean_limits, 3)
message('95% percent limits for density mean: ',
        rounded[1], ' ', rounded[2])
```
