tmatta / lsasim

Simulate large scale assessment data
6 stars 5 forks source link

Unfinished function due to no extraction for outputs #21

Closed wleoncio closed 3 years ago

wleoncio commented 3 years ago

0. Setup

I've tested most values below. Not all testings are shown in this report. I only included the testings that are showing errors/warnings or inconsistent results.

cluster_gen_2 <- function(...) {
  cluster_gen(..., verbose = FALSE, calc_weights = FALSE)
}
set.seed(12334)
n1 <- c(3, 6)
n2 <- c(groups = 4, people = 2)
n3 <- c(school = 3, class = 2, student = 5)
n4 <- c(20, 50)
n5 <- list(school = 3, class = c(2, 1, 3), student = c(20, 20, 10, 30, 30, 30))
n5a <- list(school = 3, class = c(2, 3, 3), student = c(20, 20, 10, 30, 30, 30))
n6 <- list(school = 3, class = c(2, 1, 3), student = ranges(10, 50))
n6a <- list(school = 3, class = c(2, 3, 3), student = ranges(10, 50))
n7 <- list(school = 10, student = ranges(10, 50))
n8 <- list(school = 3, student = c(20, 20, 10))
n8a <- list(school = 3, class = c(2, 2, 2),student = c(20, 20, 10))
n8b <- list(school = 3, class = c(2, 3, 3),student = c(20, 20, 10, 5))
n8c <- list(school = 3, class = c(2, 1, 3),student = c(20, 20, 10))
n9 <- list(school = 10, class = c(2,1,3,1,1,1,2,1,2,1), student = ranges(10, 50))
n10 <- list(country = 2, school = 10, class = c(2,1,3,1,1,1,2,1,2,1), student = ranges(10, 50))
n11 <- list(culture = 2, country = 2, school = 10, class = c(2,1,3,1,1,1,2,1,2,1), student = ranges(10, 50))
n12 <- list(culture = 2, country = 2, district = 3, school = 10, class = c(2,1,3,1,1,1,2,1,2,1), student = ranges(10, 50))
N1 <- c(100, 20)

11. Unfinished function due to no extraction for outputs

test_mean_sigma <- function(seed.id, level=c(2,3,4), c_mean=FALSE, sigma=FALSE){ # option=c("list","vector")
  set.seed(seed.id)

  # if (option=="list"){
  #   n <- vector("list", length=level)
  #   n[[1]] <- sample(seq(1,10),1)
  #   for (i in 1:(n[[1]]-1)){
  #
  #   }
  # } else if (option=="vector") {
    n <- sample(seq(1,20),level,replace=T)
  # } else {
  #   warning("incorrect input for option")
  # }

  # set up n_X
  id <- sample(seq(1,level-1),1)
  n_X <- sample(seq(1,5),id,replace=T)

  # set up c_mean
  if (c_mean==T){
    if (id==1){
      c_mean <- runif(n_X, -1000, 1000)
    } else {
      c_mean <- vector("list", length=id)
      for (i in 1:id){
        c_mean[[i]] <- runif(n_X[i], -1000, 1000)
      }
    }
  } else {
    c_mean <- NULL
  }

  # set up sigma
  if (sigma==T){
    if (id==1){
      sigma <- runif(n_X, 1e-6, 100)
    } else {
      sigma <- vector("list", length=id)
      for (i in 1:id){
        sigma[[i]] <- runif(n_X[i], 1e-6, 100)
      }
    }
  } else {
    sigma <- NULL
  }

  data <- cluster_gen(n, n_X, c_mean, sigma, verbose=F, calc_weights=F)
  # stat <- summarize_clusters(data)
  output <- list(c_mean, sigma, data)
}
wleoncio commented 3 years ago

@Hugo-v587, I did not understand this last part of your report, could you please clarify?

Hugo-v587 commented 3 years ago

I first tried to write a function to extract the core values (mean, sigma, data names, etc.) from the outputs, so that I could do multiple testings and compare the results at the same time. I first assumed the outputs were in the forms of vectors/data frames, like other packages, and then I could save the outputs in the environment. Then I realized that the outputs could only be shown in the console, so this function would not work.

This is an unfinished function, however, I still included it since I thought it could be a good start for the "mass testing." The vision for this function would enable researchers to run multiple sets of data generation at the same time (e.g., mean = c(10,15,20), sigma = c(50,60,80), it would generate three surveys, and then I could compare the estimated means/sigmas in vectors).

Please let me know if you have additional questions.

wleoncio commented 3 years ago

Got it! I'll close the issue, then, but it's nice to have the code here, as it might come in handy when implementing unit tests.