Learn R Programming

idefix (version 0.2.4)

SurveyApp: 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, buttons.text,
  intro.text, end.text, data.dir = NULL, c.lvls = NULL, crit = NULL,
  alt.cte = NULL, prior.mean = NULL, prior.covar = NULL,
  cand.set = NULL, m = NULL)

Arguments

des

A design matrix in which each row is a profile. Can be generated with Modfed

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.

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 attributelevels for each continuous attribute. The default is NULL.

crit

A string containing eihter KL or DB indicating the adaptive criterion to be used.

alt.cte

A binary vector indicating for each alternative if an alternative specific constant is present. 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.

m

Numeric value. Number of draws = base^m.

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.

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, but is not necesarry.

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.

Whenever adaptive sets will be generated, crit, prior.mean, prior.covar, cand.set and m, should be specified.

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 number of draws sampeled from the posterior preference distribution in the importance sampling algorithm used for adaptive sets can be specified with m, where the number is 2^m.

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.

References

crabbemnldes

Examples

Run this code
# NOT RUN {
#### Present choice design without adaptive sets (n.total = sets in des)
# NOTE that the data will be saved in the current working directory. 
# 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,
          data.dir = dataDir)
# Data 
data_num <- LoadData(data.dir = dataDir, type  = "num")
data_char <- LoadData(data.dir = dataDir, type = "char")

#### Present choice design with adaptive sets (n.total > sets in des)
# NOTE that the data will be saved in the current working directory. 
# 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 = 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, data.dir = dataDir, crit= "KL",
prior.mean = p.mean, prior.covar = p.var, cand.set = cand, m = 6)
# Data 
data_num <- LoadData(data.dir = dataDir, type = "num")
data_char <- LoadData(data.dir = dataDir, type = "char")

#### Choice design with only adaptive sets (des=NULL)
# NOTE that the data will be saved in the current working directory. 
# setting for adaptive sets 
levels <- c(3, 3, 3)
p.mean <- c(0.3, 0.7, 0.3, 0.7, 0.3, 0.7)
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, data.dir = dataDir, 
          crit= "KL", prior.mean = p.mean, prior.covar = p.var, cand.set = cand, m = 6)
# Data 
data_num <- LoadData(data.dir = dataDir, type = "num")
data_char <- LoadData(data.dir = dataDir, type = "char")
# }

Run the code above in your browser using DataLab