Skip to content
Snippets Groups Projects
Commit 97c8a836 authored by samuelsmock's avatar samuelsmock
Browse files

added a few new tests on test that output

parent 665bd675
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ bcoeff <- list( ...@@ -15,7 +15,7 @@ bcoeff <- list(
basc = -1.2, basc = -1.2,
basc2 = -1.4, basc2 = -1.4,
baction = 0.1, baction = 0.1,
badvisory = 0.4, badvisory =0.4,
bpartner = 0.3, bpartner = 0.3,
bcomp = 0.02) bcomp = 0.02)
......
rm(list=ls())
devtools::load_all()
designpath<- system.file("extdata","feedadditives" ,package = "simulateDCE")
#notes <- "This design consists of different heuristics. One group did not attend the methan attribute, another group only decided based on the payment"
notes <- "Three heuristics"
resps =300 # number of respondents
nosim=2 # number of simulations to run (about 500 is minimum)
#betacoefficients should not include "-"
basc = 0.2
bcow = 0.3
badv = 0.3
bvet = 0.3
bfar = 0.3
bmet = 0.3
bbon = 0.3
bbon2 = 1.9
basc2 =2
decisiongroups=c(0,0.3,0.6,0.8,1)
#place your utility functions here
u<- list(u1= list(
v1 =V.1 ~ bcow*alt1.cow + badv * alt1.adv + bvet * alt1.vet + bfar * alt1.far + bmet*alt1.met + bbon * alt1.bon,
v2 =V.2 ~ bcow*alt2.cow + badv * alt2.adv + bvet * alt2.vet + bfar * alt2.far + bmet*alt2.met + bbon * alt2.bon,
v3 =V.3 ~ basc)
,
u2 = list(
v1 =V.1 ~ bcow*alt1.cow + badv * alt1.adv + bvet * alt1.vet + bfar * alt1.far + bbon * alt1.bon,
v2 =V.2 ~ bcow*alt2.cow + badv * alt2.adv + bvet * alt2.vet + bfar * alt2.far + bbon * alt2.bon,
v3 =V.3 ~ basc),
u3 = list(
v1 =V.1 ~ bbon2 * alt1.bon,
v2 =V.2 ~ bbon2 * alt2.bon,
v3 =V.3 ~ basc),
u4 = list(v1 =V.1 ~ basc2 + bcow*alt1.cow + badv * alt1.adv + bvet * alt1.vet + bfar * alt1.far + bmet*alt1.met + bbon * alt1.bon,
v2 =V.2 ~ bcow*alt2.cow + badv * alt2.adv + bvet * alt2.vet + bfar * alt2.far + bmet*alt2.met + bbon * alt2.bon,
v3 =V.3 ~ basc)
)
No preview for this file type
...@@ -153,7 +153,7 @@ test_that("Simulation results are reasonable", { ...@@ -153,7 +153,7 @@ test_that("Simulation results are reasonable", {
result1 <- sim_all(nosim = nosim, resps = resps, destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff) result1 <- sim_all(nosim = nosim, resps = resps, destype = destype, designpath = designpath, u = ul, bcoeff = bcoeff)
## The function below is intended to find a dataframe called $coef in the output ## The function below is intended to find a dataframe called $coef in the output
## regardless of the output data structure which can vary ## regardless of the output data structure, which can vary
find_dataframe <- function(list_object, dataframe_name) { find_dataframe <- function(list_object, dataframe_name) {
# Check if the current object is a list # Check if the current object is a list
if (is.list(list_object)) { if (is.list(list_object)) {
...@@ -182,12 +182,25 @@ test_that("Simulation results are reasonable", { ...@@ -182,12 +182,25 @@ test_that("Simulation results are reasonable", {
for (variable in names(bcoeff)){ for (variable in names(bcoeff)){
### Compare singular input value (hypothesis) with the average value of all iterations. ### ### Compare singular input value (hypothesis) with the average value of all iterations. ###
### This could be made more rigorous by testing each iteration or by changing the ### ### This could be made more rigorous by testing each iteration rather than the mean or by changing the ###
### tolerance around the input value considered valid. ### tolerance around the input value considered valid.
input_value <- bcoeff[[variable]] input_value <- bcoeff[[variable]]
mean_output_value <- mean(coeffNestedOutput[[paste0("est_", variable)]]) ## access the mean value of each iteration mean_output_value <- mean(coeffNestedOutput[[paste0("est_", variable)]]) ## access the mean value of each iteration
##change this depending on how rigorous you want to be ##change this depending on how rigorous you want to be
# Check if variable exists in coeffNestedOutput
expect_true(paste0("est_", variable) %in% names(coeffNestedOutput),
sprintf("Variable est_%s does not exist in coeffNestedOutput", variable))
# Check if variable is numeric
expect_type(coeffNestedOutput[[paste0("est_", variable)]], "numeric",
sprintf("Variable est_%s in coeffNestedOutput is not numeric", variable))
# Check if each entry in the variable column is numeric
expect_true(all(sapply(coeffNestedOutput[[paste0("est_", variable)]], is.numeric)),
sprintf("Variable est_%s in coeffNestedOutput contains non-numeric values", variable))
expect_gt(mean_output_value, input_value - 1) expect_gt(mean_output_value, input_value - 1)
expect_lt(mean_output_value, input_value + 1) expect_lt(mean_output_value, input_value + 1)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment