Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions R/pred.R
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,15 @@ pred_fun_Y <- function(model, yrestrictions, outcome_type, outcome_name,
# Fit GLM for outcome variable using user-specified model and entire dataset
fitY <- stats::glm(model, family = outcome_fam, data = obs_data, y = TRUE)
}
if(anyNA(coefficients(fitY))) {
stop(
"`NA` coefficients produced in prediction model. ",
"This may be due to (multi)collinearity in `ymodel` predictor variables, ",
"or including `time_name` variable in a 'continuous_eof' model.\n",
"Variables returning `NA` coefficients:\n - ",
paste(names(coefficients(fitY)[is.na(coefficients(fitY))]), collapse = "\n - ")
)
}
fitY$rmse <- add_rmse(fitY)
fitY$stderr <- add_stderr(fitY)
fitY$vcov <- add_vcov(fitY)
Expand Down
22 changes: 22 additions & 0 deletions R/simulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,28 @@ simulate <- function(o, fitcov, fitY, fitD,
min_time, show_progress, pb, int_visit_type, ...){
set.seed(subseed)

invalid_coefs <- vapply(lapply(fitcov, coefficients), anyNA, logical(1)) |> any()

if (invalid_coefs) {

coefficients <- lapply(fitcov, coefficients)

errored_parts <- coefficients[vapply(coefficients, anyNA, logical(1))] |>
lapply(\(coefs) {names(coefs[is.na(coefs)])})


paste(names(errored_parts), errored_parts, sep = "\n - ", collapse = "\n\n")

stop(
"`NA` coefficients produced in covariate prediction model. ",
"This may be due to (multi)collinearity in `covmodels` predictor variables, ",
"or including `time_name` variable in a 'continuous_eof' model.\n",
"Variables returning `NA` coefficients:\n",
paste(names(errored_parts), errored_parts, sep = "\n - ", collapse = "\n\n")
)

}

# Mechanism of passing intervention variable and intervention is different for parallel
# and non-parallel versions
if (parallel){
Expand Down