Skip to content

Commit

Permalink
residuals.logistic now handling missing values properly
Browse files Browse the repository at this point in the history
  • Loading branch information
robjhyndman committed Dec 11, 2023
1 parent 60a4b6c commit af4d9fb
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions R/logistic.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ train_logistic <- function(.data, specials, ...) {
keep <- complete.cases(xreg) & complete.cases(y)
fit <- stats::glm.fit(xreg[keep, , drop = FALSE], y[keep, , drop = FALSE],
family = stats::binomial())
resid <- fits <- matrix(nrow = nrow(y), ncol = ncol(y))
resid[keep, ] <- as.matrix(fit$residuals)
fit$residuals <- resid
fits[keep, ] <- as.matrix(fit$fitted.values)
fit$fitted.values <- fits

# Fill in missing values
tmp <- matrix(nrow = nrow(y), ncol = ncol(y))
fit$y <- y
tmp[keep, ] <- as.matrix(fit$residuals)
fit$residuals <- tmp
tmp[keep, ] <- as.matrix(fit$fitted.values)
fit$fitted.values <- tmp
tmp[keep, ] <- as.matrix(fit$effects)
fit$effects <- tmp
tmp[keep, ] <- as.matrix(fit$linear.predictors)
fit$linear.predictors <- tmp
tmp[keep,] <- as.matrix(fit$weights)
fit$weights <- tmp
tmp[keep,] <- as.matrix(fit$prior.weights)
fit$prior.weights <- tmp

if (is_empty(fit$coefficients)) {
fit$coefficients <- matrix(nrow = 0, ncol = NCOL(y))
}
Expand Down

0 comments on commit af4d9fb

Please sign in to comment.