Skip to content

Instantly share code, notes, and snippets.

@wleoncio
Created April 22, 2024 08:34
Show Gist options
  • Save wleoncio/25c7467a89380b108204975bd6d81774 to your computer and use it in GitHub Desktop.
Save wleoncio/25c7467a89380b108204975bd6d81774 to your computer and use it in GitHub Desktop.
Issue 50 lsasim
# Setup
remotes::install_github("tmatta/lsasim", "issue-50")
#> Using GitHub PAT from the git credential store.
#> Downloading GitHub repo tmatta/lsasim@issue-50
#> 
#> ── R CMD build ─────────────────────────────────────────────────────────────────
#> * checking for file ‘/tmp/RtmpCKm8ak/remotes9c8f72a0c9f7/tmatta-lsasim-940c83a/DESCRIPTION’ ... OK
#> * preparing ‘lsasim’:
#> * checking DESCRIPTION meta-information ... OK
#> * checking for LF line-endings in source and make files and shell scripts
#> * checking for empty or unneeded directories
#> * building ‘lsasim_2.1.4-1713774844.tar.gz’
#> Installing package into '/home/waldir/R/x86_64-pc-linux-gnu-library/4.3'
#> (as 'lib' is unspecified)
library("NAEPirtparams")
library("lsasim")
#> This is lsasim 2.1.4-1713774844
param <- NAEPirtparams::parameters
item_par <- param[param$level %in% 8 & param$subject %in% "Mathematics" & param$year %in% 2015, ]
item_par$item <- sample(1:1e5, nrow(item_par))
item_par <- item_par[1:32, ]  # just to simplify the example, but works just as well without this

item_par_2 <- item_par
item_par_2$item <- seq_len(nrow(item_par_2))

# Block design
block <- lsasim::block_design(n_blocks = 10, item_parameters = item_par)
block_2 <- lsasim::block_design(n_blocks = 10, item_parameters = item_par_2)

# Testing
print(block)
#> $block_assignment
#>       b1    b2    b3    b4    b5    b6    b7    b8    b9   b10
#> i1 78866 51628 16554 46732  1156 31430 63896  8692 18043 11327
#> i2 92135 12114 40122  5634 43552 15308 39110 35460 55405 99933
#> i3 31377 54589 79394 96671  6231 66420 65462 99488 15459 34653
#> i4 54766 15454     0     0     0     0     0     0     0     0
#> 
#> $block_descriptives
#>     block length average difficulty
#> b1             4              0.426
#> b2             4             -0.101
#> b3             3              0.937
#> b4             3             -0.252
#> b5             3             -0.099
#> b6             3              0.507
#> b7             3              0.306
#> b8             3              1.439
#> b9             3              0.928
#> b10            3              0.525
print(block_2)
#> $block_assignment
#>    b1 b2 b3 b4 b5 b6 b7 b8 b9 b10
#> i1  1  2  3  4  5  6  7  8  9  10
#> i2 11 12 13 14 15 16 17 18 19  20
#> i3 21 22 23 24 25 26 27 28 29  30
#> i4 31 32  0  0  0  0  0  0  0   0
#> 
#> $block_descriptives
#>     block length average difficulty
#> b1             4              0.426
#> b2             4             -0.101
#> b3             3              0.937
#> b4             3             -0.252
#> b5             3             -0.099
#> b6             3              0.507
#> b7             3              0.306
#> b8             3              1.439
#> b9             3              0.928
#> b10            3              0.525
identical(block$block_descriptives, block_2$block_descriptives)
#> [1] TRUE

Created on 2024-04-22 with reprex v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment