renamed res_ij to resi
This commit is contained in:
37
R/resi.R
Normal file
37
R/resi.R
Normal file
@ -0,0 +1,37 @@
|
||||
## File Name: resi.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
|
||||
|
||||
resi <- 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))
|
||||
|
||||
}
|
Reference in New Issue
Block a user