-
Notifications
You must be signed in to change notification settings - Fork 0
/
models_no_weights.R
185 lines (162 loc) · 5.8 KB
/
models_no_weights.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Load libraries and data -----------------------------------------------------
# Main library for model estimation is "logitr"- documentation here:
# https://jhelvy.github.io/logitr
# To install, install the "remotes" library, then install "logitr" from github:
# # install.packages("remotes")
# remotes::install_github('jhelvy/logitr')
library('logitr')
library(readr)
china_data <- read_csv(here::here('data', 'china_cars.csv'))
us_data <- read_csv(here::here('data', 'us_cars.csv'))
# MNL Models ------------------------------------------------------------------
# --- China models ---
# Preference space
mnl_pref_china <- logitr(
data = china_data,
choiceName = 'choice',
obsIDName = 'obsnum',
parNames = c(
'price', 'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
'bevFastcharge','opCost', 'accelTime')
)
# WTP space
mnl_wtp_china <- logitr(
data = china_data,
choiceName = 'choice',
obsIDName = 'obsnum',
parNames = c(
'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
'bevFastcharge','opCost', 'accelTime'),
priceName = 'price',
modelSpace = 'wtp',
options = list(
numMultiStarts = 10,
startParBounds = c(-10, 10))
)
# Compare WTP
wtpCompare(mnl_pref_china, mnl_wtp_china, "price")
# --- US models ---
# Preference space
mnl_pref_us <- logitr(
data = us_data,
choiceName = 'choice',
obsIDName = 'obsnum',
parNames = c(
'price', 'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
'bevFastcharge','opCost', 'accelTime')
)
# WTP space
mnl_wtp_us <- logitr(
data = us_data,
choiceName = 'choice',
obsIDName = 'obsnum',
parNames = c(
'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
'bevFastcharge','opCost', 'accelTime'),
priceName = 'price',
modelSpace = 'wtp',
options = list(
numMultiStarts = 10,
startParBounds = c(-10, 10)))
# Compare WTP
wtpCompare(mnl_pref_us, mnl_wtp_us, "price")
# MXL Models ------------------------------------------------------------------
# --- China models ---
mxl_pref_china <- logitr(
data = china_data,
choiceName = 'choice',
obsIDName = 'obsnum',
parNames = c(
'price', 'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
'bevFastcharge','opCost', 'accelTime'),
randPars = c(
hev = 'n', phev10 = 'n', phev20 = 'n', phev40 = 'n', bev75 = 'n',
bev100 = 'n', bev150 = 'n', american = 'n', japanese = 'n', chinese = 'n',
skorean = 'n', phevFastcharge = 'n', bevFastcharge = 'n', accelTime = 'n',
opCost = 'n'),
modelSpace = 'pref',
options = list(
numMultiStarts = 5,
startVals = mnl_wtp_china$Estimate,
startParBounds = c(-5, 5),
# numDraws = 125,
standardDraws = draws)
)
mxl_wtp_china <- logitr(
data = china_data,
choiceName = 'choice',
obsIDName = 'obsnum',
parNames = c(
'price', 'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
'bevFastcharge','opCost', 'accelTime'),
priceName = 'price',
randPars = c(
hev = 'n', phev10 = 'n', phev20 = 'n', phev40 = 'n', bev75 = 'n',
bev100 = 'n', bev150 = 'n', american = 'n', japanese = 'n', chinese = 'n',
skorean = 'n', phevFastcharge = 'n', bevFastcharge = 'n', accelTime = 'n',
opCost = 'n'),
modelSpace = 'wtp',
options = list(
numMultiStarts = 5,
startVals = mnl_wtp_china$Estimate,
startParBounds = c(-5, 5),
numDraws = 125))
# --- US models ---
mxl_pref_us <- logitr(
data = us_data,
choiceName = 'choice',
obsIDName = 'obsnum',
parNames = c(
'price', 'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
'bevFastcharge','opCost', 'accelTime'),
randPars = c(
hev = 'n', phev10 = 'n', phev20 = 'n', phev40 = 'n', bev75 = 'n',
bev100 = 'n', bev150 = 'n', american = 'n', japanese = 'n', chinese = 'n',
skorean = 'n', phevFastcharge = 'n', bevFastcharge = 'n', accelTime = 'n',
opCost = 'n'),
modelSpace = 'pref',
options = list(
numMultiStarts = 5,
startVals = mnl_wtp_us$Estimate,
startParBounds = c(-5, 5),
numDraws = 125))
mxl_wtp_us <- logitr(
data = us_data,
choiceName = 'choice',
obsIDName = 'obsnum',
parNames = c(
'price', 'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
'bevFastcharge','opCost', 'accelTime'),
priceName = 'price',
randPars = c(
hev = 'n', phev10 = 'n', phev20 = 'n', phev40 = 'n', bev75 = 'n',
bev100 = 'n', bev150 = 'n', american = 'n', japanese = 'n', chinese = 'n',
skorean = 'n', phevFastcharge = 'n', bevFastcharge = 'n', accelTime = 'n',
opCost = 'n'),
modelSpace = 'wtp',
options = list(
numMultiStarts = 5,
startVals = mnl_wtp_us$Estimate,
startParBounds = c(-5, 5),
numDraws = 125))
# ---------------------------------------------------------------------------
# Save estimated model objects
models_no_weights <- list(
mnl_pref_china = mnl_pref_china,
mnl_wtp_china = mnl_wtp_china,
mnl_pref_us = mnl_pref_us,
mnl_wtp_us = mnl_wtp_us,
mxl_pref_china = mxl_pref_china,
mxl_wtp_china = mxl_wtp_china,
mxl_pref_us = mxl_pref_us,
mxl_wtp_us = mxl_wtp_us
)
saveRDS(models_no_weights, here::here('results', 'models_no_weights.Rds'))