knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

simboil

The goal of simboil is to stream line simulation workflows. It hopes to bring simmering simmering simmering simulations to a boil.

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("mncube/simboil")

Use Monte Carlo simulation to test a condition

The default setting of simtest simulates a coin flip and tests whether 10 flips has 3 or more head (where head is defined as 1). The function and example was inspired by A Beginner's Guide to Monte Carlo Simulations presented by Dan Uehara for UseR Oslo: https://www.youtube.com/watch?v=g2Uu9m0IlFE

library(simboil)
coinflips <- simtest()
mean(coinflips)

Use simulation to get quantiles

In the example below, simq is used to compare a practice test to the test mean and standard deviation from the past 3 years

#Test scores from the new test administered over the past 3 years is not 
#available but the mean (75) and sd (14) is known
sim_scores <- as.vector(rnorm(1000, 75, 14))

#Practice test scores for low performing math class 
practice_test <- as.vector(rnorm(30, 68, 7))

#See how low performers compare to past performers

#Run simulation
getqs <- simq(frame = sim_scores, ref_samp = practice_test, 
              main = "Distribution of Past Tests", xlab = "Sample Means")

#Get requested quantiles (example uses defaults of lowp = .025, highp = .975)
getqs$quantiles

#Compare practice test to distribution of past tests
getqs$histogram

Compare the empirical cdf to the true cdf using the plots

Plot the empirical vs true cdf for the uniform distribution as follows:

evt_cdf(ylab = "Cumulative Probability", col = "blue", main = "Uniform ECDF (black) vs Uniform CDF (blue)")

To get a more accurate ECDF plot, increase the number of samples using n

evt_cdf(n = 10^5, ylab = "Cumulative Probability", col = "blue", main = "Uniform ECDF (black) vs Uniform CDF (blue)")

You can also change from the uniform distribution to other distributions such as the normal distribution by using anonymous functions

evt_cdf(n = 200, ylab = "Cumulative Probability", col = "blue", main = "Normal ECDF (black) vs Normal CDF (blue)",
        remp = function(x)stats::rnorm(x),
        ptrue = function(x)stats::pnorm(x))


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