simtest: SimTest

Description Usage Arguments Value Examples

View source: R/simtest.R

Description

Use Monte Carlo Simulation on anonymous test function

Usage

1
2
3
4
5
6
7
simtest(
  test = function(x) sum(x) >= 3,
  on = c(0, 1),
  reps = 10,
  sims = 10^2,
  replace = TRUE
)

Arguments

test

An anonymous test function

on

A vector of values to sample from

reps

The number of samples for each iteration of test

sims

The number of test iterations

replace

Replace argument from the base R function: sample(x, size, replace = FALSE, prob = NULL)

Value

A vector with test results for "sims" iterations of the test

Examples

1
2
3
4
5
6
7
#The default settings of simtest checks whether reps = 10 samples from
#"on = c(0, 1)" returns a value of "1" three or more times.  This can be thought of
#as a test for whether flipping a coin 10 times returns heads three or more times.
#Example and function inspired from A Beginner's Guide to Monte Carlo Simulations
#presented by Dan Uehara for UseR Oslo: https://www.youtube.com/watch?v=g2Uu9m0IlFE
coinflips <- simtest()
mean(coinflips)

mncube/simboil documentation built on Dec. 21, 2021, 8:07 p.m.