function gen_items($space, $covariate) { global $N_ITEMS, $dims, $COVARIATE_NAME; # Create an item bank to store the items. # Setting the property "sizeHint" increases allocation efficiency # It's a bit kludgy, but the php gtk bindings require passing # the name of the object to the objects constructor in order to # set the construction properties. $bank = new OscatsItemBank('OscatsItemBank', array("sizeHint" => $N_ITEMS)); # Create the items for ($i = 0; $i < $N_ITEMS; $i++) { # First we create an IRT model container for our item # We have to specify which dimensions to be used with the "dims" array # (in this case, we use both of the dimensions of the space) $model = new OscatsModelL2p('OscatsModelL2p', array("space" => $space, "dims" => $dims, "covariates" => $covariate)); # Then, set the parameters. Here there are 4: # Discrimination on two dimensions, difficulty, and covariate coef. $model->set_param_by_name("Diff", Oscats::rnd_normal(sqrt(3))); $model->set_param_by_name("Discr.Cont.1", Oscats::rnd_uniform_range(0, 1)); $model->set_param_by_name("Discr.Cont.2", Oscats::rnd_uniform_range(0, 2)); $model->set_param_by_name($COVARIATE_NAME, Oscats::rnd_uniform_range(0.5, 1.5)); # Create an item based on this model # This is equivalent to oscats_item_new(0, model) in C $item = new OscatsItem(0, $model); # Add the item to the item bank $bank->add_item($item); # Since php is garbage collected, we don't have to worry about # reference counting. } return $bank; }
function gen_examinees($space) { global $N_EXAMINEES; $dim = $space->get_dim_by_name("Cont.1"); $ret = array(); for ($i = 0; $i < $N_EXAMINEES; $i++) { # Latent IRT ability parameter. This is a one-dimensional test. $theta = new OscatsPoint('OscatsPoint', array("space" => $space)); # Sample the ability from N(0,1) distribution $theta->set_cont($dim, Oscats::rnd_normal(1)); # Create a new examinee $e = new OscatsExaminee(); # Set the examinee's true (simulated) ability $e->set_sim_theta($theta); $ret[] = $e; } return $ret; }