From ffeb30082dd6015a93cec66efd6bfa422641bf11 Mon Sep 17 00:00:00 2001 From: emse-p4a-gwu Date: Sun, 19 Feb 2023 06:39:55 -0500 Subject: [PATCH] add comment to predict --- R/predict.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/predict.R b/R/predict.R index c62f646..92334a0 100644 --- a/R/predict.R +++ b/R/predict.R @@ -127,7 +127,7 @@ predict.logitr <- function( formatNewData <- function(object, newdata, obsID) { inputs <- object$inputs newdata <- as.data.frame(newdata) # tibbles break things - newdata <- adjustFactorLevels(object, newdata) # if missing factor levels + newdata <- checkFactorLevels(object, newdata) recoded <- recodeData(newdata, inputs$pars, inputs$randPars) X <- recoded$X predictParCheck(object, X) # Check if model pars match those from newdata @@ -145,7 +145,11 @@ formatNewData <- function(object, newdata, obsID) { return(list(X = X, scalePar = scalePar, obsID = obsID)) } -adjustFactorLevels <- function(object, newdata) { +# If some factor levels present in the data used to estimate the model +# are missing, then they need to be added back into the newdata so that +# the coefficients are correctly interpreted. This function adds back +# missing factor levels +checkFactorLevels <- function(object, newdata) { levels_orig <- object$data$factorLevels factorLevels <- getFactorLevels(newdata, object$inputs$pars) if (length(factorLevels) > 0) {