38 lines
1.1 KiB
R
38 lines
1.1 KiB
R
## File Name: res_ij.R
|
|
## File version: 1.0
|
|
|
|
#' Compute rasch person-item residuals
|
|
#'
|
|
#' This function computes person-item residuals for rasch family adjacent-categories models
|
|
#' like the Rasch model or the PCM
|
|
#'
|
|
#' @param thetahat_i Person parameter estimate for person i
|
|
#' @param delta_hat_j Item threshold parameter estimates for item j
|
|
#' @param res Response of person i to item j
|
|
#' @param beta Estimated latent mean difference between groups, can be ignored
|
|
#' @return A single scalar equal to the residual for person i on item j
|
|
#' @import vcrpart
|
|
#' @export
|
|
|
|
res_ij <- function(thetahat_i,delta_hat_j,res,beta=0){
|
|
var=0
|
|
denomin=1
|
|
for (i in 1:length(delta_hat_j)) {
|
|
|
|
denomin=denomin+exp(i*(thetahat_i+beta)-sum(delta_hat_j[1:i]))
|
|
}
|
|
posterior=c(1)
|
|
for (i in 1:length(delta_hat_j)) {
|
|
posterior=c(posterior,exp(i*(thetahat_i+beta)-sum(delta_hat_j[1:i])))
|
|
}
|
|
|
|
posterior=posterior/denomin
|
|
|
|
for(i in 0:length(delta_hat_j)){
|
|
|
|
var=var+((i-sum(posterior*0:length(delta_hat_j)))**2)*posterior[i+1]
|
|
}
|
|
return((res-sum(posterior*0:length(delta_hat_j)))/sqrt(var))
|
|
|
|
}
|