/* import classic item analysis */
data classic; infile "AAAAA1cp1.dat";
input right percent logit pearson biserial;
drop right;
id = _N_;

/* compute curve height of one-parameter model */
data onep; infile "AAAAA1cp2.dat";
input onep_intercept  onep_a  onep_b  onep_disper  onep_g   
onep_chisq  
onep_df 
onep_inter_se 
onep_a_se 
onep_b_se 
onep_disper_se 
onep_g_se 
onep_prob;
drop onep_intercept onep_g onep_disper;
id = _N_;
onep_minus5 =1/(1+EXP(-1*onep_a*(-5-onep_b)*1.7));
onep_minus4 =1/(1+EXP(-1*onep_a*(-4-onep_b)*1.7));
onep_minus3 =1/(1+EXP(-1*onep_a*(-3-onep_b)*1.7));
onep_minus2 =1/(1+EXP(-1*onep_a*(-2-onep_b)*1.7));
onep_minus1 =1/(1+EXP(-1*onep_a*(-1-onep_b)*1.7));
onep_zero =1/(1+EXP(-1*onep_a*(-onep_b)*1.7));
onep_plus1 =1/(1+EXP(-1*onep_a*(1-onep_b)*1.7));
onep_plus2 =1/(1+EXP(-1*onep_a*(2-onep_b)*1.7));
onep_plus3 =1/(1+EXP(-1*onep_a*(3-onep_b)*1.7));
onep_plus4 =1/(1+EXP(-1*onep_a*(4-onep_b)*1.7));
onep_plus5 =1/(1+EXP(-1*onep_a*(5-onep_b)*1.7));

/* compute curve height of two-parameter model */
data twop; infile "AAAAA2cp2.dat";
input twop_intercept  twop_a  twop_b  twop_disper  twop_g   
twop_chisq  
twop_df 
twop_inter_se 
twop_a_se 
twop_b_se 
twop_disper_se 
twop_g_se 
twop_prob;
drop twop_intercept twop_g twop_disper;
id = _N_;
twop_minus5 =1/(1+EXP(-1*twop_a*(-5-twop_b)*1.7));
twop_minus4 =1/(1+EXP(-1*twop_a*(-4-twop_b)*1.7));
twop_minus3 =1/(1+EXP(-1*twop_a*(-3-twop_b)*1.7));
twop_minus2 =1/(1+EXP(-1*twop_a*(-2-twop_b)*1.7));
twop_minus1 =1/(1+EXP(-1*twop_a*(-1-twop_b)*1.7));
twop_zero =1/(1+EXP(-1*twop_a*(-twop_b)*1.7));
twop_plus1 =1/(1+EXP(-1*twop_a*(1-twop_b)*1.7));
twop_plus2 =1/(1+EXP(-1*twop_a*(2-twop_b)*1.7));
twop_plus3 =1/(1+EXP(-1*twop_a*(3-twop_b)*1.7));
twop_plus4 =1/(1+EXP(-1*twop_a*(4-twop_b)*1.7));
twop_plus5 =1/(1+EXP(-1*twop_a*(5-twop_b)*1.7));

/* compute curve height of three-parameter model */
data thrp; infile "AAAAA3cp2.dat";
input thrp_intercept  thrp_a  thrp_b  thrp_disper  thrp_g   
thrp_chisq  
thrp_df 
thrp_inter_se 
thrp_a_se 
thrp_b_se 
thrp_disper_se 
thrp_g_se 
thrp_prob;
drop thrp_intercept thrp_disper;
id = _N_;
thrp_minus5 =thrp_g+((1-thrp_g)*(1/(1+EXP((-5-thrp_b)*1.7*thrp_a*-1))));
thrp_minus4 =thrp_g+((1-thrp_g)*(1/(1+EXP((-4-thrp_b)*1.7*thrp_a*-1))));
thrp_minus3 =thrp_g+((1-thrp_g)*(1/(1+EXP((-3-thrp_b)*1.7*thrp_a*-1))));
thrp_minus2 =thrp_g+((1-thrp_g)*(1/(1+EXP((-2-thrp_b)*1.7*thrp_a*-1))));
thrp_minus1 =thrp_g+((1-thrp_g)*(1/(1+EXP((-1-thrp_b)*1.7*thrp_a*-1))));
thrp_zero =thrp_g+((1-thrp_g)*(1/(1+EXP((-thrp_b)*1.7*thrp_a*-1))));
thrp_plus1 =thrp_g+((1-thrp_g)*(1/(1+EXP((1-thrp_b)*1.7*thrp_a*-1))));
thrp_plus2 =thrp_g+((1-thrp_g)*(1/(1+EXP((2-thrp_b)*1.7*thrp_a*-1))));
thrp_plus3 =thrp_g+((1-thrp_g)*(1/(1+EXP((3-thrp_b)*1.7*thrp_a*-1))));
thrp_plus4 =thrp_g+((1-thrp_g)*(1/(1+EXP((4-thrp_b)*1.7*thrp_a*-1))));
thrp_plus5 =thrp_g+((1-thrp_g)*(1/(1+EXP((5-thrp_b)*1.7*thrp_a*-1))));

/* output all data to a text file */
data final; merge classic onep twop thrp; by id;
onep_fit = onep_chisq/onep_df;
twop_fit = twop_chisq/twop_df;
thrp_fit = thrp_chisq/thrp_df;
file "AAAAA_final.txt" lrecl=1028;
put 
id percent logit pearson biserial  
onep_a  
onep_b    
onep_chisq  
onep_df 
onep_fit
onep_inter_se 
onep_a_se 
onep_b_se 
onep_disper_se 
onep_g_se 
onep_prob
onep_minus5 
onep_minus4 
onep_minus3 
onep_minus2 
onep_minus1 
onep_zero 
onep_plus1 
onep_plus2 
onep_plus3 
onep_plus4 
onep_plus5

twop_a  
twop_b    
twop_chisq  
twop_df 
twop_fit
twop_inter_se 
twop_a_se 
twop_b_se 
twop_disper_se 
twop_g_se 
twop_prob
twop_minus5 
twop_minus4 
twop_minus3 
twop_minus2 
twop_minus1 
twop_zero 
twop_plus1 
twop_plus2 
twop_plus3 
twop_plus4 
twop_plus5

thrp_a  
thrp_b  
thrp_g 
thrp_chisq  
thrp_df 
thrp_fit
thrp_inter_se 
thrp_a_se 
thrp_b_se 
thrp_disper_se 
thrp_g_se 
thrp_prob
thrp_minus5 
thrp_minus4 
thrp_minus3 
thrp_minus2 
thrp_minus1 
thrp_zero 
thrp_plus1 
thrp_plus2 
thrp_plus3 
thrp_plus4 
thrp_plus5
;

/* create tables of option (distractor) X theta (ability) */
ods html file="AAAAA.html";
data theta; infile "AAAAA.theta";
input SID $1-12  @13 (q1-qGGGGG) (1.0) t1 se1 t2 se2 t3 se3;
data new; set theta;
t1r = round(t1);
t2r = round(t2);
t3r = round(t3);
proc freq; tables (q1-qGGGGG) * t1r /nopercent norow;
proc freq; tables (q1-qGGGGG) * t2r /nopercent norow; 
proc freq; tables (q1-qGGGGG) * t3r /nopercent norow; 
quit;
ods html close;
run;