// globals

function preprocess () {
  

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

function calculate () {
  
  rad_hypot       = getValue("rad_hypot");
  rad_resppat     = getValue("rad_resppat");
  mtx_resppat     = getValue("mtx_resppat");
  rad_pvalue      = getValue("rad_pvalue");
  spin_mc         = getValue("spin_mc");

  
  
  options = array() ;
  if(rad_hypot == "greater" || rad_hypot == "two.sided")
    options[] = "alternative=\"$rad_hypot\"" ;
  if(rad_resppat == "resp_matrix" && mtx_resppat)
    options[] = "resp.patterns=$mtx_resppat" ;
  if(rad_pvalue == "montecarlo")
    options[] = "simulate.p.value=TRUE" ;
  if(rad_pvalue == "montecarlo" && spin_mc != "1000" )
    options[] = "B=$spin_mc" ;


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

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