Parameters

FUN <- rnorm
n <- 10000
mu <- 100
sigma <- 15
args <- list(
  n = rep(
    x = n,
    times = 10000
  ),
  mean = mu,
  sd = sigma
)
par <- FALSE
ncores <- NULL
Variable <- c(
  "`FUN`",
  "`n`",
  "`mu` named as `mean` in `args`.",
  "`sigma` named as `sd` in `args`."
)
Description <- c(
  "Function.",
  "Number of observations.",
  "Population mean $\\left( \\mu \\right)$.",
  "Standard deviation $\\left( \\sigma \\right)$."
)
Value <- c(
  "`rnorm`",
  n,
  mu,
  sigma
)
knitr::kable(
  x = data.frame(
    Variable,
    Description,
    Value
  ),
  row.names = FALSE
)
Variable Description Value
FUN Function. rnorm
n Number of observations. 10000
mu named as mean in args. Population mean \(\left( \mu \right)\). 100
sigma named as sd in args. Standard deviation \(\left( \sigma \right)\). 15

Run test

sample <- util_lapply(
  FUN = FUN,
  args = args,
  par = par,
  ncores = ncores
)
sample_means <- unlist(
  util_lapply(
    FUN = mean,
    args = c(x = sample),
    par = par,
    ncores = ncores
  )
)
mean_of_means <- mean(sample_means)
mean_of_ns <- mean(
  lengths(sample)
)

Results

Description <- c(
  "Sample size.",
  "Mean of means."
)
Parameter <- c(
  n,
  mu
)
Result <- c(
  mean_of_ns,
  mean_of_means
)
knitr::kable(
  x = data.frame(
    Description,
    Parameter,
    Result
  ),
  row.names = FALSE
)
Description Parameter Result
Sample size. 10000 10000.00000
Mean of means. 100 99.74345
test_that("sample size used is correct", {
  expect_equivalent(
    mean_of_ns,
    n
  )
})
#> Test passed 🥳
test_that("the mean of means converges to the population mean", {
  expect_equivalent(
    round(
      x = mean_of_means,
      digits = 0
    ),
    mu,
  )
})
#> Test passed 🥇