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
d432800a
Commit
d432800a
authored
1 year ago
by
dj44vuri
Browse files
Options
Downloads
Patches
Plain Diff
small changes for decisiongroups and some comments in simulate_all
parent
4589a4d6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/simulate_choices.R
+11
-6
11 additions, 6 deletions
R/simulate_choices.R
with
11 additions
and
6 deletions
R/simulate_choices.R
+
11
−
6
View file @
d432800a
...
...
@@ -15,7 +15,7 @@ simulate_choices <- function(data, utility, setspp, destype, bcoefficients, deci
### unpack the bcoeff list so variables are accessible
### unpack the bcoeff list so variables are accessible
for
(
key
in
names
(
bcoefficients
))
{
assign
(
key
,
bcoefficients
[[
key
]])
}
...
...
@@ -51,7 +51,7 @@ simulate_choices <- function(data, utility, setspp, destype, bcoefficients, deci
cat
(
"\n decisiongroups exists: "
,
exists
(
"decisiongroups"
))
if
(
exists
(
"
decisiongroups
"
))
{
### create a new variable to classify decision groups.
if
(
length
(
decisiongroups
)
>
2
)
{
### create a new variable to classify decision groups.
data
=
dplyr
::
mutate
(
data
,
group
=
as.numeric
(
cut
(
dplyr
::
row_number
(),
breaks
=
decisiongroups
*
dplyr
::
n
(),
...
...
@@ -64,20 +64,25 @@ simulate_choices <- function(data, utility, setspp, destype, bcoefficients, deci
data
$
group
=
1
}
## Do user entered manipulations to choice set
data
<-
data
%>%
dplyr
::
group_by
(
ID
)
%>%
dplyr
::
mutate
(
!!!
manipulations
)
## split dataframe into groups
subsets
<-
split
(
data
,
data
$
group
)
## for each group calculate utility
subsets
<-
purrr
::
map2
(
.x
=
seq_along
(
utility
),
.y
=
subsets
,
~
dplyr
::
mutate
(
.y
,
purrr
::
map_dfc
(
utility
[[
.x
]],
by_formula
)))
##put data from eachgroup together again
data
<-
dplyr
::
bind_rows
(
subsets
)
## add random component and calculate total utility
data
<-
data
%>%
dplyr
::
rename_with
(
~
stringr
::
str_replace
(
.
,
pattern
=
"\\."
,
"_"
),
tidyr
::
everything
())
%>%
dplyr
::
mutate
(
dplyr
::
across
(
.cols
=
n
,
.fns
=
~
evd
::
rgumbel
(
setspp
,
loc
=
0
,
scale
=
1
),
.names
=
"{'e'}_{n}"
),
...
...
@@ -89,9 +94,9 @@ simulate_choices <- function(data, utility, setspp, destype, bcoefficients, deci
cat
(
"\n data has been
made
\n"
)
cat
(
"\n data has been
created
\n"
)
cat
(
"\n First few observations \n "
)
cat
(
"\n First few observations
of the dataset
\n "
)
print
(
utils
::
head
(
data
))
cat
(
"\n \n "
)
return
(
data
)
...
...
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