README.md

MeghaMCSE

The goal of MeghaMCSE is to caclulate performance criteria measures such as bias, relative bias, mean squared error, root mean squared error etc. for results from simulation studies. In addition to calculating the performance measures, the package also calculates associated Monte Carlo Standard Errors.

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("meghapsimatrix/MeghaMCSE")

Example

This is a basic example which shows you how to solve a common problem:

library(MeghaMCSE)

library(tidyverse)
library(broom)
library(kableExtra)

set.seed(20191228)

# function to create normally distributed data for each group to run t test

generate_dat <- function(n = 50, effect_x){

  dat <- tibble(group_1 = rnorm(n, 0, 1), 
                group_2 = rnorm(n, effect_x, 1))

  return(dat)

}


# function to calculate t-test, pulls out estimate of the mean difference, p val and ci 

estimate_t <- function(sim_dat){

  res <- tidy(t.test(sim_dat$group_2, sim_dat$group_1)) %>%
    select(estimate, p_val = p.value, ci_low = conf.low, ci_high = conf.high)

  return(res)

}


# generating 1000 iterations

results <- 
  rerun(1000, {
    dat <- generate_dat(effect_x = .5)
    estimate_t(dat)
  }) %>%
  bind_rows()


# running calc_mcse

calc_mcse(estimates = results$estimate, true_param = .5, K = nrow(results), perfm_criteria = c("bias", "variance", "mse", "rmse", "relative bias", "relative mse"))
#>           bias    bias_mcse        var    var_mcse       mse    mse_mcse
#> 1 -0.002331351 4.068566e-05 0.04068566 0.001834095 0.0406911 0.001831553
#>        rmse   rmse_mcse  rel_bias rel_bias_mcse   rel_mse rel_mse_mcse
#> 1 0.2017203 0.004539833 0.9953373    0.01275706 0.1627644 0.0009157767


calc_mcse(estimates = results$p_val, true_param = .5, alpha = .05, K = nrow(results), lower_bound = results$ci_low, upper_bound = results$ci_high, perfm_criteria = c("rejection rate", "coverage", "width"))
#>   rej_rate rej_rate_mcse coverage coverage_mcse     width  width_mcse
#> 1    0.688    0.01465114    0.951   0.006892024 0.7914277 0.001793593


meghapsimatrix/MeghaMCSE documentation built on Jan. 2, 2020, 2:56 a.m.