Added theta estimation methods
This commit is contained in:
14
R/pcm.R
14
R/pcm.R
@ -10,11 +10,15 @@
|
||||
#' @param grp string containing the name of the column where an optional group membership variable is stored in df
|
||||
#' @param dif.items vector containing the list of indexes in "items" corresponding to dif items
|
||||
#' @param type.dif vector containing DIF form for each item specified in dif.items. 1 is homogeneous DIF, 0 is heterogeneous DIF
|
||||
#' @param verbose set to TRUE to print a detailed output, FALSE otherwise
|
||||
#' @param fit string determining the optimization algorithm. Values "ucminf" or "nlminb" ar recommended
|
||||
#' @param method.theta string determining the estimation method for individual latent variable values. Either "eap", "mle" or "wle"
|
||||
#' @return A data.frame containing various model outputs
|
||||
#' @import vcrpart
|
||||
#' @import PP
|
||||
#' @export
|
||||
|
||||
pcm <- function(df=NULL,items=NULL,grp=NULL,dif.items=NULL,type.dif=NULL,verbose=T,fit="ucminf") {
|
||||
pcm <- function(df=NULL,items=NULL,grp=NULL,dif.items=NULL,type.dif=NULL,verbose=T,fit="ucminf",method.theta="eap") {
|
||||
##### Detecting errors
|
||||
|
||||
if (any(!(items %in% colnames(df)))) {
|
||||
@ -205,7 +209,13 @@ pcm <- function(df=NULL,items=NULL,grp=NULL,dif.items=NULL,type.dif=NULL,verbose
|
||||
}
|
||||
|
||||
}
|
||||
theta <- -1*ranef(mod,norm=F)+ifelse(grp==1,beta,0)
|
||||
if (method.theta=="eap") {
|
||||
theta <- c(-1*ranef(mod,norm=F)+ifelse(grp==1,beta,0))
|
||||
} else if (method.theta=="wle") {
|
||||
theta <- PP::PP_gpcm(as.matrix(df[,items]),t(restab),rep(1,length(items)))$resPP$resPP[,1]
|
||||
} else if (method.theta=="mle") {
|
||||
theta <- PP::PP_gpcm(as.matrix(df[,items]),t(restab),rep(1,length(items)),type="mle")$resPP$resPP[,1]
|
||||
}
|
||||
resid <- apply(matrix(1:nbitems,ncol=length(nbitems)),1, function(k) sapply(1:nrow(df), function(j) res_ij(theta[j],restab[k,],df[j,items[k]],beta=0)))
|
||||
colnames(resid) <- items_o
|
||||
|
||||
|
Reference in New Issue
Block a user