summarize.sims: Summarize a simulation study

Description Usage Arguments Examples

Description

Summarize a simulation study where we have a matrix of parameter values that we are interested.

Usage

1
2
summarize.sims(summary.function, Params, sim.directory = "./sim_directory",
  ...)

Arguments

summary.function

A function to summarize a single simulation into a vector of output statistics.

sim.directory

The local directory to store the simulation results.

params

A data frame of parameter values. This should be the same data frame as was used to create the simulation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Simulation is creating data and fitting
# a regression model to estimate a slope.
Sim.Function <- function(N, alpha, beta, sigma){
  x <- runif(N, 0, 10)
  y <- alpha + beta*x + rnorm(N, 0, sigma)
  model <- lm(y~x)
  return(model)
}

# Create a matrix where each row represents a set of parameters
Params <- expand.grid(N=20, alpha=0, beta=c(0,1), sigma=c(.2, 1))

# Run the simulations.
run.sims(Sim.Function, Params, num.reps=10)

# Now that the simulations are run, we want to analyze
# them.  Create a function to be applied to each simulation
# that results in a single row.  Those rows will be concatenated
# together into a large data frame that summarizes the simulation.

# Because the output of the Sim.Function was a linear model output,
# that is the input for this function
Summary.Function <- function(model, params){
  beta.hat <- coef(model)[2]
  beta.lwr <- confint(model)[2,1]
  beta.upr <- confint(model)[2,2]
  return( data.frame(beta=beta.hat, lwr=beta.lwr, upr=beta.upr))
}

Sims <- summarize.sims(Summary.Function, Params)

dereksonderegger/Simulations2 documentation built on May 15, 2019, 3:59 a.m.