Description Usage Arguments Value Examples
View source: R/statistical-functions.R
Calculates the expected range of n observations drawn from a distibution with standard deviation sd
1 | ExpectedRange(sd, n)
|
sd |
standard deviation |
n |
number of observations |
numeric
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ExpectedRange(5, 15)
## Not run:
library(tidyverse)
f <- function(x, n) n * x * pnorm(x)^(n - 1) * dnorm(x)
ests <- expand.grid(mean = 0, sd = 2, n = 15, rep = 1:1000, i = 1:15) %>%
mutate(rdv = rnorm(n(), mean, sd)) %>%
group_by(mean, sd, n, rep) %>%
summarise(sd_hat = sd(rdv),
obs.range = diff(range(rdv))) %>%
group_by(mean, sd, n, rep) %>%
mutate(sd.range = 2*sd_hat*integrate(f,-Inf,Inf, n = n)$value,
exp.range = ExpectedRange(sd, n))
ests %>%
gather(estimate, value, -mean, -sd, -n, -rep, -sd_hat, -exp.range) %>%
ggplot(aes(x = estimate, y = value)) +
geom_boxplot() +
geom_hline(aes(yintercept = exp.range)) +
facet_wrap(~n)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.