tidy_mc_latex {tidyMC}R Documentation

Create a 'LaTeX' table with the summarized results of a Monte Carlo Simulation

Description

Create a 'LaTeX' table containing the summarized results of a Monte Carlo simulation run by future_mc() and summarized by summary.mc().

Usage

tidy_mc_latex(
  x,
  repetitions_set = NULL,
  which_setup = NULL,
  parameter_comb = NULL,
  which_out = NULL,
  kable_options = NULL
)

Arguments

x

An object of class summary.mc. For restrictions see details.

repetitions_set

A vector of integers specifying at which repetitions the summarized results should be displayed in the table. Default: The argument repetitions in future_mc(), which means that the summarized results after the last repetition are displayed in the table.

which_setup

A character vector containing the nice_names for the different parameter combinations (returned by future_mc()), which should be presented in the table. Default: All parameter combinations are presented.

parameter_comb

Alternative to which_setup. A named list whose components are named after (some of) the parameters in param_list in future_mc(). Each component is a vector containing the values for the parameters to be filtered by. Default: All parameter combinations are presented.

which_out

A character vector containing the names of (some of) the named outputs (the names of the returned list of fun in future_mc()), which should be displayed in the table. Default: All outputs are displayed.

kable_options

A list whose components are named after possible parameters of kableExtra::kbl() customizing the generated table.

Details

Only one of the arguments which_setup and parameter_comb can be specified at one time.

Only (output - parameter combination)-pairs for which the summary function specified in the sum_funs argument of summary.mc() returns a single scalar value appear as non-NA values in the 'LaTeX' table. If a specific output is summarized with functions that do not return a single numeric value over all parameter combinations, then this output is discarded from the table. Similarly, if for a specific parameter combination all fun outputs are summarized with functions which do not return a single numeric value, then this parameter combination is discarded as well. In summary, all outputs must be summarized with functions which return just one numeric value.

Value

An object of class knitr_kable which can be modified by the functions in the kableExtra package is returned.

Examples

test_func <- function(param = 0.1, n = 100, x1 = 1, x2 = 2) {
  data <- rnorm(n, mean = param) + x1 + x2
  stat <- mean(data)
  stat_2 <- var(data)

  if (x2 == 5) {
    stop("x2 can't be 5!")
  }

  return(list(mean = stat, var = stat_2))
}

param_list <- list(
  param = seq(from = 0, to = 1, by = 0.5),
  x1 = 1:2
)

test_mc <- future_mc(
  fun = test_func,
  repetitions = 1000,
  param_list = param_list,
  n = 10,
  x2 = 2
)

tidy_mc_latex(summary(test_mc))

set.seed(101)
tidy_mc_latex(
  summary(test_mc),
  repetitions_set = c(10, 1000),
  which_out = "mean",
  kable_options = list(caption = "Mean MCS results")
)


[Package tidyMC version 1.0.0 Index]