tmatta / lsasim

Simulate large scale assessment data
6 stars 5 forks source link

sigma & cor_matrix #18

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)

8. sigma & cor_matrix

More detailed problems, see 0831-0906 log

Error and warning messages

m1 <- matrix(c(1, 0.2, 0.3, 0.4,
               0.2, 1, 0.5, 0.7,
               0.3, 0.5, 1, 0.8,
               0.4, 0.7, 0.8, 1), 4, 4)
m2 <- matrix(c(1, 0.5, 0.6,
               0.5, 1, 0.9,
               0.6, 0.9, 1), 3, 3)
m3 <- matrix(c(1, 0.55, 0.77,
               0.55, 1, 0.33,
               0.77, 0.33, 1), 3, 3)
m4 <- matrix(c(1, 0.55,
               0.55, 1), 2, 2)
set.seed(12334)
sc1 <- cluster_gen_2(n7, sigma = c(1, 2, 3, 4), cor_matrix = m1)
## Error: length(c_sd) cannot be larger than n_X + theta
#Error: length(c_sd) cannot be larger than n_X + theta
sc2 <- cluster_gen_2(n7, sigma = c(0.5, 0.7, 10), cor_matrix = m2)
## Error: length(c_sd) cannot be larger than n_X + theta
sc3 <- cluster_gen_2(n7, sigma = c(0.2, 0.4, 5), cor_matrix = m3)
## Error: length(c_sd) cannot be larger than n_X + theta
set.seed(12334)
sc4 <- cluster_gen_2(n7, sigma = c(7, 1.5), cor_matrix = m4)
## Error: length(c_sd) cannot be larger than n_X + theta
sc1 <- cluster_gen_2(n7, n_X=4, n_W=0, sigma = c(1, 2, 3, 4), cor_matrix = m1)
summarize_clusters(sc1)
## ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Summary statistics for all schools
##        q1                  q2                  q3                  q4
##  Min.   :-3.605576   Min.   :-7.397607   Min.   :-12.06988   Min.   :-18.261601
##  Mean   :-0.003267   Mean   : 0.003846   Mean   :  0.03168   Mean   :  0.028594
##  Max.   : 4.489504   Max.   : 8.400096   Max.   : 11.95036   Max.   : 15.393644
##
##  Stddev.: 1          Stddev.: 2          Stddev.: 2.99       Stddev.: 4.02
##
##
##
##  Heterogeneous correlation matrix
##           q1        q2        q3        q4
## q1 1.0000000 0.2063884 0.3094543 0.4059252
## q2 0.2063884 1.0000000 0.5036588 0.7020910
## q3 0.3094543 0.5036588 1.0000000 0.8023377
## q4 0.4059252 0.7020910 0.8023377 1.0000000
set.seed(12334)
sc2 <- cluster_gen_2(n7, n_X=2, n_W=1, sigma = c(0.5, 0.7), cor_matrix = m2)
summarize_clusters(sc2)
## ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Summary statistics for all schools
##        q1                  q2            q3
##  Min.   :-2.096478   Min.   :-3.047702   1:8290
##  Mean   :-0.006185   Mean   :-0.003631   2:8959
##  Max.   : 1.974930   Max.   : 2.888648   3:4911
##                                          4:2429
##  Stddev.: 0.5        Stddev.: 0.69       5:2143
##
##                                          Prop.
##                                          1:0.31
##                                          2:0.335
##                                          3:0.184
##                                          4:0.091
##                                          5:0.08
##
##
##
##  Heterogeneous correlation matrix
##           q1        q2        q3
## q1 1.0000000 0.5059057 0.5056551
## q2 0.5059057 1.0000000 0.7381464
## q3 0.5056551 0.7381464 1.0000000
set.seed(12334)
sc3 <- cluster_gen_2(n7, n_X=3, n_W=0, sigma = c(0.2, 0.4, 5), cor_matrix = m3)
summarize_clusters(sc3)
## ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Summary statistics for all schools
##        q1                  q2                  q3
##  Min.   :-0.838591   Min.   :-1.740243   Min.   :-19.29974
##  Mean   :-0.002146   Mean   :-0.002025   Mean   : -0.02129
##  Max.   : 0.789972   Max.   : 1.495702   Max.   : 21.35207
##
##  Stddev.: 0.2        Stddev.: 0.4        Stddev.: 5.09
##
##
##
##  Heterogeneous correlation matrix
##           q1        q2        q3
## q1 1.0000000 0.5578145 0.7759395
## q2 0.5578145 1.0000000 0.3436756
## q3 0.7759395 0.3436756 1.0000000
set.seed(12334)
sc4 <- cluster_gen_2(n7, n_X=2, n_W=0, sigma = c(7, 1.5), cor_matrix = m4)
summarize_clusters(sc4)
## ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Summary statistics for all schools
##        q1                  q2
##  Min.   :-27.66705   Min.   :-5.963463
##  Mean   :  0.02940   Mean   : 0.002929
##  Max.   : 29.42276   Max.   : 6.446907
##
##  Stddev.: 7          Stddev.: 1.49
##
##
##
##  Heterogeneous correlation matrix
##           q1        q2
## q1 1.0000000 0.5416685
## q2 0.5416685 1.0000000
wleoncio commented 3 years ago

Fixed. cluster_gen() was taking c_mean but not sigma into consideration when auto-generating n_X.