Skip to content
Snippets Groups Projects
Commit 7b3bda5b authored by dj44vuri's avatar dj44vuri
Browse files

aggregate results works but is not very helpful so far. Next step is to save output

parent bc73745f
No related branches found
No related tags found
No related merge requests found
...@@ -3,19 +3,20 @@ ...@@ -3,19 +3,20 @@
#' Processes the simulation results to extract summaries, coefficients, and graphs. #' Processes the simulation results to extract summaries, coefficients, and graphs.
#' #'
#' @param all_designs A list of simulation results from sim_choice. Can contain different designs but need to have the common structure returned by simchoice #' @param all_designs A list of simulation results from sim_choice. Can contain different designs but need to have the common structure returned by simchoice
#' @param bcoeff A named list of true parameter values used in the simulation.
#' @param designname A character vector of design names used in the simulation.
#' @param reshape_type Method for reshaping data: "auto", "stats", or "tidyr".
#'
#' @return A list with aggregated results including summary, coefficients, graphs, and power. #' @return A list with aggregated results including summary, coefficients, graphs, and power.
#' @export #' @export
aggregateResults <- function(all_designs, designname, bcoeff, reshape_type){ aggregateResults <- function(all_designs){
designname <- all_designs[["arguements"]][["designname"]]
reshape_type <- all_designs[["arguements"]][["Reshape Type"]]
bcoeff <- all_designs[["arguements"]][["Beta values"]]
powa <- purrr::map(all_designs, ~ .x$power) powa <- purrr::map(all_designs, ~ .x$power)
summaryall <- as.data.frame(purrr::map(all_designs, ~ .x$summary)) %>% summaryall <- as.data.frame(purrr::compact(purrr::map(all_designs, ~ .x$summary))) %>% ## purrr::compact to remove all NULL
dplyr::select(!dplyr::ends_with("vars")) %>% dplyr::select(!dplyr::ends_with("vars")) %>%
tibble::rownames_to_column("parname") %>% tibble::rownames_to_column("parname") %>%
dplyr::mutate(parname = stringr::str_remove(parname, "^est_")) %>% dplyr::mutate(parname = stringr::str_remove(parname, "^est_")) %>%
...@@ -26,11 +27,10 @@ summaryall <- as.data.frame(purrr::map(all_designs, ~ .x$summary)) %>% ...@@ -26,11 +27,10 @@ summaryall <- as.data.frame(purrr::map(all_designs, ~ .x$summary)) %>%
".n", "truepar", "mean", "sd", "min" , "max", "range" , "se" ".n", "truepar", "mean", "sd", "min" , "max", "range" , "se"
))) )))
coefall <- purrr::map(all_designs, ~ .x$coefs) coefall <- purrr::compact(purrr::map(all_designs, ~ .x$coefs))
pat <- paste0("(", paste(designname, collapse = "|"), ").") # needed to identify pattern to be replaced pat <- paste0("(", paste(designname, collapse = "|"), ").") # needed to identify pattern to be replaced
preprocessed <- as.data.frame(coefall) %>% preprocessed <- as.data.frame(coefall) %>%
dplyr::select(!dplyr::matches("pval|run")) %>% dplyr::select(!dplyr::matches("pval|run")) %>%
dplyr::rename_with(~ sub("est_", "", .x), dplyr::everything()) %>% dplyr::rename_with(~ sub("est_", "", .x), dplyr::everything()) %>%
......
...@@ -170,11 +170,6 @@ sim_all <- function(nosim = 2, ...@@ -170,11 +170,6 @@ sim_all <- function(nosim = 2,
print(time) print(time)
if (estimate == TRUE) {
all_designs<- simulateDCE::aggregateResults(all_designs=all_designs, designname=designname, bcoeff=bcoeff, reshape_type=reshape_type)
}
all_designs[["time"]] = time all_designs[["time"]] = time
all_designs[["arguements"]] = list( all_designs[["arguements"]] = list(
"Beta values" = bcoeff, "Beta values" = bcoeff,
...@@ -183,9 +178,19 @@ all_designs<- simulateDCE::aggregateResults(all_designs=all_designs, designname= ...@@ -183,9 +178,19 @@ all_designs<- simulateDCE::aggregateResults(all_designs=all_designs, designname=
"Manipulation of vars" = manipulations, "Manipulation of vars" = manipulations,
"Number Simulations" = nosim, "Number Simulations" = nosim,
"Respondents" = resps, "Respondents" = resps,
"Designpath" = designpath "Designpath" = designpath,
"Reshape Type" = reshape_type,
"mode" = mode,
"designname" = designname
) )
if (estimate == TRUE) {
all_designs<- simulateDCE::aggregateResults(all_designs=all_designs)
}
return(all_designs) return(all_designs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment