pc_sa: Partial Correlation Analysis of a Simulation Model

Description Usage Arguments Details Value References Examples

Description

pc_sa conducts a partial correlation analysis.

Usage

1
2
3
4
5
pc_sa(abm, input_values, out = "action_avg", sample_count = 100,
  constraints = "none", nboot = 1000, previous_pc_sa = NULL,
  model_data = NULL, iterations = NULL, parallel = FALSE, cores = NULL,
  verbose = TRUE, extra_verbose = FALSE, rank = TRUE, method = c("src",
  "pcc"))

Arguments

abm

A function that takes each of the input_values as arguments.

input_values

List

out

Optional Character vector length one to be passed an argument to the abm function to specify what outcome measure to use.

sample_count

Optional Numeric vector length one. Default is 100.

constraints

Optional Character vector that is either "none" or is using only variable names that are specified in the input_values List argument. This character vector is evaluated in an environment created for the sampled data on the variables, and its evaluation results in a Logical vector that that subsets sampled.

nboot

Optional Numeric vector length one. Default is 1000.

previous_pc_sa

Optional list where each element is an S4 object created by using this function to previously run this analysis. The main use case is when the previous analysis shows that we need to run more simulations to reduce the uncertainty in the estimates. If this is provided, the simulation outputs and the design matrix of parameter inputs will be addde to the outputs and inputs used by the current call of the function and then the sensitivity analysis will be computed with the previous and current results.

model_data

Optional data.frame with the data that was used to build the model. This is used if one wants to ensure that all parameters tested are in the convex hull of the data used to build the model that is now being analyzed. This uses the WhatIf package in the Suggest field of the eat description file.

iterations

Optional numeric vector length one.

parallel

Optional logical vector length one. Default is FALSE.

cores

Optional Numeric vector length one. Default is parallel::detectCores().

verbose

Optional logical vector.

extra_verbose

Optional logical vector, default is FALSE.

rank

Optional logical vector.

method

Optional character vector that is either "src" (Standardized Regression Coefficient) or "pcc" (Partial Correlation Coefficient)

Details

This is function of the eat package. It takes a simulation model in function form and a list of input values. Helper function for extracting R-sqaured is adapted from Thiele et al. (2014).

Value

Returns a sensitivity object that can be plotted by functions.

References

G. Pujol et al., Sensitivity: Sensitivity Analysis (2014), (available at http://cran.r-project.org/web/packages/sensitivity/index.html).

A. Saltelli, K. Chan, E. M. Scott, Sensitivity Analysis (Wiley, Chichester, 2009).

J. C. Thiele, W. Kurth, V. Grimm, Facilitating Parameter Estimation and Sensitivity Analysis of Agent-Based Models: A Cookbook Using NetLogo and R. Journal of Artificial Societies and Social Simulation. 17, 11 (2014).

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
# Unconstrained Analysis
fake_abm <- function(params, out) {
  x1 <- params[1]
  x2 <- params[2]
  if (out=="sq") return(x1^2 + x2 + rnorm(1, 0))
  if (out=="ident") return(x1 + x2 + rnorm(1, 0))
}
inputs <- lapply(list(param1 = NA, param2 = NA), 
                 function(x) list(random_function = "qunif",
                                  ARGS = list(min = 0, max = 1)))
pc_sa(fake_abm, inputs, "sq")
pc_sa(fake_abm, inputs, "sq", method = "pcc", rank = FALSE)
res <- pc_sa(fake_abm, inputs, "sq", method = "src")
plot(res); res@r_squared

# Constrained Analysis
fake_abm <- function(params, out) {
  x1 <- params[1]
  x2 <- params[2]
  if (out=="sq") return(x1^2 + x2 + rnorm(1, 0))
  if (out=="ident") return(x1 + x2 + rnorm(1, 0))
}
inputs <- lapply(list(param1 = NA, param2 = NA), 
                 function(x) list(random_function = "qunif",
                                  ARGS = list(min = 0, max = 1)))
res <- pc_sa(fake_abm, inputs, "sq", constraints = "param1 > 0.1 & param2 < 0.9")

JohnNay/sa documentation built on May 7, 2019, 12:01 p.m.