// globals

function preprocess () {
  

echo ('  require(ltm)\n');
}

function calculate () {
  
  spin_groups     = getValue("spin_groups");
  drop_sumgroups  = getValue("drop_sumgroups");
  rad_pvalue      = getValue("rad_pvalue");
  spin_mc         = getValue("spin_mc");

  
  
  options = array() ;
  if(spin_groups != "10")
    options[] = "G=$spin_groups" ;
  if(drop_sumgroups != "median")
    options[] = "FUN=$drop_sumgroups" ;
  if(rad_pvalue == "montecarlo")
    options[] = "simulate.p.value=TRUE" ;
  if(rad_pvalue == "montecarlo" && spin_mc != "100" )
    options[] = "B=$spin_mc" ;


echo ('itemfit.res <- item.fit(' + getValue("x"));
                  
                  if(options) echo (", "+join(", ", options));
 echo (')\n');
}

function printout () {
echo ('rk.header ("Item-fit statistics (' + getValue("x") + ')")\n');
echo ('rk.print (itemfit.res)\n');
}
