-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.R
63 lines (49 loc) · 1.44 KB
/
functions.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
library(MASS)
library(logitr)
library(mlogit)
library(mded)
library(showtext)
library(htmltools)
logitrData <- function(filtered_survey_data) {
incremented_scale <-c()
dce_count = nrow(filtered_survey_data) / 4
for (i in 1:dce_count){
incremented_scale <- append(incremented_scale,c(i,i,i,i))
}
filtered_survey_data$obsId <- incremented_scale
return (filtered_survey_data)
}
wtp_space_results <- function(each_user_results){
multi_starts = 100
pars = c("Location","Contacts","Financial","Fingerprint","Text","BrowsingHistory")
mnl_pref_each <- logitr(
data = logitrData(each_user_results),
outcome = "is_selected_int",
obsID = "obsId",
pars = c("price","Location","Contacts","Financial","Fingerprint","Text","BrowsingHistory")
)
# wtp_mnl_pref_each <- wtp(mnl_pref_each,scalePar = "price")
wtp_pref <- coef(mnl_pref_each)
for(i in 1:7){
if(i!=1){
wtp_pref[i]=-(wtp_pref[i]/wtp_pref[1])
}
}
mnl_wtp_each <- logitr(
data = logitrData(each_user_results),
outcome = "is_selected_int",
obsID = "obsId",
pars = pars,
scalePar = "price",
numCores = 1,
numMultiStarts = multi_starts,
#modelSpace = "wtp"
startVals = wtp_pref
)
# print(wtpCompare(mnl_pref_each,mnl_wtp_each,scalePar = 'price'))
print(wtp_pref)
print(coef(mnl_wtp_each))
return(
coef(mnl_wtp_each)
)
}