Skip to content
Snippets Groups Projects
Commit 4b1d858e authored by dj44vuri's avatar dj44vuri
Browse files

readdesign function working and no issues on check

parent c5d2a367
No related branches found
No related tags found
No related merge requests found
^DCEsim\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^data-raw$
utils::globalVariables(c("designfile", "destype", "Choice.situation", "Design"))
......@@ -10,8 +10,16 @@
#' @return a dataframe
#' @export
#'
#' @examples \dontrun{readdesign("Projects/test/Designs/firstdesign.ngd", "ngene")}
#' @examples library(simulateDCE)
#' mydesign <-readdesign(
#' system.file("extdata","agora", "altscf_eff.ngd" ,package = "simulateDCE"),
#' "ngene")
#'
#' print(mydesign)
#'
readdesign <- function(design = designfile, designtype = destype) {
design <- switch(designtype,
"ngene" = readr::read_delim(design,
......@@ -24,7 +32,7 @@ readdesign <- function(design = designfile, designtype = destype) {
dplyr::filter(!is.na(Choice.situation)),
"spdesign" = as.data.frame(readRDS(design)) |>
dplyr::mutate(Choice.situation = 1:dplyr::n()) |>
dplyr::rename_with(~ stringr::str_replace(., pattern = "_", "\\."), everything()),
dplyr::rename_with(~ stringr::str_replace(., pattern = "_", "\\."), tidyr::everything()),
stop("Invalid value for design. Please provide either 'ngene' or 'spdesign'.")
)
}
Design Choice situation alt1.b alt1.c alt1.d alt1.p alt2.b alt2.c alt2.d alt2.p Block
1 1 0 1 1 41 0 0 1 71 3
1 2 0 0 0 83 0 0 1 71 2
1 3 1 1 0 83 0 1 0 59 3
1 4 0 1 0 35 0 0 0 53 1
1 5 1 0 1 77 0 0 0 59 2
1 6 1 0 0 47 0 1 0 41 3
1 7 0 0 0 53 0 1 1 35 1
1 8 0 0 1 47 0 1 0 41 1
1 9 1 1 0 59 0 1 1 83 3
1 10 0 0 1 41 1 0 0 47 1
1 11 0 1 0 77 1 1 0 71 3
1 12 1 0 1 35 0 0 0 53 2
1 13 0 1 0 41 1 0 1 41 3
1 14 1 0 0 59 1 1 0 83 1
1 15 0 0 0 83 1 0 1 77 1
1 16 1 1 0 47 1 1 1 35 2
1 17 1 0 1 83 0 1 1 47 2
1 18 1 0 1 53 1 0 1 77 3
1 19 1 1 1 53 0 1 1 83 1
1 20 0 1 1 77 1 1 0 65 2
1 21 1 0 0 53 1 0 0 65 2
1 22 1 1 1 41 1 1 0 77 1
1 23 0 0 0 59 1 1 1 35 2
1 24 1 1 0 77 0 0 1 65 1
1 25 0 1 1 35 0 0 1 71 3
1 26 1 0 1 71 1 1 1 35 3
1 27 0 1 1 71 0 1 1 47 1
1 28 1 0 1 47 0 0 0 53 3
1 29 0 1 1 71 1 0 0 59 2
1 30 1 1 0 65 1 0 0 53 2
1 31 0 0 1 65 1 1 1 83 2
1 32 1 1 0 35 1 0 1 41 1
1 33 0 0 0 65 0 0 0 59 3
1 34 0 1 1 65 1 1 0 47 3
1 35 1 1 1 71 1 0 1 65 1
1 36 0 0 0 59 0 1 0 77 2
||||||||||
design
;alts = alt1*, alt2*, alt3
;rows = 36
;block = 3
;eff = (mnl,d)
;rep = 1000
;con
;model:
U(alt1) = b1[-1.2] + b2[0.1] * B[0,1] + b3[0.4] * C[0,1] + b4[0.3] * D[0,1] + b5[0.02] * P[35:83:6]/
U(alt2) = b6[-1.8] + b7[0.2]* B + b8[0.6] * C + b9[0.4] * D + b10[0.015]* P
;formatTitle = 'Scenario <scenarionumber>'
;formatTableDimensions = 3, 6
;formatTable:
1,1 = '' /
1,2 = 'Results' /
1,3 = 'Beratung' /
1,4 = 'Partner' /
1,5 = 'Kompensation' /
1,6 = 'Choice question&:' /
2,1 = 'alt1' /
2,2 = '<alt1.b>' /
2,3 = '<alt1.c>' /
2,4 = '<alt1.d>' /
2,5 = '<alt1.p>' /
2,6 = '' /
3,1 = 'alt2' /
3,2 = '<alt2.b>' /
3,3 = '<alt2.c>' /
3,4 = '<alt2.d>' /
3,5 = '<alt2.p>' /
3,6 = ''
;formatTableStyle:
1,1 = 'default' /
1,2 = 'headingattribute' /
1,3 = 'headingattribute' /
1,4 = 'headingattribute' /
1,5 = 'headingattribute' /
1,6 = 'headingattribute' /
2,1 = 'heading1' /
2,2 = 'body1' /
2,3 = 'body1' /
2,4 = 'body1' /
2,5 = 'body1' /
2,6 = 'choice1' /
3,1 = 'heading2' /
3,2 = 'body2' /
3,3 = 'body2' /
3,4 = 'body2' /
3,5 = 'body2' /
3,6 = 'choice2'
;formatStyleSheet = Default.css
;formatAttributes:
alt1.b(0=Results, 1=Action) /
alt1.c(0=Keine Beratung, 1=Mit Beratung) /
alt1.d(0=Keine Partner, 1=Mit Partner) /
alt1.p(35=#0, 41=#0, 47=#0, 53=#0, 59=#0, 65=#0, 71=#0, 77=#0, 83=#0) /
alt2.b(0=Results, 1=Action) /
alt2.c(0=Keine Beratung, 1=Mit Beratung) /
alt2.d(0=Keine Partner, 1=Mit Partner) /
alt2.p(35=#0, 41=#0, 47=#0, 53=#0, 59=#0, 65=#0, 71=#0, 77=#0, 83=#0)
$
\ No newline at end of file
Design Choice situation alt1.b alt1.c alt1.d alt1.p alt2.b alt2.c alt2.d alt2.p Block
1 1 1 0 1 53 0 1 0 59 1
1 2 1 1 0 71 0 0 1 47 2
1 3 1 0 0 53 0 1 1 71 2
1 4 0 0 0 77 1 1 1 35 2
1 5 0 1 1 65 1 0 0 59 2
1 6 0 1 0 35 1 0 1 83 2
1 7 1 1 1 59 0 0 0 65 1
1 8 1 1 1 35 0 0 0 83 2
1 9 0 0 1 47 1 1 0 65 2
1 10 0 0 1 41 1 1 0 77 1
1 11 1 1 0 59 0 0 1 53 1
1 12 1 0 1 71 0 1 0 47 1
1 13 1 0 0 83 0 1 1 35 2
1 14 1 0 0 47 0 1 1 71 1
1 15 0 0 1 77 1 1 0 41 1
1 16 0 1 0 41 1 0 1 77 1
1 17 0 1 1 65 1 0 0 53 2
1 18 0 1 0 83 1 0 1 41 1
||||||||||
design
;alts = alt1*, alt2*, alt3
;rows = 18
;block = 2
;eff = (mnl,d,mean)
;rep = 1000
;bdraws = halton(1000)
;con
;model:
U(alt1) = b1[(n,-1.2,0.1)] + b2[(n,0.1,0.02)] * B[0,1] + b3[(n,0.4,0.1)] * C[0,1] + b4[(n,0.3,0.1)] * D[0,1] + b5[(n,0.02,0.001)] * P[35:83:6]/
U(alt2) = b6[(n,-1.4,0.1)] + b2 * B + b3 * C + b4 * D + b5 * P
;formatTitle = 'Scenario <scenarionumber>'
;formatTableDimensions = 3, 6
;formatTable:
1,1 = '' /
1,2 = 'Results' /
1,3 = 'Beratung' /
1,4 = 'Partner' /
1,5 = 'Kompensation' /
1,6 = 'Choice question&:' /
2,1 = 'alt1' /
2,2 = '<alt1.b>' /
2,3 = '<alt1.c>' /
2,4 = '<alt1.d>' /
2,5 = '<alt1.p>' /
2,6 = '' /
3,1 = 'alt2' /
3,2 = '<alt2.b>' /
3,3 = '<alt2.c>' /
3,4 = '<alt2.d>' /
3,5 = '<alt2.p>' /
3,6 = ''
;formatTableStyle:
1,1 = 'default' /
1,2 = 'headingattribute' /
1,3 = 'headingattribute' /
1,4 = 'headingattribute' /
1,5 = 'headingattribute' /
1,6 = 'headingattribute' /
2,1 = 'heading1' /
2,2 = 'body1' /
2,3 = 'body1' /
2,4 = 'body1' /
2,5 = 'body1' /
2,6 = 'choice1' /
3,1 = 'heading2' /
3,2 = 'body2' /
3,3 = 'body2' /
3,4 = 'body2' /
3,5 = 'body2' /
3,6 = 'choice2'
;formatStyleSheet = Default.css
;formatAttributes:
alt1.b(0=Results, 1=Action) /
alt1.c(0=Keine Beratung, 1=Mit Beratung) /
alt1.d(0=Keine Partner, 1=Mit Partner) /
alt1.p(35=#0, 41=#0, 47=#0, 53=#0, 59=#0, 65=#0, 71=#0, 77=#0, 83=#0) /
alt2.b(0=Results, 1=Action) /
alt2.c(0=Keine Beratung, 1=Mit Beratung) /
alt2.d(0=Keine Partner, 1=Mit Partner) /
alt2.p(35=#0, 41=#0, 47=#0, 53=#0, 59=#0, 65=#0, 71=#0, 77=#0, 83=#0)
$
\ No newline at end of file
Design Choice situation alt1.b alt1.c alt1.d alt1.p alt2.b alt2.c alt2.d alt2.p Block
1 1 0 1 1 65 1 0 0 59 2
1 2 1 0 1 41 0 1 0 77 1
1 3 1 1 0 41 0 0 1 77 2
1 4 0 1 0 47 1 0 1 71 2
1 5 0 1 0 35 1 0 1 83 1
1 6 0 1 1 71 1 0 0 53 1
1 7 0 0 1 71 1 1 0 41 1
1 8 1 0 1 35 0 1 0 83 1
1 9 1 1 1 53 0 0 0 65 2
1 10 1 1 0 77 0 0 1 47 1
1 11 1 1 0 65 0 0 1 47 2
1 12 0 1 1 59 1 0 0 59 1
1 13 1 0 0 53 0 1 1 65 2
1 14 0 0 0 83 1 1 1 35 2
1 15 1 0 0 83 0 1 1 35 1
1 16 0 0 1 47 1 1 0 71 2
1 17 1 0 1 77 0 1 0 41 2
1 18 0 0 0 59 1 1 1 53 1
||||||||||
design
;alts = alt1*, alt2*, alt3
;rows = 18
;block = 2
;eff = (mnl,d)
;rep = 1000
;con
;model:
U(alt1) = b1[-1.2] + b2[0.1] * B[0,1] + b3[0.4] * C[0,1] + b4[0.3] * D[0,1] + b5[0.02] * P[35:83:6]/
U(alt2) = b6[-1.4] + b2 * B + b3 * C + b4 * D + b5 * P
;formatTitle = 'Scenario <scenarionumber>'
;formatTableDimensions = 3, 6
;formatTable:
1,1 = '' /
1,2 = 'Results' /
1,3 = 'Beratung' /
1,4 = 'Partner' /
1,5 = 'Kompensation' /
1,6 = 'Choice question&:' /
2,1 = 'alt1' /
2,2 = '<alt1.b>' /
2,3 = '<alt1.c>' /
2,4 = '<alt1.d>' /
2,5 = '<alt1.p>' /
2,6 = '' /
3,1 = 'alt2' /
3,2 = '<alt2.b>' /
3,3 = '<alt2.c>' /
3,4 = '<alt2.d>' /
3,5 = '<alt2.p>' /
3,6 = ''
;formatTableStyle:
1,1 = 'default' /
1,2 = 'headingattribute' /
1,3 = 'headingattribute' /
1,4 = 'headingattribute' /
1,5 = 'headingattribute' /
1,6 = 'headingattribute' /
2,1 = 'heading1' /
2,2 = 'body1' /
2,3 = 'body1' /
2,4 = 'body1' /
2,5 = 'body1' /
2,6 = 'choice1' /
3,1 = 'heading2' /
3,2 = 'body2' /
3,3 = 'body2' /
3,4 = 'body2' /
3,5 = 'body2' /
3,6 = 'choice2'
;formatStyleSheet = Default.css
;formatAttributes:
alt1.b(0=Results, 1=Action) /
alt1.c(0=Keine Beratung, 1=Mit Beratung) /
alt1.d(0=Keine Partner, 1=Mit Partner) /
alt1.p(35=#0, 41=#0, 47=#0, 53=#0, 59=#0, 65=#0, 71=#0, 77=#0, 83=#0) /
alt2.b(0=Results, 1=Action) /
alt2.c(0=Keine Beratung, 1=Mit Beratung) /
alt2.d(0=Keine Partner, 1=Mit Partner) /
alt2.p(35=#0, 41=#0, 47=#0, 53=#0, 59=#0, 65=#0, 71=#0, 77=#0, 83=#0)
$
\ No newline at end of file
Design Choice situation alt1.b alt1.c alt1.d alt1.p alt2.b alt2.c alt2.d alt2.p Block
1 1 0 0 0 35 1 0 0 41 2
1 2 0 0 0 35 0 1 1 41 2
1 3 1 1 1 35 1 1 0 53 4
1 4 1 1 1 35 0 1 0 47 1
1 5 1 0 0 41 1 0 0 59 3
1 6 1 0 0 41 0 0 0 35 4
1 7 0 1 1 41 0 1 0 83 4
1 8 0 1 1 41 1 0 1 59 2
1 9 0 1 0 47 1 0 0 77 1
1 10 1 1 0 47 0 0 1 77 2
1 11 1 0 1 47 0 0 1 53 3
1 12 0 0 1 47 0 1 1 41 2
1 13 0 1 0 53 0 1 1 71 3
1 14 1 1 0 53 0 1 1 59 3
1 15 0 0 1 53 1 0 0 41 3
1 16 1 0 1 53 0 0 0 65 1
1 17 1 0 0 59 1 1 0 47 1
1 18 0 1 0 59 1 0 0 71 4
1 19 0 1 1 59 1 1 1 65 2
1 20 1 0 1 59 0 0 1 47 1
1 21 0 0 0 65 1 1 1 77 4
1 22 1 1 0 65 1 1 1 35 4
1 23 1 1 1 65 0 1 0 77 3
1 24 0 0 1 65 0 0 0 35 1
1 25 1 0 0 71 0 0 1 65 2
1 26 1 1 0 71 1 1 0 65 1
1 27 0 1 1 71 0 0 0 83 3
1 28 0 0 1 71 1 0 1 47 3
1 29 1 0 0 77 1 0 1 53 4
1 30 0 1 0 77 1 1 1 83 1
1 31 1 1 1 77 1 0 1 83 1
1 32 0 0 1 77 0 1 0 53 4
1 33 0 0 0 83 0 1 0 59 2
1 34 0 1 0 83 1 1 1 35 2
1 35 1 1 1 83 0 0 1 71 4
1 36 1 0 1 83 1 1 0 71 3
||||||||||
design
;alts = alt1*, alt2*, alt3
;rows = 36
;block = 4
;orth = seq
;con
;model:
U(alt1) = b1 + b2 * B[0,1] + b3 * C[0,1] + b4 * D[0,1] + b5 * P[35:83:6]/
U(alt2) = b6[-1.4] + b2 * B + b3 * C + b4 * D + b5 * P
;formatTitle = 'Scenario <scenarionumber>'
;formatTableDimensions = 3, 6
;formatTable:
1,1 = '' /
1,2 = 'Results' /
1,3 = 'Beratung' /
1,4 = 'Partner' /
1,5 = 'Kompensation' /
1,6 = 'Choice question&:' /
2,1 = 'alt1' /
2,2 = '<alt1.b>' /
2,3 = '<alt1.c>' /
2,4 = '<alt1.d>' /
2,5 = '<alt1.p>' /
2,6 = '' /
3,1 = 'alt2' /
3,2 = '<alt2.b>' /
3,3 = '<alt2.c>' /
3,4 = '<alt2.d>' /
3,5 = '<alt2.p>' /
3,6 = ''
;formatTableStyle:
1,1 = 'default' /
1,2 = 'headingattribute' /
1,3 = 'headingattribute' /
1,4 = 'headingattribute' /
1,5 = 'headingattribute' /
1,6 = 'headingattribute' /
2,1 = 'heading1' /
2,2 = 'body1' /
2,3 = 'body1' /
2,4 = 'body1' /
2,5 = 'body1' /
2,6 = 'choice1' /
3,1 = 'heading2' /
3,2 = 'body2' /
3,3 = 'body2' /
3,4 = 'body2' /
3,5 = 'body2' /
3,6 = 'choice2'
;formatStyleSheet = Default.css
;formatAttributes:
alt1.b(0=Results, 1=Action) /
alt1.c(0=Keine Beratung, 1=Mit Beratung) /
alt1.d(0=Keine Partner, 1=Mit Partner) /
alt1.p(35=#0, 41=#0, 47=#0, 53=#0, 59=#0, 65=#0, 71=#0, 77=#0, 83=#0) /
alt2.b(0=Results, 1=Action) /
alt2.c(0=Keine Beratung, 1=Mit Beratung) /
alt2.d(0=Keine Partner, 1=Mit Partner) /
alt2.p(35=#0, 41=#0, 47=#0, 53=#0, 59=#0, 65=#0, 71=#0, 77=#0, 83=#0)
$
\ No newline at end of file
Design Choice situation alt1.b alt1.c alt1.d alt1.p alt2.b alt2.c alt2.d alt2.p Block
1 1 0 1 1 53 0 0 0 65 2
1 2 1 1 0 77 1 0 1 47 2
1 3 0 1 0 71 0 0 1 41 1
1 4 1 1 1 59 1 0 0 65 1
1 5 0 0 0 65 1 1 1 59 2
1 6 0 0 1 53 0 1 0 47 2
1 7 0 0 1 47 1 1 0 71 2
1 8 1 1 0 83 0 1 1 35 1
1 9 0 0 1 47 1 0 0 53 1
1 10 1 1 0 35 0 1 1 83 2
1 11 0 1 0 65 1 1 1 59 1
1 12 0 0 0 59 1 0 1 53 1
1 13 1 1 0 77 1 0 1 41 2
1 14 1 1 1 35 0 1 0 77 1
1 15 0 0 1 41 1 1 0 71 1
1 16 1 0 1 71 0 0 0 77 1
1 17 1 0 1 83 0 1 0 35 2
1 18 1 0 0 41 0 0 1 83 2
||||||||||
design
;alts = alt1*, alt2*, alt3
;rows = 18
;block = 2
;eff = (mnl,d)
;rep = 1000
;model:
U(alt1) = b1[-10] + b2[9] * B[0,1] + b3[4] * C[0,1] + b4[0.3] * D[0,1] + b5[0.02] * P[35:83:6]/
U(alt2) = b6[-1.4] + b2 * B + b3 * C + b4 * D + b5 * P
;formatTitle = 'Scenario <scenarionumber>'
;formatTableDimensions = 3, 6
;formatTable:
1,1 = '' /
1,2 = 'Results' /
1,3 = 'Beratung' /
1,4 = 'Partner' /
1,5 = 'Kompensation' /
1,6 = 'Choice question&:' /
2,1 = 'alt1' /
2,2 = '<alt1.b>' /
2,3 = '<alt1.c>' /
2,4 = '<alt1.d>' /
2,5 = '<alt1.p>' /
2,6 = '' /
3,1 = 'alt2' /
3,2 = '<alt2.b>' /
3,3 = '<alt2.c>' /
3,4 = '<alt2.d>' /
3,5 = '<alt2.p>' /
3,6 = ''
;formatTableStyle:
1,1 = 'default' /
1,2 = 'headingattribute' /
1,3 = 'headingattribute' /
1,4 = 'headingattribute' /
1,5 = 'headingattribute' /
1,6 = 'headingattribute' /
2,1 = 'heading1' /
2,2 = 'body1' /
2,3 = 'body1' /
2,4 = 'body1' /
2,5 = 'body1' /
2,6 = 'choice1' /
3,1 = 'heading2' /
3,2 = 'body2' /
3,3 = 'body2' /
3,4 = 'body2' /
3,5 = 'body2' /
3,6 = 'choice2'
;formatStyleSheet = Default.css
;formatAttributes:
alt1.b(0=Results, 1=Action) /
alt1.c(0=Keine Beratung, 1=Mit Beratung) /
alt1.d(0=Keine Partner, 1=Mit Partner) /
alt1.p(35=#0, 41=#0, 47=#0, 53=#0, 59=#0, 65=#0, 71=#0, 77=#0, 83=#0) /
alt2.b(0=Results, 1=Action) /
alt2.c(0=Keine Beratung, 1=Mit Beratung) /
alt2.d(0=Keine Partner, 1=Mit Partner) /
alt2.p(35=#0, 41=#0, 47=#0, 53=#0, 59=#0, 65=#0, 71=#0, 77=#0, 83=#0)
$
\ No newline at end of file
......@@ -18,6 +18,11 @@ a dataframe
Creates a dataframe with the design.
}
\examples{
\dontrun{readdesign("Projects/test/Designs/firstdesign.ngd", "ngene")}
library(simulateDCE)
mydesign <-readdesign(
system.file("extdata","agora", "altscf_eff.ngd" ,package = "simulateDCE"),
"ngene")
print(mydesign)
}
design_path <- system.file("extdata","agora", "altscf_eff.ngd" ,package = "simulateDCE")
test_that("wrong designtype", {
expect_error(readdesign(design = design_path, designtype = "ng"),"Invalid value for design. Please provide either 'ngene' or 'spdesign'.")
})
test_that("file does not exist", {
expect_error(readdesign(design = system.file("data-raw/agora/alcf_eff.ngd", package = "simulateDCE"), designtype = "ngene"),
"does not exist in current working directory")
})
test_that("all is correct, but gives a warning", {
expect_warning(readdesign(design = design_path, designtype = "ngene"),
"One or more parsing issues, call ")
})
de
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment