simq: simq

Description Usage Arguments Value Examples

View source: R/simq.R

Description

Simulate quantiles for a sample estimator

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
simq(
  estimator = function(x) mean(x),
  reps = 30,
  sims = 10000,
  frame = 1:100,
  ref_samp,
  lowp = 0.025,
  highp = 0.975,
  replace = TRUE,
  main = "Distribution of Samples",
  xlab = "Sample Estimates",
  ylab = "Frequency",
  breaks = 20
)

Arguments

estimator

Anonymous function defining estimator of interest

reps

Number of samples per iteration of simulation

sims

Number of iteration in simulation

frame

Sampling frame from which to draw sample

ref_samp

A reference sample (reference sample estimate is blue abline in histogram)

lowp

Lower percentile in stats::quantile(.,probs=c(lowp,highp)) function (left red abline in histogram)

highp

Higher percentile in stats::quantile(.,probs=c(lowp,highp)) function (right red abline in histogram)

replace

Parameter for base::sample

main

Histogram title

xlab

Histogram x-axis label

ylab

Histogram y-axis label

breaks

Histogram breakpoints

Value

A list with two objecs: 1) Return the requested quantiles from "sims" iterations of the simulation and 2) Histogram with reference ablines with references for lowp, highp, and ref_samp over "sims" iterations of the simulation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#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 Practice Tests", xlab = "Sample Means")

#Get requested quantiles
getqs$quantiles

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

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