The program automatically simulates the values of the Rasch model parameters, and # randomly generates a data set from those parameters, before computing all the 36 # person fit statistics. However, simple modifications of the commands in the "Initiate()" # function allow the user to input his/her own data set, and/or input his/her parameter # estimates (of any IRT model), before computing the 36 fit statistics. # # # # THREE STEPS TO CALCULATE 36 PERSON FIT STATISTICS # # (1) ENTER APPROPRIATE SPECIFICATIONS WITHIN THE # "Initiate" FUNCTION BELOW, INCLUDING DATA, # RASCH PARAMETER ESTIMATES, NUMBER OF PERSONS, NUMBER OF ITEMS, # ETC. # # (2) SAVE THIS PROGRAM, AND THEN, # WHILE STILL IN THIS COMMAND WINDOW, HIT "F10" # TO READ YOUR UPDATES # # (3) WITH YOUR CURSOR, HIGHLIGHT THIS COMMAND: RUNIT() # AND THEN HIT "F10" TO GENERATE THE RESULTS # OF THE 36 PERSON FIT STATISTICS IN THE BOTTOM OF THIS WINDOW # THE RESULTS WILL ASLO APPEAR IN A MATRIX NAMED "RESULTS", # IN THE "Object Explorer"WINDOW OF S-PLUS INITIATE <<- function(){ options(object.size=8000000) # PROGRAM SETUP--------------------------------------------------------------------------------#-----------------------------------------------------------------------------------------------------------------------# IN THE NEXT SIX LINES ENTER THE NUMBER (N) OF PERSONS, # THE NUMBER (L) OF TEST ITEMS, YOU WISH TO ANALYZE; # ALSO ENTER THE NUMBER OF ITEMS IN EACH OF THE THREE # TEST SUBSETS (FOR PERSON FIT METHODS BASED ON GROUPING TEST ITEMS) #-----------------------------------------------------------------------------------------------------------------------N <<- 100 # ENTER Number of persons L <<- 40 # ENTER Number of test items S <<- 3 # ENTER Number of item subsets s.1 <<- 13 # ENTER Number of item in subset 1 s.2 <<- 14 # ENTER Number of item in subset 2 s.3 <<- 13 # ENTER Number of items in subset 3 # # #====================================================================== # Simulate parameters of a Rasch model #====================================================================== theta <<- sort(runif(N,-3,3)) ##THIS COMMAND SIMULATES L PERSON ABILITY PARAMETERS FROM A UNIFORM U(-3,3) DISTRIBUTION #BUT YOU MAY YOU MAY INSTEAD ENTER ANY SET OF N ESTIMATES OF THE ABILITY PARAMETER delta <<- sort(runif(L,-3,3)) ##THIS COMMAND SIMULATES L ITEM DIFFICULTY PARAMETER VALUES FROM A UNIFORM U(-3,3) DISTRIBUTION #BUT HERE YOU MAY INSTEAD ENTER ANY SET OF L ESTIMATES OF THE ITEM DIFFICULTY PARAMETER logs <<- (matrix(theta,N,1) %*% matrix(1,1,L)) - (matrix(1,N,1) %*% matrix(delta,1,L)) probs <<- (1+exp(-logs))^-1 delta.matrix <<- matrix(1,N,1) %*% matrix(delta,1,L) # # #======================================================================# # Generate a Simulated Data Set (or enter your own data set) #====================================================================== # NOTE: YOU MAY INSTEAD WISH TO ENTER YOUR OWN (REAL) DATA MATRIX # INTO AN OBJECT CALLED "Data" # IF YOU WISH TO USE REAL DATA, # THEN YOU DON'T NEED TO USE THE NEXT 5 LINES OF CODE Data <<- ifelse(matrix(runif(N*L),N,L)>probs,0,1) # Generate data Data <<- t(rbind(Data,(N-colSums(Data)))) Data <<- t(Data[order(Data[,(N+1)]),-(N+1)]) Data <<- cbind(Data,(rowSums(Data))) Data <<- Data[order(Data[,(L+1)]),-(L+1)] #-------------------------------------------------------------------------------------------------------- ---------------return()} # ******YOU NEED NOT MODIFY ANY OF THE REMAINING CODE BELOW # ******YOU NEED NOT MODIFY ANY OF THE REMAINING CODE BELOW # ******YOU NEED NOT MODIFY ANY OF THE REMAINING CODE BELOW FITANALYSIS1 <<- function(){ # elements of Van der Flier statistics #-------------------------------------------------------------------------------------------------------# Person/item scores & proportions # r <<- rowSums(Data) # Person score r i.sc <<- colSums(Data) # Item score s r.matrix <<- matrix(r,N,1) %*% matrix(1,1,L) s.matrix <<- matrix(1,N,1) %*% matrix(i.sc,1,L) p.cor.n <<- (r/L) # Proportion correct by person n p.cor.i <<- (i.sc/N) # Proportion correct by item i p.cor.i.matrix <<- t(matrix(p.cor.i,L,N)) # # Create Guttman & Anti-Guttman matrices # gutt <- r.matrix - t(matrix(1:L,L,N)) gutt <<- ifelse(gutt<0,0,1) antigutt <- (L-r.matrix) - t(matrix(1:L,L,N)) antigutt <<- ifelse(antigutt<0,1,0) log.p.i <<- log(p.cor.i.matrix / (1-p.cor.i.matrix)) U.a <<- rowSums(gutt * log.p.i,na.rm=T) U.b <<- rowSums(Data * log.p.i,na.rm=T) U.c <<- rowSums(antigutt * log.p.i,na.rm=T) a.1 <<- rowSums(p.cor.i.matrix * log.p.i,na.rm=T) a.2 <<- (rowSums(p.cor.i.matrix * (1-p.cor.i.matrix) * log.p.i,na.rm=T)) / (rowSums(p.cor.i.matrix * (1p.cor.i.matrix),na.rm=T)) a.3 <<- r - rowSums(p.cor.i.matrix,na.rm=T) a <<- a.1 + (a.2*a.3) E.U3 <<- (U.a-a) / (U.a-U.c) b.1 <<- rowSums(p.cor.i.matrix * (1-p.cor.i.matrix) * (log.p.i^2),na.rm=T) b.2 <<- (rowSums(p.cor.i.matrix * (1-p.cor.i.matrix) * log.p.i,na.rm=T))^2 b.3 <<- rowSums(p.cor.i.matrix * (1-p.cor.i.matrix),na.rm=T) b <<- (b.1 - (b.2/b.3)) sd.U3 <<- (sqrt(b)) / (abs(U.a - U.c)) # # elements of Sijitsma H statistic # sig.ij <<- var(t(Data),t(Data),unbiased=F) diag(sig.ij) <<- rep(0,N) H.num <<- apply(sig.ij,1,sum) H.denom1 <<- matrix(p.cor.n,N,1) %*% matrix(1-p.cor.n,1,N) #Bi(1-Bj) H.denom2 <<- matrix(1-p.cor.n,N,1) %*% matrix(p.cor.n,1,N) #(1-Bi)Bj H.denom <<- ifelse(H.denom1>H.denom2,H.denom2,H.denom1) diag(H.denom) <<- rep(0,N) H.denom <<- apply(H.denom,1,sum) # # IRT probability elements # IRT.var <<- probs*(1-probs) IRT.resid <<- (Data-probs) IRT.sq.resid <<- (Data-probs)^2 IRT.sqstan.resid <<- IRT.sq.resid / IRT.var inv.IRT.var <<- 1/IRT.var U.sd <<- sqrt((rowSums(inv.IRT.var) - (4*L)) / (L^2)) W.sd <<- (sqrt((rowSums(IRT.var,na.rm=T)) - (4*(rowSums(IRT.var^2,na.rm=T))))) / (rowSums(IRT.var,na.rm=T)) UW1.sd <<- sqrt((rowSums(inv.IRT.var[,1:s.1]) - (4*s.1))/(s.1^2)) UW2.sd <<- sqrt((rowSums(inv.IRT.var[,(s.1+1):(s.1+s.2)]) - (4*s.2))/(s.2^2)) UW3.sd <<- sqrt((rowSums(inv.IRT.var[,(s.1+s.2+1):L]) - (4*s.3))/(s.3^2)) UB.sd <<- (2 / (S-1))^.5 UBa <<- rowSums(IRT.sq.resid[,1:s.1],na.rm=T)/rowSums(IRT.var[,1:s.1],na.rm=T) UBb <<rowSums(IRT.sq.resid[,(s.1+1):(s.1+s.2)],na.rm=T)/rowSums(IRT.var[,(s.1+1):(s.1+s.2)],na.rm=T) UBc <<- rowSums(IRT.sq.resid[,(s.1+s.2+1):L],na.rm=T)/rowSums(IRT.var[,(s.1+s.2+1):L],na.rm=T) # # Elements of ECI statistics group.probs <<- matrix(1,N,1) %*% matrix(colMeans(probs,na.rm=T),1,L) IRT.probs.mean <<- matrix(rowMeans(probs,na.rm=T),N,1) %*% matrix(1,1,L) PY <<- (probs - Data) # # Elements of Likelihood statistics l.matrix <<- (Data*log(probs)) + ((1-Data)*log(1-probs)) l <<- rowSums(l.matrix,na.rm=T) E.l.matrix <<- (probs*log(probs)) + ((1-probs)*log(1-probs)) E <<- rowSums(E.l.matrix,na.rm=T) var.l.matrix <<- probs*(1-probs)*((log(probs/(1-probs)))^2) var.l <<- rowSums(var.l.matrix,na.rm=T) l.m.num <<- ((rowSums(l.matrix[,1:s.1],na.rm=T)) - (rowSums(E.l.matrix[,1:s.1],na.rm=T))) + ((rowSums(l.matrix[,(s.1+1):(s.1+s.2)],na.rm=T)) (rowSums(E.l.matrix[,(s.1+1):(s.1+s.2)],na.rm=T))) + ((rowSums(l.matrix[,(s.1+s.2+1):L],na.rm=T)) (rowSums(E.l.matrix[,(s.1+s.2+1):L],na.rm=T))) l.m.den <<- (rowSums(var.l.matrix[,1:s.1],,na.rm=T)) + ((rowSums(var.l.matrix[,(s.1+1):(s.1+s.2)],,na.rm=T))) + ((rowSums(var.l.matrix[,(s.1+s.2+1):L],,na.rm=T))) # ## elements of p value for Molenaar's M statistic m.M1 <<- rowSums((-delta.matrix)*probs,na.rm=T) sd.M.11 <<- rowSums((-delta.matrix)*(-delta.matrix)*probs*(1-probs),na.rm=T) sd.M.12 <<- rowSums((-delta.matrix)*probs*(1-probs),na.rm=T) sd.M.22 <<- rowSums(probs*(1-probs),na.rm=T) kappa03 <<- rowSums(((-delta.matrix)^0)*(1^3)*probs*(1-probs)*(1-(2*probs)),na.rm=T) kappa12 <<- rowSums(((-delta.matrix)^1)*(1^2)*probs*(1-probs)*(1-(2*probs)),na.rm=T) kappa21 <<- rowSums(((-delta.matrix)^2)*(1^1)*probs*(1-probs)*(1-(2*probs)),na.rm=T) kappa30 <<- rowSums(((-delta.matrix)^3)*(1^0)*probs*(1-probs)*(1-(2*probs)),na.rm=T) beta.M <<- sd.M.12/sd.M.22 m.M <<- m.M1 - ((kappa12 - (beta.M*kappa03)) / (2*sd.M.22)) var.M <<- sd.M.11 - ((sd.M.12^2)/(sd.M.22)) gam <<- ((kappa30) - (3*beta.M*kappa21) + (3*(beta.M^2)*kappa12) - ((beta.M^3)*kappa03)) / (sqrt(var.M)^3) # return()} FITANALYSIS <<- function(){ # #************************************************************************************* ** # 1. Guttman statistic (Guttman, 1944) # g.data <- Data[,-1] h.data <- Data[,-L] Gni <- g.data * (1-h.data) G <<- rowSums(Gni) #************************************************************************************* ** # 2. Normed Guttman statistic (Van der Flier, 1977) # Gstar <<- G / (r*(L-r)) # #************************************************************************************* ** # 3. Personal biserial correlation (Donlan & F. Fischer, 1968), non-parametric # pbs <<- diag(cor(t(Data),t(s.matrix),unbiased=F)) # #************************************************************************************* ** # 4. Caution index (Sato, 1975) # Caution <<- 1 - ((diag(var(t(Data),t(s.matrix),unbiased=F))) / (diag(var(t(gutt),t(s.matrix),unbiased=F)))) # #************************************************************************************* ** # 5. Modified Caution index (Harnisch & Linn, 1981) # MCI <<- (diag(var(t(gutt),t(p.cor.i.matrix),unbiased=F)) - diag(var(t(Data),t(p.cor.i.matrix),unbiased=F))) / (diag(var(t(gutt),t(p.cor.i.matrix),unbiased=F)) - diag(var(t(antigutt),t(p.cor.i.matrix),unbiased=F))) # #************************************************************************************* ** # 6. U3 (Van der Flier, 1982) # U3 <<- (U.a-U.b) / (U.a-U.c) # #************************************************************************************* ** # 7. ZU3 (Van der Flier, 1982) # ZU3 <<- (U3 - E.U3) / (sd.U3) # #************************************************************************************* ** #8. H statistic (Sijtsma, 1986) # H <<- H.num / H.denom # #************************************************************************************* ** # 9-11. A,D,E (Kane & Brennan, 1980) # A <<- rowSums(Data*p.cor.i.matrix,na.rm=T) D <<- rowSums(p.cor.i.matrix*gutt,na.rm=T) - A Ei <<- A / rowSums(p.cor.i.matrix*gutt,na.rm=T) # #************************************************************************************* ** # 12-17. Mean squares & standardized mean squares # U <<- rowMeans(IRT.sqstan.resid,na.rm=T) ZU <<- ((U^(1/3))-1)*(3/(U.sd)) + (U.sd/3) # Smith, 1986 W <<- rowSums(IRT.sq.resid,na.rm=T) / rowSums(IRT.var,na.rm=T) ZW <<- ((W^(1/3))-1)*(3/(W.sd)) + (W.sd/3) # Smith, 1986 ln.U <<- (log(U) + U - 1) * (sqrt((L-1)/8)) ln.W <<- (log(W) + W - 1) * (sqrt((L-1)/8)) # #************************************************************************************* ** # 18-27. ECIs # ECI1 <<- 1 - ((diag(var(t(Data),t(s.matrix),unbiased=F,na.method="include"))) / (diag(var(t(probs),t(s.matrix),unbiased=F,na.method="include")))) ECI2 <<- 1 - ((diag(var(t(Data),t(group.probs),unbiased=F,na.method="include"))) / (diag(var(t(probs),t(group.probs),unbiased=F,na.method="include")))) ECI3 <<- 1 - ((diag(cor(t(Data),t(group.probs),unbiased=F,na.method="include"))) / (diag(cor(t(probs),t(group.probs),unbiased=F,na.method="include")))) ECI4 <<- 1 - ((diag(var(t(Data),t(probs),unbiased=F,na.method="include"))) / (diag(var(t(probs),t(group.probs),unbiased=F,na.method="include")))) ECI5 <<- 1 - ((diag(cor(t(Data),t(probs),unbiased=F,na.method="include"))) / (diag(cor(t(probs),t(group.probs),unbiased=F,na.method="include")))) ECI6 <<- 1 - ((diag(var(t(Data),t(probs),unbiased=F,na.method="include"))) / (rowVars(probs,unbiased=F,na.rm=T))) ECI1z <<- (diag(var(t(PY),t(s.matrix),unbiased=F,na.method="include"))*L) / sqrt(rowSums((((s.matrix matrix(mean(i.sc),N,L))^2)*IRT.var),na.rm=T)) ECI2z <<- (diag(var(t(PY),t(group.probs),unbiased=F,na.method="include"))*L) / sqrt(rowSums((((group.probs - matrix(mean(group.probs[1,]),N,L))^2)*IRT.var),na.rm=T)) ECI4z <<- (diag(var(t(PY),t(probs),unbiased=F,na.method="include"))*L) / sqrt(rowSums((((probs IRT.probs.mean)^2)*IRT.var),na.rm=T)) ECI6z <<- ECI4z # #************************************************************************************* ** # 28-29. Likelihood l (Levine & Rubin, 1979) and standardized l (Drasgow et al., 1985) # l <<- l lz <<- (l - E)/(sqrt(var.l)) # #************************************************************************************* ** # 30-31. M statisticS (Molenaar & Hoijtink, 1990) # M <<- (rowSums(Data*delta.matrix,na.rm=T)) * -1 ZM <<- (M - m.M) / sqrt(var.M) M.pvalue <<- pnorm(ZM) - (((dnorm(ZM))*((ZM^2)-1)*gam)/6) #Bedrick # #************************************************************************************* ** # 32-36. Item group person fit statistics # D.theta.W1 <<- rowMeans(IRT.sq.resid[,1:s.1],na.rm=T) D.theta.W2 <<- rowMeans(IRT.sq.resid[,(s.1+1):(s.1+s.2)],na.rm=T) D.theta.W3 <<- rowMeans(IRT.sq.resid[,(s.1+s.2+1):L],na.rm=T) D.theta <<- D.theta.W1 + D.theta.W2 + D.theta.W3 lzm <<- l.m.num / l.m.den UB <<- (1/(S-1)) * (UBa+UBb+UBc) ZUB <<- ((UB^(1/3))-1)*(3/(UB.sd)) + (UB.sd/3) # Smith, 1986 ln.UB <<- (log(UB) + UB - 1) * (sqrt((S-1)/8)) UW1 <<- rowMeans(IRT.sqstan.resid[,1:s.1],na.rm=T) ZUW1 <<- ((UW1^(1/3))-1)*(3/(UW1.sd)) + (UW1.sd/3) # Smith, 1986 ln.UW1 <<- (log(UW1) + UW1 - 1) * (sqrt((s.1-1)/8)) UW2 <<- rowMeans(IRT.sqstan.resid[,(s.1+1):(s.1+s.2)],na.rm=T) ZUW2 <<- ((UW2^(1/3))-1)*(3/(UW2.sd)) + (UW2.sd/3) # Smith, 1986 ln.UW2 <<- (log(UW2) + UW2 - 1) * (sqrt((s.2-1)/8)) UW3 <<- rowMeans(IRT.sqstan.resid[,(s.1+s.2+1):L],na.rm=T) ZUW3 <<- ((UW3^(1/3))-1)*(3/(UW3.sd)) + (UW3.sd/3) # Smith, 1986 ln.UW3 <<- (log(UW3) + UW3 - 1) * (sqrt((s.3-1)/8)) ln.UW1 <<- ifelse((ln.UW1==-Inf) | (ln.UW1==+Inf),NA,ln.UW1) ln.UW2 <<- ifelse((ln.UW2==-Inf) | (ln.UW2==+Inf),NA,ln.UW2) ln.UW3 <<- ifelse((ln.UW3==-Inf) | (ln.UW3==+Inf),NA,ln.UW3) # return()} RUNIT <<- function(){ INITIATE() FITANALYSIS1() FITANALYSIS() RESULTS <<- cbind(G,Gstar) RESULTS <<- cbind(RESULTS,pbs) RESULTS <<- cbind(RESULTS,Caution) RESULTS <<- cbind(RESULTS,MCI) RESULTS <<- cbind(RESULTS,U3) RESULTS <<- cbind(RESULTS,ZU3) RESULTS <<- cbind(RESULTS,H) RESULTS <<- cbind(RESULTS,A) RESULTS <<- cbind(RESULTS,D) RESULTS <<- cbind(RESULTS,Ei) RESULTS <<- cbind(RESULTS,U) RESULTS <<- cbind(RESULTS,ZU) RESULTS <<- cbind(RESULTS,W) RESULTS <<- cbind(RESULTS,ZW) RESULTS <<- cbind(RESULTS,ln.U) RESULTS <<- cbind(RESULTS,ln.W) # (Drasgow et al. 199 RESULTS <<- cbind(RESULTS,ECI1) RESULTS <<- cbind(RESULTS,ECI2) RESULTS <<- cbind(RESULTS,ECI3) RESULTS <<- cbind(RESULTS,ECI4) RESULTS <<- cbind(RESULTS,ECI5) RESULTS <<- cbind(RESULTS,ECI6) RESULTS <<- cbind(RESULTS,ECI1z) RESULTS <<- cbind(RESULTS,ECI2z) RESULTS <<- cbind(RESULTS,ECI4z) RESULTS <<- cbind(RESULTS,ECI6z) RESULTS <<- cbind(RESULTS,l) RESULTS <<- cbind(RESULTS,lz) RESULTS <<- cbind(RESULTS,M) RESULTS <<- cbind(RESULTS,M.pvalue) RESULTS <<- cbind(RESULTS,D.theta) RESULTS <<- cbind(RESULTS,lzm) RESULTS <<- cbind(RESULTS,UB) RESULTS <<- cbind(RESULTS,ZUB) RESULTS <<- cbind(RESULTS,ln.UB) RESULTS <<- round(RESULTS,3) N <<- L <<- S <<- s.1 <<- s.2 <<- s.3 <<- logs <<- probs <<- delta.matrix <<- r <<- i.sc <<- r.matrix <<c() s.matrix <<- p.cor.n <<- p.cor.i <<- p.cor.i.matrix <<- gutt <<- antigutt <<- antigutt <<- log.p.i <<- c() U.a <<- U.b <<- U.c <<- a.1 <<- a.2 <<- a.3 <<- a <<- E.U3 <<- b.1 <<- b.2 <<- b.3 <<- b <<- sd.U3 <<c() sig.ij <<- H.num <<- H.denom1 <<- H.denom2 <<- H.denom <<- var.l <<- c() H.denom <<- IRT.var <<- IRT.resid <<- IRT.sq.resid <<- IRT.sqstan.resid <<- inv.IRT.var <<- c() U.sd <<- W.sd <<- UW1.sd <<- UW2.sd <<- UW3.sd <<- UB.sd <<- UBa <<- UBb <<- UBc <<- c() group.probs <<- IRT.probs.mean <<- PY <<- l.matrix <<- l <<- E.l.matrix <<- E <<- var.l.matrix <<- c() l.m.num <<- l.m.den <<- m.M1 <<- sd.M.11 <<- sd.M.12 <<- sd.M.22 <<- kappa03 <<- kappa12 <<- c() kappa21 <<- kappa30 <<- beta.M <<- m.M <<- var.M <<- gam <<- g.data <<- h.data <<- Gni <<- G <<c() Gstar <<- pbs <<- Caution <<- MCI <<- U3 <<- ZU3 <<- H <<- A <<- D <<- Ei <<- U <<- ZU <<- W <<c() ZW <<- ln.U <<- ln.W <<- ECI1 <<- ECI2 <<- ECI3 <<- ECI4 <<- ECI5 <<- ECI6 <<- ECI1z <<ECI2z <<- c() ECI4z <<- ECI6z <<- ECI4z <<- l <<- lz <<- M <<- ZM <<- M.pvalue <<- D.theta.W1 <<- D.theta.W2 <<- c() D.theta.W3 <<- D.theta <<- lzm <<- UB <<- ZUB <<- ln.UB <<- UW1 <<- ZUW1 <<- ln.UW1 <<- UW2 <<- c() random <<- ZUW2 <<- ln.UW2 <<- UW3 <<- ZUW3 <<- ln.UW3 <<- ln.UW1 <<- ln.UW2 <<- ln.UW3 <<- c() return(RESULTS)}