sampleSizer.Rd
This function allows you to estimate a model on a design of experiment
that you have not yet used to collect data. This allows you to learn
about deficiencies in your design of experiment and also assess the sample
size needed to achieve parameter precision levels before you go out and
use the design to collect data. The function fills out the survey with
random choices and estimates a model. It does this multiple times with an
increasing number of observations, set by the nbreaks
argument. While the
coefficients in those models are meaningless, the standard errors on the
coefficients are informative. The example below estimates 10 separate models
and then plots the standard errors against the number of observations. In
this example, assume that the yogurt data was not a completed survey but
rather a blank design of experiment with no observed choices.
sampleSizer( survey, parNames = NULL, parTypes = NULL, interactions = FALSE, nbreaks = 10, randPars = NULL, options = list(message = FALSE) )
survey | The choice survey data frame exported from the |
---|---|
parNames | A vector of the names of the parameters to be estimated in the model. Must be the same as the column names in the |
parTypes | A vector determining the type of each variable: "c" for continuous, or "d" for discrete. Continuous variables will be linearly coded whereas discrete variables will be dummy coded with one level removed for identification. Defaults to |
interactions | A logical value for adding interactions between all parameters in |
nbreaks | The number of different sample size groups. |
randPars | A named vector whose names are the random parameters and values the distribution: |
options | A list of options to control the model estimation. |
Returns a data frame of the standard error values for different sample sizes.
if (FALSE) { library(conjointTools) # A simple conjoint experiment about apples, with one attribute (price) # modeled as continuous # Make the design of experiment doe <- makeDoe( levels = c(3, 3, 3), varNames = c("price", "type", "freshness"), type = "full" ) # Make the survey survey <- makeSurvey( doe = doe, # Design of experiment nResp = 1000, # Total number of respondents (upper bound) nAltsPerQ = 3, # Number of alternatives per question nQPerResp = 6 # Number of questions per respondent ) # Compute sample sizes results <- sampleSizer( survey = survey, parNames = c('price', 'type', 'freshness'), parTypes = c('c', 'd', 'd'), # Set continuous vs. discrete variables nbreaks = 10 ) # Preview results head(results) # Plot results library(ggplot2) ggplot(results) + geom_point(aes(x = size, y = se, color = coef), fill = "white", pch = 21) + scale_y_continuous(limits = c(0, NA)) + labs(x = 'Number of observations', y = 'Standard Error', color = "Variable") + theme_bw() }