From f9bcebbec317e869e0e7b5d5a3012c761f0e27de Mon Sep 17 00:00:00 2001 From: corentinchoisy Date: Tue, 3 Jun 2025 15:53:56 +0200 Subject: [PATCH] added na.action setting in pcm --- R/pcm.R | 4 ++-- man/pcm.Rd | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/pcm.R b/R/pcm.R index 97b6aa8..8edc36f 100644 --- a/R/pcm.R +++ b/R/pcm.R @@ -14,6 +14,7 @@ #' @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" +#' @param na.action function for treatment of NAs to be passed to model estimation #' @return A data.frame containing various model outputs #' @import vcrpart #' @import PP @@ -270,7 +271,6 @@ pcm <- function(df=NULL,items=NULL,grp=NULL,dif.items=NULL,type.dif=NULL,weights } } - if (is.null(grpo)) { if (method.theta=="eap") { theta <- c(-1*ranef(mod,norm=F)+ ifelse(is.null(grpo),0, ifelse(grp==1,beta,0) ) ) } else if (method.theta=="wle") { @@ -278,7 +278,7 @@ pcm <- function(df=NULL,items=NULL,grp=NULL,dif.items=NULL,type.dif=NULL,weights } 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) resi(theta[j],restab[k,],df[j,items[k]],beta=0))) colnames(resid) <- items_o diff --git a/man/pcm.Rd b/man/pcm.Rd index 1aa1a0e..253b854 100644 --- a/man/pcm.Rd +++ b/man/pcm.Rd @@ -35,6 +35,8 @@ pcm( \item{fit}{string determining the optimization algorithm. Values "ucminf" or "nlminb" ar recommended} \item{method.theta}{string determining the estimation method for individual latent variable values. Either "eap", "mle" or "wle"} + +\item{na.action}{function for treatment of NAs to be passed to model estimation} } \value{ A data.frame containing various model outputs