modelavgIRT <- function(personscores,personSEs,selectionindex,rescale=TRUE) { ##rescale personscores to have mean 0 and var 1 #rescale personSEs proportionally if(rescale==TRUE){ for(i in seq(ncol(personscores))){ personscores[,i] <- (personscores[,i] - mean(personscores[,i]))/sd(personscores[,i]) personSEs[,i] <- personSEs[,i]/sd(personscores[,i]) } } ##compute weights weights <- c(rep(NA,length(selectionindex))) for(i in seq(length(selectionindex))){ weights[i] <- sum(exp(- .5*selectionindex[1:length(selectionindex)]+.5*selectionindex[i]))^(-1) } ##compute averaged person scores avg.personscore <- matrix(NA,nrow(personscores),1) for(i in seq(nrow(personscores))){ avg.personscore[i,] <- sum(weights*personscores[i,]) } ##compute averaged person SEs avg.personSE <- matrix(NA,nrow(personSEs),1) for(i in seq(nrow(personSEs))){ avg.personSE[i,] <- sum(weights*sqrt(personSEs[i,]^2+(personscores[i,]- avg.personscore[i,])^2)) } output <- list(weights,avg.personscore,avg.personSE) names(output) <- c(“weights”,”Average person score”,”Average person SE”) return(output) }