test_that('make sure that factor levels line up with original data', { skip_on_cran() skip_if_not_installed('rstanarm') set.seed(500) modelData <- rstanarm::wells modelData$assoc <- ifelse(modelData$assoc==1, 'Y', 'N') rowMiss <- sample(1:nrow(modelData), size=10, replace=F) colMiss <- sample(1:ncol(modelData), size=10, replace=T) for(i in 1:10){ modelData[rowMiss[[i]], colMiss[[i]]] <- NA } logitModel <- suppressWarnings(rstanarm::stan_glm(switch ~ dist*educ + arsenic + I(arsenic^2) + assoc, data=modelData, family=binomial, refresh=0, chains=2, iter=500)) expect_identical(levels(newValueF(logitModel$model, marg_effect='assoc', new_value='Y')$assoc), sort(unique(logitModel$model$assoc))) })