Skip to content

Commit df25b25

Browse files
committed
Updated examples
Updated examples using new simulation syntax.
1 parent 39eff17 commit df25b25

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

examples/example.R

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,34 +134,33 @@ wtpCompare(mxl.pref, mxl.wtp, priceName='price')
134134
# ============================================================================
135135
# Run Market Simulation Using Estimated Models
136136

137-
# Create a market to simulate. Each row is an alternative and each column an
138-
# attribute. In this example, I just use one of the choice observations from
139-
# the yogurt dataset:
140-
market = subset(yogurt, obsID==42,
141-
select=c('feat', 'price', 'dannon', 'hiland', 'yoplait'))
142-
row.names(market) = c('dannon', 'hiland', 'weight', 'yoplait')
143-
market
137+
# Create a set of alternatives for which to simulate shares. Each row is an
138+
# alternative and each column an attribute. In this example, I just use one of the choice observations from the yogurt dataset:
139+
alts = subset(yogurt, obsID==42,
140+
select=c('feat', 'price', 'dannon', 'hiland', 'yoplait'))
141+
row.names(alts) = c('dannon', 'hiland', 'weight', 'yoplait')
142+
alts
144143

145144
# Run the simulation using the preference space MNL model:
146-
mnl.pref.simulation = marketSimulation(mnl.pref, market, alpha=0.025)
145+
mnl.pref.simulation = simulateShares(mnl.pref, alts, alpha=0.025)
147146
mnl.pref.simulation
148-
# The results show the expected market shares for each alternative.
147+
# The results show the expected shares for each alternative.
149148
# The low and high values show a 95% confidence interval, estimated using
150149
# simulation. You can change the CI level by setting alpha to a different
151150
# value (e.g. a 90% CI is obtained with alpha=0.05).
152151

153152
# Run the simulation using the WTP space MNL model:
154-
mnl.wtp.simulation = marketSimulation(mnl.wtp, market, priceName='price')
153+
mnl.wtp.simulation = simulateShares(mnl.wtp, alts, priceName='price')
155154
mnl.wtp.simulation
156155
# Since these two models are equivalent except in different spaces, the
157156
# simulation results should be the same. Note that 'priceName' is the name
158-
# of the price attribute in the market argument and must be included for
157+
# of the price attribute in the alts argument and must be included for
159158
# WTP space models.
160159

161-
# Market simulations can also be run using MXL models in either space:
162-
mxl.pref.simulation = marketSimulation(mxl.pref, market, alpha=0.025)
160+
# Simulations can also be run using MXL models in either space:
161+
mxl.pref.simulation = simulateShares(mxl.pref, alts)
163162
mxl.pref.simulation
164-
mxl.wtp.simulation = marketSimulation(mxl.wtp, market, priceName='price', alpha=0.025)
163+
mxl.wtp.simulation = simulateShares(mxl.wtp, alts, priceName='price')
165164
mxl.wtp.simulation
166165

167166
# Plot simulation results from preference space MNL model:

0 commit comments

Comments
 (0)