Skip to content

Commit ffeb300

Browse files
committed
add comment to predict
1 parent 0592749 commit ffeb300

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

R/predict.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ predict.logitr <- function(
127127
formatNewData <- function(object, newdata, obsID) {
128128
inputs <- object$inputs
129129
newdata <- as.data.frame(newdata) # tibbles break things
130-
newdata <- adjustFactorLevels(object, newdata) # if missing factor levels
130+
newdata <- checkFactorLevels(object, newdata)
131131
recoded <- recodeData(newdata, inputs$pars, inputs$randPars)
132132
X <- recoded$X
133133
predictParCheck(object, X) # Check if model pars match those from newdata
@@ -145,7 +145,11 @@ formatNewData <- function(object, newdata, obsID) {
145145
return(list(X = X, scalePar = scalePar, obsID = obsID))
146146
}
147147

148-
adjustFactorLevels <- function(object, newdata) {
148+
# If some factor levels present in the data used to estimate the model
149+
# are missing, then they need to be added back into the newdata so that
150+
# the coefficients are correctly interpreted. This function adds back
151+
# missing factor levels
152+
checkFactorLevels <- function(object, newdata) {
149153
levels_orig <- object$data$factorLevels
150154
factorLevels <- getFactorLevels(newdata, object$inputs$pars)
151155
if (length(factorLevels) > 0) {

0 commit comments

Comments
 (0)