SurveyApp: Shiny application to generate a discrete choice survey.

View source: R/shiny_support.R

SurveyAppR Documentation

Shiny application to generate a discrete choice survey.

Description

This function starts a shiny application which puts choice sets on screen and saves the responses. The complete choice design can be provided in advance, or can be generated sequentially adaptively, or can be a combination of both.

Usage

SurveyApp(
  des = NULL,
  n.total,
  alts,
  atts,
  lvl.names,
  coding,
  alt.cte = NULL,
  no.choice = NULL,
  buttons.text,
  intro.text,
  end.text,
  data.dir = NULL,
  c.lvls = NULL,
  prior.mean = NULL,
  prior.covar = NULL,
  cand.set = NULL,
  n.draws = NULL,
  lower = NULL,
  upper = NULL,
  parallel = TRUE,
  reduce = TRUE
)

Arguments

des

A numeric matrix which represents the design matrix. Each row is a profile.

n.total

A numeric value indicating the total number of choice sets.

alts

A character vector containing the names of the alternatives.

atts

A character vector containing the names of the attributes.

lvl.names

A list containing character vectors with the values of each level of each attribute.

coding

A character vector denoting the type of coding used for each attribute. See also Profiles.

alt.cte

A binary vector indicating for each alternative if an alternative specific constant is present. The default is NULL.

no.choice

An integer indicating which alternative should be a no choice alternative. The default is NULL.

buttons.text

A string containing the text presented together with the option buttons.

intro.text

A string containing the text presented before the choice survey.

end.text

A string containing the text presented after the choice survey.

data.dir

A character string with the directory denoting where the data needs to be written. The default is NULL

c.lvls

A list containing numeric vectors with the attribute levels for each continuous attribute. The default is NULL.

prior.mean

Numeric vector indicating the mean of the multivariate normal distribution (prior).

prior.covar

Covariance matrix of the prior distribution.

cand.set

A numeric matrix in which each row is a possible profile. The Profiles function can be used to generate this matrix.

n.draws

Numeric value indicating the number of draws.

lower

Numeric vector of lower truncation points, the default is NULL.

upper

Numeric vector of upper truncation points, the default is NULL.

parallel

Logical value indicating whether computations should be done over multiple cores. The default is TRUE.

reduce

Logical value indicating whether the candidate set should be reduced or not.

Details

A pregenerated design can be specified in des. This should be a matrix in which each row is a profile. This can be generated with Modfed or CEA, but it is not necessary.

If n.total = nrow(des) / length(alts), the specified design will be put on screen, one set after the other, and the responses will be saved. If n.total > (nrow(des) / length(alts)), first the specified design will be shown and afterwards the remaining sets will be generated adaptively. If des = NULL, n.total sets will be generated adaptively. See SeqMOD for more information on adaptive choice sets.

Whenever adaptive sets will be generated, prior.mean, prior.covar, cand.set and n.draws, should be specified. These arguments are necessary for the underlying importance sampling algorithm to update the prior preference distribution. lower and upper can be used to specify lower and upper truncation points. See ImpsampMNL for more details.

The names specified in alts will be used to label the choice alternatives. The names specified in atts will be used to name the attributes in the choice sets. The values of lvl.names will be used to create the values in the choice sets. See Decode for more details.

The text specified in buttons.text will be displayed above the buttons to indicate the preferred choice (for example: "indicate your preferred choice"). The text specified in intro.text will be displayed before the choice sets. This will generally be a description of the survey and some instructions. The text specified in end.text will be displayed after the survey. This will generally be a thanking note and some further instructions.

A no choice alternative is coded as an alternative with 1 alternative specific constant and zero's for all other attribute levels. If a no choice alternative is present in des, or is desired when generating adaptive choice sets, no.choice should be specified. This should be done with an integer, indicating which alternative is the no choice option. This alternative will not be presented on screen, but the option to select "no choice" will be. The alt.cte argument should be specified accordingly, namely with a 1 on the location of the no.choice option. See examples for illustration.

When parallel is TRUE, detectCores will be used to decide upon the number of available cores. That number minus 1 cores will be used to search for the optimal adaptive choice set. For small problems (6 parameters), parallel = TRUE can be slower. For larger problems the computation time will decrease significantly.

When reduce = TRUE, the set of all potential choice sets will be reduced to choice sets that have a unique information matrix. If no alternative specific constants are used, reduce should always be TRUE. When alternative specific constants are used reduce can be TRUE so that the algorithm will be faster, but the combinations of constants and profiles will not be evaluated exhaustively.

Value

After completing the survey, two text files can be found in data.dir. The file with "num" in the filename is a matrix with the numeric choice data. The coded design matrix ("par"), presented during the survey, together with the observed responses ("resp") can be found here. Rownames indicate the setnumbers. The file with "char" in the filename is a matrix with character choice data. The labeled design matrix ("par"), presented during the survey, together with the observed responses ("resp") can be found here. See LoadData to load the data.

References

\insertRef

juidefix

Examples

## Not run: 
#### Present choice design without adaptive sets (n.total = sets in des)
# example design 
data("example_design") # pregenerated design
xdes <- example_design
### settings of the design 
code <- c("D", "D", "D")
n.sets <- 8
# settings of the survey
alternatives <- c("Alternative A", "Alternative B")
attributes <- c("Price", "Time", "Comfort")
labels <- vector(mode="list", length(attributes))
labels[[1]] <- c("$10", "$5", "$1")
labels[[2]] <- c("20 min", "12 min", "3 min")
labels[[3]] <- c("bad", "average", "good")
i.text <- "Welcome, here are some instructions ... good luck!"
b.text <- "Please choose the alternative you prefer"
e.text <- "Thanks for taking the survey"
dataDir <- getwd()
# Display the survey 
SurveyApp (des = xdes, n.total = n.sets, alts = alternatives, 
          atts = attributes, lvl.names = labels, coding = code, 
          buttons.text = b.text, intro.text = i.text, end.text = e.text)

#### Present choice design with partly adaptive sets (n.total > sets in des)
# example design 
data("example_design") # pregenerated design
xdes <- example_design
### settings of the design 
code <- c("D", "D", "D")
n.sets <- 12
# settings of the survey
alternatives <- c("Alternative A", "Alternative B")
attributes <- c("Price", "Time", "Comfort")
labels <- vector(mode="list", length(attributes))
labels[[1]] <- c("$10", "$5", "$1")
labels[[2]] <- c("20 min", "12 min", "3 min")
labels[[3]] <- c("bad", "average", "good")
i.text <- "Welcome, here are some instructions ... good luck!"
b.text <- "Please choose the alternative you prefer"
e.text <- "Thanks for taking the survey"
# setting for adaptive sets 
levels <- c(3, 3, 3)
cand <- Profiles(lvls = levels, coding = code)
p.mean <- c(0.3, 0.7, 0.3, 0.7, 0.3, 0.7)
p.var <- diag(length(p.mean))
dataDir <- getwd()
# Display the survey 
SurveyApp(des = xdes, n.total = n.sets, alts = alternatives, 
          atts = attributes, lvl.names = labels, coding = code, 
          buttons.text = b.text, intro.text = i.text, end.text = e.text, 
          prior.mean = p.mean, prior.covar = p.var, cand.set = cand, 
          n.draws = 50)
          
#### Choice design with only adaptive sets (des=NULL)
# setting for adaptive sets 
levels <- c(3, 3, 3)
p.mean <- c(0.3, 0.7, 0.3, 0.7, 0.3, 0.7)
low = c(-Inf, -Inf, -Inf, 0, 0, -Inf)
up = rep(Inf, length(p.mean))
p.var <- diag(length(p.mean)) 
code <- c("D", "D", "D")
cand <- Profiles(lvls = levels, coding = code)
n.sets <- 12
# settings of the survey
alternatives <- c("Alternative A", "Alternative B")
attributes <- c("Price", "Time", "Comfort")
labels <- vector(mode="list", length(attributes))
labels[[1]] <- c("$10", "$5", "$1")
labels[[2]] <- c("20 min", "12 min", "3 min")
labels[[3]] <- c("bad", "average", "good")
i.text <- "Welcome, here are some instructions ... good luck!"
b.text <- "Please choose the alternative you prefer"
e.text <- "Thanks for taking the survey"
dataDir <- getwd()
# Display the survey 
SurveyApp(des = NULL, n.total = n.sets, alts = alternatives,
          atts = attributes, lvl.names = labels, coding = code, 
          buttons.text = b.text, intro.text = i.text, end.text = e.text, 
          prior.mean = p.mean, prior.covar = p.var, cand.set = cand, 
          lower = low, upper = up, n.draws = 50)
# If CEA algorithm is desired, cand.set argument is not needed
SurveyApp(des = NULL, n.total = n.sets, alts = alternatives,
         atts = attributes, lvl.names = labels, coding = code, 
         buttons.text = b.text, intro.text = i.text, end.text = e.text, 
         prior.mean = p.mean, prior.covar = p.var, 
         lower = low, upper = up, n.draws = 50)
         
#### Present choice design with a no choice alternative.
# example design 
data("nochoice_design") # pregenerated design
xdes <- nochoice_design
### settings of the design 
code <- c("D", "D", "D")
n.sets <- 8
# settings of the survey
alternatives <- c("Alternative A", "Alternative B", "None")
attributes <- c("Price", "Time", "Comfort")
labels <- vector(mode = "list", length(attributes))
labels[[1]] <- c("$10", "$5", "$1")
labels[[2]] <- c("20 min", "12 min", "3 min")
labels[[3]] <- c("bad", "average", "good")
i.text <- "Welcome, here are some instructions ... good luck!"
b.text <- "Please choose the alternative you prefer"
e.text <- "Thanks for taking the survey"

# Display the survey 
SurveyApp(des = xdes, n.total = n.sets, alts = alternatives, 
          atts = attributes, lvl.names = labels, coding = code, 
          buttons.text = b.text, intro.text = i.text, end.text = e.text,
          no.choice = 3, alt.cte = c(0, 0, 1))

## End(Not run)

idefix documentation built on March 28, 2022, 5:05 p.m.