# The following lines of code synthesize responses to Case 1 BWS questions,
# return them in detailed and simple format, and then fit the models using
# the function clogit in the survival package. The questions evaluate seven
# items. The choice sets consist of seven questions with four items each.
# The function find.BIB in the crossdes package creates the corresponding
# BIBD with seven treatments, seven blocks, and size four. The systematic
# component of the utility for items is the same as that explained in the
# Details section.
if (FALSE) {
# Load packages
library(survival)
library(crossdes)
# Generate BIBD
set.seed(123)
bibd <- find.BIB(trt = 7, b = 7, k = 4)
isGYD(bibd)
bibd
# Synthesize responses to Case 1 BWS questions
b <- c(0.5, 1.2, 1.6, 1.8, 2.1, 0, 0.9)
items = c("A", "B", "C", "D", "E", "F", "G")
dat.detail <- bws.response(
design = bibd, item.names = items,
b = b, n = 100,
detail = TRUE, seed = 123)
str(dat.detail)
dat.simple <- bws.response(
design = bibd,
b = b, n = 100,
detail = FALSE, seed = 123)
str(dat.simple)
# Convert dat.simple into dataset for the analysis
response.vars <- colnames(dat.simple)[-1]
dat.simple.md <- bws.dataset(
respondent.dataset = dat.simple,
response.type = 1,
choice.sets = bibd,
design.type = 2,
item.names = items,
id = "id",
response = response.vars,
model = "maxdiff")
# Fit conditional logit models
mf <- RES ~ A + B + C + D + E + G + strata(STR)
out.detail <- clogit(mf, dat.detail)
out.simple <- clogit(mf, dat.simple.md)
out.simple
all.equal(coef(out.detail), coef(out.simple))
}
Run the code above in your browser using DataLab