program accov !ccccccccccccccccccccccccccccccccccccccccccccccccccccccccc !ccccc cccc !ccccc This program will read in 0-1 test data cccc !ccccc and calculate the matrix of average cccc !ccccc conditional covariances. BH 1/12/04 cccc !ccccc cccc !ccccccccccccccccccccccccccccccccccccccccccccccccccccccccc parameter (maxitem=100,maxexmn=10000) !ccccc Be sure to set the parameter values in the subroutines as well integer okcheck,nexmn,nitem,i,j character*20 datflnm integer respmat(maxexmn,maxitem) real covmat(maxitem,maxitem) /(maxitem*maxitem)*0.0/ !ccccc Read in the data call read01test(nexmn,nitem,respmat,okcheck) !ccccc If the data has been read in correctly then !ccccc allow the user to see the average conditional !ccccc covariance for any item pair they select. if (okcheck.eq.0) then write(*,*) write(*,*) 'Hit enter to calculate ' write(*,*) read(*,*) call acc(nexmn,nitem,respmat,covmat) do 500 while (i.ne.999) write(*,*) write(*,*) 'Enter item 1 (or 999 to quit)' read(*,*) i if (i.ne.999) then write(*,*) 'Enter item 2' read(*,*) j write(*,*) write(*,*) 'The conditional covariance for' write(*,*) 'item ',i,' and item',j,' is ', covmat(i,j) endif 500 continue endif !ccccc End main body of program stop end !ccccccccccccccccccccccccccccccccccccccccccccccccccccccccc !ccccc cccc !ccccc Begin Subroutines cccc !ccccc cccc !ccccccccccccccccccccccccccccccccccccccccccccccccccccccccc subroutine read01test(nexmn,nitem,respmat,okcheck) !ccccc This Subroutine will read in a 01 data set with no spaces. parameter (maxitem=100,maxexmn=10000) !ccccc Make sure these parameters match the main program. !ccccc Also, be sure that dataline is *maxitem and also that !ccccc line 9000 is amaxitem integer okcheck,nexmn,nitem,i,j character*20 datflnm integer respmat(maxexmn,maxitem) character*100 dataline 9000 format(a100) !ccccc get the file name write(*,*) write(*,*) 'Enter the name of the file containing' write(*,*) 'the exam data. Each row should be a' write(*,*) 'separate examinee with no ID or spaces' write(*,*) 'between the items.' write(*,*) read(*,*) datflnm !ccccc open the file and read in the data, counting the number !ccccc of examinees and the number of items write(*,*) write(*,*) 'Now reading in the raw data' write(*,*) 'contained in the file ',datflnm write(*,*) open(file=datflnm,unit=8) nexmn=0 nitem=0 !ccccc Read in the first line and count the number of items. !ccccc Note that we set okcheck to be 1 if there is a non-01 !ccccc data point, and to be 3 if the data set is empty. !ccccc 2 is a temporary setting to break the loop if there !ccccc is a blank line at the end. okcheck=0 read(8,9000,end=8510) dataline nexmn=nexmn+1 j=0 do 1000 while(okcheck.eq.0) j=j+1 if (dataline(j:j).eq.'1') then respmat(nexmn,j)=1 nitem=j elseif(dataline(j:j).eq.'0') then respmat(nexmn,j)=0 nitem=j else okcheck=1 endif 1000 continue !ccccc Read in the remaining lines of the data set. okcheck=0 do 1050 while(okcheck.eq.0) read(8,9000,end=8510) dataline nexmn=nexmn+1 j=0 do 1060 while((okcheck.eq.0).and.(j.lt.nitem)) j=j+1 if (dataline(j:j).eq.'1') then respmat(nexmn,j)=1 elseif( dataline(j:j).eq.'0') then respmat(nexmn,j)=0 elseif (j.eq.1) then okcheck=2 else okcheck=1 endif 1060 continue 1050 continue 8510 continue !ccccc deal with error messages if (okcheck.eq.2) then okcheck=0 endif if (okcheck.eq.1) then write(*,*) write(*,*) 'There was an error reading in' write(*,*) 'examinee',nexmn,'.' write(*,*) elseif (nexmn.eq.0)then write(*,*) write(*,*) 'The data set was empty!' write(*,*) okcheck=3 else write(*,*) write(*,*) 'Read successful:' write(*,*) ' Number of items=',nitem write(*,*) ' Number of examinees=',nexmn write(*,*) endif !ccccc End of read01test subroutine return end subroutine acc(nexmn,nitem,respmat,covmat) !ccccc This subroutine will calculate all the pairwise !ccccc conditional covariances. parameter (maxitem=100,maxexmn=10000) !ccccc Make sure these parameters match the main program. integer nexmn,nitem,i,j,k,scoretemp integer respmat(maxexmn,maxitem) integer score(maxexmn) /maxexmn*0/ integer strata(0:1,0:1,0:(maxitem-2)) /(4*(maxitem-1))*0/ integer p1,p2 real covmat(maxitem,maxitem) real n,ntotal do 2000 i=1,nexmn do 2010 j=1,nitem score(i)=score(i)+respmat(i,j) 2010 continue 2000 continue !ccccc See notes in class for the logic here. do 2020 i=1,(nitem-1) do 2030 j=(i+1),nitem do 2040 k=1,nexmn scoretemp=score(k)-respmat(k,i)-respmat(k,j) strata(respmat(k,i),respmat(k,j),scoretemp)= c strata(respmat(k,i),respmat(k,j),scoretemp)+1 2040 continue ntotal=0.0 do 2050 k=0,(nitem-2) n=strata(0,0,k)+strata(0,1,k)+strata(1,0,k)+strata(1,1,k)+0.0 p11=strata(1,1,k) p1=strata(1,0,k)+strata(1,1,k) p2=strata(0,1,k)+strata(1,1,k) if (n.gt.1) then ntotal=ntotal+n covmat(i,j)=covmat(i,j)+n*(p11/n-(p1/n)*(p2/n)) endif strata(0,0,k)=0 strata(0,1,k)=0 strata(1,0,k)=0 strata(1,1,k)=0 2050 continue covmat(i,j)=covmat(i,j)/ntotal covmat(j,i)=covmat(i,j) 2030 continue 2020 continue !ccccc End of acc subroutine return end !ccccccccccccccccccccccccccccccccccccccccccccccccccccccccc !ccccc cccc !ccccc End Subroutines cccc !ccccc and Program cccc !ccccc cccc !ccccccccccccccccccccccccccccccccccccccccccccccccccccccccc