# The following example is based on the dataset rice.
# The choice sets differ from those in the dataset rice.
library(survival)
dsgn.rice <- rotation.design(
attribute.names = list(
Region = c("RegA", "RegB", "RegC"),
Cultivation = c("Conv", "NoChem", "Organic"),
Price = c("1700", "2000", "2300")),
nalternatives = 2,
nblocks = 3,
row.renames = FALSE,
randomize = TRUE,
seed = 987)
syn.rice1 <- ce.response(
design = dsgn.rice,
categorical.attributes = c("Region", "Cultivation"),
continuous.attributes = "Price",
optout = TRUE,
b = c(4.4, 0.47, 0.97, 0.66, 1.1, -0.0023),
n = 99,
detail = TRUE,
seed = 1)
head(syn.rice1, 30)
mf <- RES ~ ASC + RegB + RegC + NoChem + Organic + Price + strata(STR)
(out1 <- clogit(mf, data = syn.rice1))
syn.rice.simple <- ce.response(
design = dsgn.rice,
categorical.attributes = c("Region", "Cultivation"),
continuous.attributes = "Price",
optout = TRUE,
b = c(4.4, 0.47, 0.97, 0.66, 1.1, -0.0023),
n = 99,
detail = FALSE,
seed = 1)
head(syn.rice.simple)
dsgnmat.rice <- make.design.matrix(
choice.experiment.design = dsgn.rice,
optout = TRUE,
categorical.attributes = c("Region", "Cultivation"),
continuous.attributes = c("Price"),
unlabeled = TRUE)
syn.rice2 <- make.dataset(
respondent.dataset = syn.rice.simple,
choice.indicators =
c("q1", "q2", "q3"),
design.matrix = dsgnmat.rice)
(out2 <- clogit(mf, data = syn.rice2))
all.equal(coef(out1), coef(out2))
Run the code above in your browser using DataLab