R/theta.matching.R

#' theta.matching
#' 
#' Because ltm only provides theta estimates for each response pattern, not for each person,
#' this function is made to get the theta estimates for each person according to the person's
#' response pattern
#' 
#' @param data A data frame containing the fata
#' @param item item included in Rasch Analysis
#' @param theta.pattern theta estimate from ltm's factor scores function

theta.matching = function (data, item, theta.pattern) {
  
  theta = c()
  data = data[,item]
  for(i in 1:nrow(data)) {
    if(is.na(data[i,1])){
      theta.pattern.subset = theta.pattern[is.na(theta.pattern[,1]),]
    }else{
      theta.pattern.subset = theta.pattern[theta.pattern[,1] == data[i, 1],]
    }
    
    for(j in 1:nrow(theta.pattern.subset)){
      if(toString(data[i, ]) == toString(theta.pattern.subset[j, item])){
        theta = c(theta, theta.pattern.subset[j, "z1"])
        break
      }  
    }
  }
  cbind(data, theta)
}
changxiulee/BayesianRasch documentation built on Nov. 18, 2019, 6:54 a.m.