We are busy people. We spend most of our time analyzing the large-scale national and international assessments for which dexter was developed. So far, we have not had the time to discuss at length the facilities for simulating item response data with dexter. Of course they are there, since simulation plays a vital role in our approach to generating plausible values and modelling in general – see Marsman et al. (2017). But they are somewhat hidden among several ‘functions of theta’ – anyway, here is the overdue introduction to data simulation with dexter.
Simulating IRT data for a single booklet of Rasch items is quite easy – it can be done with a single line in plain R:
The dexter way would be:
We just construct a tibble with the item parameters in the expected format, after which it is a single line again. We now discuss a more interesting and complicated case. The example is by Jesse and the comments by me, so the perception of a certain age difference is inevitable even if not deliberate.
library(mvtnorm) set.seed(42) domains = c('geometry','algebra','measurement') nit = 50 pop_theta = tribble( ~gender, ~school_type, ~geometry, ~algebra, ~measurement, ~sd, ~n, 'boys', 'sbo', -.3, -.5, -.5 , .6, 500, 'girls', 'sbo', -.5, -.5, -.2 , .6, 400, 'boys', 'bao', .7, .5, .2 , 1, 1200, 'girls', 'bao', .5, .5, .5 , 1, 1100 )
tribble, ot transposed tibble, defines the combinations of gender, two Dutch school types, and three domains that will be treated as three highly correlated but distinct abilities. The hypothesized abilities will have a multivariate normal distribution with means varying across domains, sexes, and school types, and standard deviations differing just across school types. The last column has the number of fictional students in each cell.
Here we constructed the tibble that defines the items, just as in the initial example.
sprintf is a much better choice than
paste0 because it produces sortable names: we don’t get items 10 through 19 sorted before item 2, for example. Next, define the correlation matrix for the three domains and use the mvtnorm package to generate the abilities:
This happens in a dplyr pipe that groups by gender and school type, effectively calling
rmvnorm four times and combining the results in a tibble. Now that we have the items and the thetas, call
r_score three times to generate the simulated item responses, and stack the output:
Add the two person properties:
The simulated data is ready now, but we are going to put it in a dexter database and have some more fun with generating an incomplete design. The creation of a dexter database (a.k.a. project) always starts with a set of scoring rules. We shall make some trivial rules, where responses can be only 0 or 1, and will be scored as 0 or 1:
From the rules, we generate an empty database, announcing the two person properties included with the data:
db = start_new_project(dummy_rules, ':memory:', person_properties=list(gender='<unknown>', school_type='<unknown>'))
Now, let us have an incomplete design, 30 items per booklet. SBO students will get the easier booklet, and BAO students will get the more difficult one. In real life, this would be determined by a pretest with a small sample of students, but we will simply sort items on their true difficulty parameters. The easy booklet will contain all items except the 20 most difficult ones, and the difficult booklets all items except the 20 easiest ones; thus, the two booklets have an overlap of 10 items of average difficulty:
items_SBO = arrange(items,beta) |> slice(1:20) |> pull(item_id) items_BAO = arrange(items,beta) |> slice(31:50) |> pull(item_id) add_booklet(db, select(dat, !any_of(items_BAO)) |> filter(school_type=='sbo'), 'sbo_booklet') add_booklet(db, select(dat, !any_of(items_SBO)) |> filter(school_type=='bao'), 'bao_booklet')
Finally, we add the domains as an item property:
We are now ready to check how the models available in dexter will cope with this simulated data set, or how the diagnostic facilities might help us investigate its particular properties.