Skip to content

Commit

Permalink
add comment to predict
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelvy committed Feb 19, 2023
1 parent 0592749 commit ffeb300
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit ffeb300

Please sign in to comment.