Skip to content

Commit

Permalink
Best sim results so far
Browse files Browse the repository at this point in the history
  • Loading branch information
haziqj committed Mar 29, 2024
1 parent 6b60a9f commit 6bd53ec
Show file tree
Hide file tree
Showing 21 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions R/30-data_gen_complex.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ make_population <- function(model_no = 1, seed = 123, H1 = FALSE,

# Stratify according to latent variable --------------------------------------
abil_order <-
as_tibble(eta) %>%
as_tibble(eta[, 1]) %>%
mutate(z = rowSums(across(everything())),
rn = row_number()) %>%
select(z, rn) %>%
Expand Down Expand Up @@ -300,7 +300,7 @@ gen_data_bin_complex3 <- function(population = make_population(1, seed = NULL),
group_by(type) %>%
mutate(pr_school_selected = npsu / dplyr::n(),
prob = pr_school_selected * pr_class_selected,
stratum_wt = dplyr::n() / total_type,
stratum_wt = 1, # dplyr::n() / total_type,
wt = 1 / (prob * stratum_wt))

# Sampling of PSUs
Expand Down
8 changes: 4 additions & 4 deletions R/50-sim_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ run_ligof_sims <- function(model_no = 1, nsim = 1000, samp_size = 1000,
"strat2"),
simtype = c("type1", "power"), starting_seed = 16423,
ncores = parallel::detectCores() - 2,
pop_Sigma = FALSE, Sigma2 = NULL) {
pop_Sigma = FALSE, Sigma2 = NULL, the_wt = NULL) {

# Model setup ----------------------------------------------------------------
mod <- txt_mod(model_no)
Expand All @@ -60,10 +60,10 @@ run_ligof_sims <- function(model_no = 1, nsim = 1000, samp_size = 1000,
if (simtype == "power") H1 <- TRUE
samp <- match.arg(samp, c("srs", "wtd", "strat", "clust", "strcl", "strat2"))

the_wt <- NULL
# the_wt <- NULL
if (samp != "srs") {
the_wt <- "wt"
pop <- make_population(model_no, seed = starting_seed, H1 = H1,
# the_wt <- "wt"
pop <- make_population(model_no, seed = 27324, H1 = H1,
Sigma2_attr = isTRUE(pop_Sigma))
Sigma2pop <- attr(pop, "Sigma2")
}
Expand Down
18 changes: 8 additions & 10 deletions data-raw/07-run_simulations.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
library(tidyverse)
library(lavaan.bingof)
library(survey)
analysis_path <- dirname(rstudioapi::getSourceEditorContext()$path)

# All simulations --------------------------------------------------------------
for (sim_type in c("type1")) {
for (samp_method in c("strat")) {
for (the_samp_size in c(1000)) {
for (mod_no in c(4)) {
for (samp_method in c("strcl")) {
for (the_samp_size in c(5000, 10000)) {
for (mod_no in 3) {
sim_name <- paste0(samp_method, mod_no, "_n", the_samp_size, "_",
sim_type)
cat("[", as.character(Sys.time()), "]", "Now running simulation",
sim_name, "\n")
sim <- run_ligof_sims(mod_no, samp_size = the_samp_size, nsim = 100,
sim <- run_ligof_sims(mod_no, samp_size = the_samp_size, nsim = 1000,
samp = samp_method, simtype = sim_type,
starting_seed = NULL,
pop_Sigma = FALSE, Sigma2 = "theoretical",
the_wt = NULL)
starting_seed = NULL, the_wt = NULL,
pop_Sigma = FALSE, Sigma2 = "theoretical")
invisible(list2env(setNames(list(sim), sim_name), envir = .GlobalEnv))
# save(list = sim_name, file = paste0(analysis_path, "/Rsave/",
# sim_name, ".RData"))
save(list = sim_name, file = paste0(analysis_path, "/Rsave/",
sim_name, ".RData"))
}
}
}
Expand Down
Binary file modified data-raw/Rsave/strcl3_n10000_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl3_n1000_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl3_n2500_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl3_n5000_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl3_n500_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl4_n10000_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl4_n1000_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl4_n2500_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl4_n5000_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl4_n500_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl5_n10000_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl5_n1000_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl5_n2500_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl5_n5000_type1.RData
Binary file not shown.
Binary file modified data-raw/Rsave/strcl5_n500_type1.RData
Binary file not shown.
Binary file modified data/all_res.rda
Binary file not shown.
Binary file modified data/res_complex_type1.rda
Binary file not shown.
Binary file modified vignettes/articles/simplots.RData
Binary file not shown.

0 comments on commit 6bd53ec

Please sign in to comment.