#' @name cjpwr
#'
#' @rdname cjpwr
#' @title Simple Power Analysis and Sample Size Diagnostic for Conjoint Designs
#' @description Johnson's rule-of-thumb calculation for determining power of conjoint designs.
#' @param n The sample size (defaults to 100 for when you're only interested in finding out necessary value of n and don't know what to specify).
#' @param t The number of choice-tasks per respondent.
#' @param a The number of alternatives per choice task (defaults to two).
#' @param c The number of analysis cells - equal to largest number of possible levels for any one feature, or the largest product of levels of any two attributes for power of two-way interaction estimates (Johnson and Orme, 2003).
#' @details \code{cjpwr} divides the product of n, t, and a by c, to give Johnson's rule-of-thumb estimation of conjoint design power. It returns a dataframe containing the inputs and result of this calculation, whether (yes/no) this exceeds the minimal minimum threshold (500) and ideal minimum threshold (1000), and the sample sizes (rounded up) necessary for minimum and ideal power thresholds.
#' @export
#' @examples
#' #conjoint design with five choice tasks per respondent, two alternative profiles per task, and maximum six levels per feature
#' cjpwr(n = 1000, t = 5, a = 2, c = 6)
#' #same design but considering interactions, where largest product of levels of any two attributes is 18 (6*3)
#' cjpwr(n = 1000, t = 5, a = 2, c = 18)
#' #without argument labels, order only matters for c
#' cjpwr(5, 1000, 2, 18)
#' cjpwr(5, c = 18, 1000, 2)
#' cjpwr(c = 18, n = 1000, a = 2, t = 5)
#' #with defaults
#' cjpwr(t = 5, c = 18)
#' @seealso \code{\link{pwr_n}}
cjpwr <-
function(n = 100, t, a = 2, c) {
nta <- n*t*a
#calculate figure to be compared against 500 and 1000
design_rep <- nta/c
#set up calculation to check for necessary n
ta <- t * a
min_c <- 500 * c
max_c <- 1000 * c
#calculate minimum sample size, rounded up, for minimal threshold
min_n <- ceiling(min_c / ta)
#calculate minimum sample size, rounded up, for ideal threshold
max_n <- ceiling(max_c / ta)
#return dataframe of results
data.frame(n = n,
t = t,
a = a,
c = c,
nta_c = design_rep,
minimum_sufficient = ifelse(design_rep >= 500, "yes", "no"),
ideal_sufficient = ifelse(design_rep >= 1000, "yes", "no"),
minimum_n = min_n,
ideal_n = max_n)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.