Skip to content

Commit

Permalink
Updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelvy committed Mar 17, 2018
1 parent 926e42f commit cf819d3
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions example/example.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,11 @@ mnl.pref = logitr(
data = choiceData,
choiceName = 'choice',
obsIDName = 'obsID',
parNames = c('price', 'feat', 'dannon', 'hiland', 'yoplait'),
options = list(
numMultiStarts = 5, # Since the log-likelihood is convex for this model
# a multistart isn't really necessary
keepAllRuns = TRUE)) # By keeping all the runs, you can review the
# results of each multistart run
parNames = c('price', 'feat', 'dannon', 'hiland', 'yoplait'))

# Print a summary of all multistart runs and a summary of the best model:
# Print a summary of the results:
summary(mnl.pref)

# Print a summary of the third model run:
summary(mnl.pref$models[[3]])

# Print a summary of the best model:
summary(mnl.pref$bestModel)

# Multistart MNL model in the WTP Space:
mnl.wtp = logitr(
data = choiceData,
Expand All @@ -44,20 +33,24 @@ mnl.wtp = logitr(
priceName = 'price',
modelSpace = 'wtp',
options = list(
# You should run a multistart for WTP models since they are non-convex,
# You should run a multistart for WTP models since they are non-convex
numMultiStarts = 10,
# You can review the results of each multistart run with keepAllRuns=T
keepAllRuns = TRUE,
prefSpaceModel = mnl.pref, # If keepAllRuns=T for the prefSpaceModel,
# the best model from the multistart
# will be used for comparison.
scaleInputs = TRUE)) # Here I scale the inputs because it helps with
# stability in this case.
# Include the preference space model as an input to 1) use the computed
# WTP as the starting parameters for the first multistart run, and
# 2) compare the WTP between the two spaces.
prefSpaceModel = mnl.pref))

# Print a summary of all multistart runs and a summary of the best model:
# Note that because the prefSpaceModel argument was included in the options
# the summary will also print a comparison of the WTP between the two spaces.
summary(mnl.wtp)

# Print a summary of only the third model run:
summary(mnl.wtp$models[[3]])

# Print a summary of the best model:
summary(mnl.wtp$bestModel)

# CAUTION ON LOCAL MINIMA:
# To check whether you have reached a global solution in WTP space models,
# try running the equivalent model in the preference space and compare the
Expand Down

0 comments on commit cf819d3

Please sign in to comment.