View source: R/power_calculation.R
power_calc | R Documentation |
Calculates power in a binomial experiment setting, given a sample size, true_prob, requirement, and significance level.
power_calc( sample_size, true_prob, requirement, requirement_type = "gt", alpha, interval_type = "ws", AC_type = "medium", prq_delta = NA )
sample_size |
the total sample size |
true_prob |
the true underlying probability of success |
requirement |
the required underlying probability of success |
requirement_type |
defaults to "gt" (greater than). Can be set to "lt" (less than) |
alpha |
the significance level for a two-sided interval |
interval_type |
defaults to "ws" (wilson_score). Can be set to "cp " (Clopper-Pearson) |
AC_type |
specifies the acceptance criteria to be used. Defaults to "medium" (point estimate surpasses requirement). Can be set to "low" (interval includes or surpasses req), "high" (interval surpasses requirement), or "high_delta" (interval surpasses prq_delta and point estimate surpasses requirement) |
prq_delta |
defaults to NA. A numeric value here indicates the minimum acceptable acceptance criteria (product requirement plus/minus some delta). Only used if AC_type = "high_delta" |
list containing parameters of power calculation (float), df of power calculation results, and power (float)
lapply(c(.990, .985, .980), FUN = function(x) sapply( possible_sample_sizes, FUN = function(y) power_calc(sample_size = y, true_prob = x, requirement=desired_sensitivity, alpha=significance_level*2, requirement_type="gt", interval_type="cp", AC_type="low")$power )) -> sens_calculations ggplot( data.frame( n = possible_sample_sizes, sens_990_power=sens_calculations[[1]], sens_985_power=sens_calculations[[2]], sens_980_power=sens_calculations[[3]] )) + geom_line(mapping=aes(x=n, y=sens_990_power, color = "true_sens_990")) + geom_line(mapping=aes(x=n, y=sens_985_power, color = "true_sens_985")) + geom_line(mapping=aes(x=n, y=sens_980_power, color = "true_sens_980")) + scale_color_manual(name="plates", values = c(true_sens_990="dodgerblue1", true_sens_985="firebrick", true_sens_980="forestgreen"), breaks = c("true_sens_990", "true_sens_985", "true_sens_980")) + labs(title="Detecting Deviation in Sensitivity from p=.995", x="n", y="Power") + theme_bw()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.