Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simulateDCE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dj44vuri
simulateDCE
Commits
20cff6f9
Commit
20cff6f9
authored
4 months ago
by
dj44vuri
Browse files
Options
Downloads
Patches
Plain Diff
utility transformation works now
parent
b77c6a1b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
DCEsim.Rproj
+1
-0
1 addition, 0 deletions
DCEsim.Rproj
R/sim_choice.R
+32
-7
32 additions, 7 deletions
R/sim_choice.R
R/simulate_choices.R
+1
-1
1 addition, 1 deletion
R/simulate_choices.R
with
34 additions
and
8 deletions
DCEsim.Rproj
+
1
−
0
View file @
20cff6f9
Version: 1.0
ProjectId: b4471ba3-d3d6-48a1-a26a-00c2bdd34cf7
RestoreWorkspace: No
SaveWorkspace: No
...
...
This diff is collapsed.
Click to expand it.
R/sim_choice.R
+
32
−
7
View file @
20cff6f9
...
...
@@ -108,15 +108,40 @@ designs_all <- list()
}
transform_util2
<-
function
()
{
mnl_U
<-
paste
(
purrr
::
map_chr
(
ut
[[
1
]],
as.character
,
keep.source.attr
=
TRUE
),
collapse
=
""
,
";"
)
%>%
stringr
::
str_replace_all
(
setNames
(
paste0
(
"@"
,
names
(
bcoefficients
)),
paste0
(
"\\b"
,
names
(
bcoefficients
),
"\\b"
)))
%>%
stringr
::
str_replace_all
(
setNames
(
paste0
(
"$"
,
names
(
datadet
)),
paste0
(
"\\b"
,
names
(
datadet
),
"\\b"
)))
%>%
stringr
::
str_replace_all
(
c
(
"priors\\[\""
=
""
,
"\"\\]"
=
""
,
"~"
=
"="
,
"\\."
=
"_"
,
"V_"
=
"U_"
))
transform_util2
<-
function
()
{
# Filter relevant database variables
relevant_database_vars
<-
setdiff
(
names
(
database
),
c
(
"V_1"
,
"V_2"
,
"U_1"
,
"U_2"
,
"CHOICE"
))
mnl_U
<-
paste
(
purrr
::
map_chr
(
ut
[[
1
]],
as.character
,
keep.source.attr
=
TRUE
),
collapse
=
""
,
";"
)
%>%
# Replace coefficients with exact matches
stringr
::
str_replace_all
(
setNames
(
paste0
(
"@"
,
names
(
bcoefficients
)),
paste0
(
"(?<![._a-zA-Z0-9])"
,
names
(
bcoefficients
),
"(?![._a-zA-Z0-9-])"
)
))
%>%
# General transformations
stringr
::
str_replace_all
(
c
(
`priors\\["`
=
""
,
`"\\]`
=
""
,
`~`
=
"="
,
`\\.`
=
"_"
,
`V_`
=
"U_"
))
%>%
# Replace only relevant database variables
stringr
::
str_replace_all
(
setNames
(
paste0
(
"$"
,
relevant_database_vars
),
paste0
(
"(?<![._a-zA-Z0-9])"
,
relevant_database_vars
,
"(?![._a-zA-Z0-9-])"
)
))
%>%
# Clean up duplicate symbols
stringr
::
str_replace_all
(
c
(
`@@`
=
"@"
,
"\\$\\$"
=
"$"
))
return
(
mnl_U
)
}
}
...
...
This diff is collapsed.
Click to expand it.
R/simulate_choices.R
+
1
−
1
View file @
20cff6f9
...
...
@@ -82,7 +82,7 @@ simulate_choices <- function(data, utility, setspp, destype, bcoefficients, deci
## add random component and calculate total utility
data
<-
data
%>%
dplyr
::
rename_with
(
~
stringr
::
str_replace
(
.
,
pattern
=
"\\."
,
"_"
),
tidyr
::
everything
())
%>%
dplyr
::
rename_with
(
~
stringr
::
str_replace
_all
(
.
,
pattern
=
"\\."
,
"_"
),
tidyr
::
everything
())
%>%
dplyr
::
mutate
(
dplyr
::
across
(
.cols
=
n
,
.fns
=
~
evd
::
rgumbel
(
setspp
,
loc
=
0
,
scale
=
1
),
.names
=
"{'e'}_{n}"
),
dplyr
::
across
(
dplyr
::
starts_with
(
"V_"
),
.names
=
"{'U'}_{n}"
)
+
dplyr
::
across
(
dplyr
::
starts_with
(
"e_"
))
)
%>%
dplyr
::
ungroup
()
%>%
dplyr
::
mutate
(
CHOICE
=
max.col
(
.
[,
grep
(
"U_"
,
names
(
.
))])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment