knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
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.
You can install the development version from GitHub with:
# install.packages("devtools") devtools::install_github("meghapsimatrix/MeghaMCSE")
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")) 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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.