From cddc72f4057401f8d7b1a9d82f2da3faf82119df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jungeh=C3=BClsing?= <jj43vyzo@usr.idiv.de> Date: Thu, 6 Jun 2024 15:29:40 +0200 Subject: [PATCH] put takedraws and getalldraws functions into the poetest function such that everything makes sense with roxygen and the documentation --- NAMESPACE | 2 +- R/poetest.R | 79 +++++++++++++++++++++++++----------------------- man/takedraws.Rd | 30 ------------------ 3 files changed, 43 insertions(+), 68 deletions(-) delete mode 100644 man/takedraws.Rd diff --git a/NAMESPACE b/NAMESPACE index ce049c9..7cb0032 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,8 +2,8 @@ export("%>%") export(createSets) +export(poetest) export(quicktexregapollo) export(remGOF) export(subcoef) -export(takedraws) importFrom(magrittr,"%>%") diff --git a/R/poetest.R b/R/poetest.R index d04c680..74610a4 100644 --- a/R/poetest.R +++ b/R/poetest.R @@ -7,59 +7,64 @@ #' @param model1 Model from which to take the first WTP values #' @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 nmae of the price coefficient +#' @param price name of the price coefficient #' #' #' @return a p value associated with "WTP1>WTP2" #' @export #' -#' @examples { +#' @examples \dontrun{ #' poeresults<-poetest(n=5000, model1 = clmodels[[model_1]],model2 = clmodels[[model_2]], att=attr, price = "bcost") #' } -## Extract relevant elements of models -takedraws <-function(n=10000, beta,vc) { - k=length(beta) - cholesky = chol(vc) - draw=matrix(nrow = n, ncol=k) - - colnames(draw) <-names(beta) +poetest <- function(n, model1, model2, att, price){ - for (d in 1:n) { - draw[d,] <- beta +t(cholesky)%*%stats::rnorm(k) + + ## Extract relevant elements of models + + takedraws <-function(n=10000, beta,vc) { + + + k=length(beta) + cholesky = chol(vc) + + draw=matrix(nrow = n, ncol=k) + + colnames(draw) <-names(beta) + + for (d in 1:n) { + draw[d,] <- beta +t(cholesky)%*%stats::rnorm(k) + } + + + + return(draw) } - - - - return(draw) -} - - -getalldraws <- function(n, model1, model2, att, price) { - - allmodels <- list(model1,model2) - - model_draws <- list() - - for (m in 1:2) { - - model_draws[[m]] <-takedraws(n,allmodels[[m]][["estimate"]],allmodels[[m]][["varcov"]]) - - model_draws[[m]] <-cbind(model_draws[[m]], wtp= model_draws[[m]][,att]/model_draws[[m]][,price]) - } - - return(model_draws) + + getalldraws <- function(n, model1, model2, att, price) { + + allmodels <- list(model1,model2) + + model_draws <- list() + + for (m in 1:2) { + + model_draws[[m]] <-takedraws(n,allmodels[[m]][["estimate"]],allmodels[[m]][["varcov"]]) + + model_draws[[m]] <-cbind(model_draws[[m]], wtp= model_draws[[m]][,att]/model_draws[[m]][,price]) + } + + return(model_draws) } + + + draws<-getalldraws(n, model1, model2, att, price) -poetest <- function(n, model1, model2, att, price){ - -draws<-getalldraws(n, model1, model2, att, price) - -wtpvec <- cbind(wtp1= draws[[1]][,"wtp"], wtp2= draws[[2]][,"wtp"]) + wtpvec <- cbind(wtp1= draws[[1]][,"wtp"], wtp2= draws[[2]][,"wtp"]) diff --git a/man/takedraws.Rd b/man/takedraws.Rd deleted file mode 100644 index 3b97639..0000000 --- a/man/takedraws.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/poetest.R -\name{takedraws} -\alias{takedraws} -\title{Perform the Poe (2005) test on different discrete choice models} -\usage{ -takedraws(n = 10000, beta, vc) -} -\arguments{ -\item{n}{number of draws} - -\item{model1}{Model from which to take the first WTP values} - -\item{model2}{Model from which to take the second WTP values} - -\item{att}{Vector of attributes whose WTP values you want to compare} - -\item{price}{nmae of the price coefficient} -} -\value{ -a p value associated with "WTP1>WTP2" -} -\description{ -Perform the Poe (2005) test on different discrete choice models -} -\examples{ -{ -poeresults<-poetest(n=5000, model1 = clmodels[[model_1]],model2 = clmodels[[model_2]], att=attr, price = "bcost") -} -} -- GitLab