Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
choiceTools
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
choiceTools
Commits
64ef4147
Commit
64ef4147
authored
10 months ago
by
Jungehülsing
Browse files
Options
Downloads
Patches
Plain Diff
add option to use robust variance covariance matrix
parent
3a3a3ad8
No related branches found
Branches containing commit
No related tags found
1 merge request
!2
Add Poetest and its documentation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
R/poetest.R
+18
-7
18 additions, 7 deletions
R/poetest.R
man/poetest.Rd
+4
-2
4 additions, 2 deletions
man/poetest.Rd
with
22 additions
and
9 deletions
R/poetest.R
+
18
−
7
View file @
64ef4147
...
...
@@ -8,17 +8,21 @@
#' @param model2 Model from which to take the second WTP values
#' @param att Vector of attributes whose WTP values you want to compare
#' @param price name of the price coefficient
#'
#'
@param vcov which variance-covariance matrix to use. Either normal for the normal one, or rob for the robust one.
#'
#' @return a p value associated with "WTP1>WTP2"
#' @export
#'
#' @examples \dontrun{
#' poeresults<-poetest(n=5000, model1 = clmodels[[model_1]],model2 = clmodels[[model_2]],
#' att=attr, price = "bcost")
#' att=attr, price = "bcost"
, vcov = "normal"
)
#' }
poetest
<-
function
(
n
,
model1
,
model2
,
att
,
price
){
poetest
<-
function
(
n
,
model1
,
model2
,
att
,
price
,
vcov
){
#stop command for invalid variance covariance matrix
if
(
!
vcov
%in%
c
(
"rob"
,
"normal"
))
{
stop
(
"Invalid value for 'vcov'. Please use one of 'rob' or 'normal'."
)
}
## Extract relevant elements of models
...
...
@@ -41,7 +45,7 @@ poetest <- function(n, model1, model2, att, price){
return
(
draw
)
}
getalldraws
<-
function
(
n
,
model1
,
model2
,
att
,
price
)
{
getalldraws
<-
function
(
n
,
model1
,
model2
,
att
,
price
,
vcov
)
{
allmodels
<-
list
(
model1
,
model2
)
...
...
@@ -49,7 +53,14 @@ poetest <- function(n, model1, model2, att, price){
for
(
m
in
1
:
2
)
{
model_draws
[[
m
]]
<-
takedraws
(
n
,
allmodels
[[
m
]][[
"estimate"
]],
allmodels
[[
m
]][[
"varcov"
]])
#implement the option to choose between the robust or the normal variance covariance matrix
varcov_matrix
<-
switch
(
vcov
,
rob
=
allmodels
[[
m
]][[
"robvarcov"
]],
normal
=
allmodels
[[
m
]][[
"varcov"
]],
stop
(
"Invalid value for 'vcov'. Please use one of 'rob' or 'normal'."
)
)
model_draws
[[
m
]]
<-
takedraws
(
n
,
allmodels
[[
m
]][[
"estimate"
]],
varcov_matrix
)
model_draws
[[
m
]]
<-
cbind
(
model_draws
[[
m
]],
wtp
=
model_draws
[[
m
]][,
att
]
/
model_draws
[[
m
]][,
price
])
}
...
...
@@ -58,7 +69,7 @@ poetest <- function(n, model1, model2, att, price){
}
draws
<-
getalldraws
(
n
,
model1
,
model2
,
att
,
price
)
draws
<-
getalldraws
(
n
,
model1
,
model2
,
att
,
price
,
vcov
)
wtpvec
<-
cbind
(
wtp1
=
draws
[[
1
]][,
"wtp"
],
wtp2
=
draws
[[
2
]][,
"wtp"
])
...
...
This diff is collapsed.
Click to expand it.
man/poetest.Rd
+
4
−
2
View file @
64ef4147
...
...
@@ -4,7 +4,7 @@
\alias{poetest}
\title{Perform the Poe (2005) test on different discrete choice models}
\usage{
poetest(n, model1, model2, att, price)
poetest(n, model1, model2, att, price
, vcov
)
}
\arguments{
\item{n}{number of draws}
...
...
@@ -16,6 +16,8 @@ poetest(n, model1, model2, att, price)
\item{att}{Vector of attributes whose WTP values you want to compare}
\item{price}{name of the price coefficient}
\item{vcov}{which variance-covariance matrix to use. Either normal for the normal one, or rob for the robust one.}
}
\value{
a p value associated with "WTP1>WTP2"
...
...
@@ -26,6 +28,6 @@ Perform the Poe (2005) test on different discrete choice models
\examples{
\dontrun{
poeresults<-poetest(n=5000, model1 = clmodels[[model_1]],model2 = clmodels[[model_2]],
att=attr, price = "bcost")
att=attr, price = "bcost"
, vcov = "normal"
)
}
}
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