R 语文组数据分析 step2

本代码包含:

1、难度:通过率、鉴别指数

2、区分度:高低分组、相关

3、科伦巴赫信度

####################################################################################################
#########################################不分维度CTT指标############################################
####################################################################################################

setwd("F:/")#修改工作路径,只含所有分析csv

files<-dir()

xlsxfile1<-paste(1:4,".xlsx",sep="")#也可以csv格式
xlsxfile2<-paste(1:4,".xlsx",sep="")

full<-read.xlsx("F:/满分.xlsx",colNames = F,na.strings="#") #读入满分数据
xd<-c()
for (j in 1:4) {data<-read.csv(file = files[j])
  
##难度1 通过率##
endat<-data[,-1]
endat=matrix(as.numeric(as.matrix(endat)),nrow=nrow(endat))
mean1<-apply(endat,2,mean)


ff<-full[j,]
if (is.na(ff[ncol(ff)])){b=ff[-which(is.na(ff))]}else{b=ff}
nd1<-mean1/b

##难度2 高低分组##

zf<-apply(endat,1,sum)
endatzf<-cbind(endat,zf)
px<-endatzf[order(endatzf[,ncol(endatzf)],decreasing = T),]###########
gf<-px[1:ceiling(nrow(endatzf)*0.27),]
df<-px[-c(1:round(nrow(px)*0.73)),]
gtgl<-apply(gf,2,mean)
dtgl<-apply(df,2,mean)

nd2<-((gtgl+dtgl)/2)/b

nd<-rbind(nd1,nd2)


##区分度1 高低分组##
qfd1<-(gtgl-dtgl)/b

##区分度2 相关##
qfd2<-t(as.matrix(apply(endat,2,function(dat)cor(dat,zf))))
colnames(qfd2)<-colnames(qfd1)
qfd<-rbind(qfd1,qfd2)


##信度##
sumsi<-sum(apply(endat,2,var))
xd[j]<-(ncol(endat)/(ncol(endat)-1))*(1-(sumsi/(var(zf))))

file1=paste("F:/第二步结果/难度/",xlsxfile1[j],sep="")
file2=paste("F:/区分度/",xlsxfile2[j],sep="")

write.xlsx(nd,file=file1)#也可以csv格式
write.xlsx(qfd,file=file2)#

}
print(xd)#打印信度

 

posted @ 2017-04-15 16:50  JoAnna_L  阅读(264)  评论(0编辑  收藏  举报