mirror of
https://github.com/agdamsbo/FreesearchR.git
synced 2025-09-12 18:09:39 +02:00
handling empty formula
This commit is contained in:
parent
269658ef17
commit
f4be547ed0
1 changed files with 9 additions and 11 deletions
|
@ -35,7 +35,7 @@ regression_model <- function(data,
|
||||||
args.list = NULL,
|
args.list = NULL,
|
||||||
fun = NULL,
|
fun = NULL,
|
||||||
vars = NULL) {
|
vars = NULL) {
|
||||||
if (!is.null(formula.str)) {
|
if (!is.null(formula.str) | formula.str != "") {
|
||||||
formula.str <- glue::glue(formula.str)
|
formula.str <- glue::glue(formula.str)
|
||||||
} else {
|
} else {
|
||||||
assertthat::assert_that(outcome.str %in% names(data),
|
assertthat::assert_that(outcome.str %in% names(data),
|
||||||
|
@ -44,10 +44,10 @@ regression_model <- function(data,
|
||||||
formula.str <- glue::glue("{outcome.str}~.")
|
formula.str <- glue::glue("{outcome.str}~.")
|
||||||
|
|
||||||
if (!is.null(vars)) {
|
if (!is.null(vars)) {
|
||||||
if (outcome.str %in% vars){
|
if (outcome.str %in% vars) {
|
||||||
vars <- vars[vars %in% outcome.str]
|
vars <- vars[vars %in% outcome.str]
|
||||||
}
|
}
|
||||||
data <- data |> dplyr::select(dplyr::all_of(c(vars,outcome.str)))
|
data <- data |> dplyr::select(dplyr::all_of(c(vars, outcome.str)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,16 +57,15 @@ regression_model <- function(data,
|
||||||
|
|
||||||
# browser()
|
# browser()
|
||||||
if (auto.mode) {
|
if (auto.mode) {
|
||||||
if (is.numeric(data[[outcome.str]])){
|
if (is.numeric(data[[outcome.str]])) {
|
||||||
fun <- "stats::lm"
|
fun <- "stats::lm"
|
||||||
} else if (is.factor(data[[outcome.str]])){
|
} else if (is.factor(data[[outcome.str]])) {
|
||||||
if (length(levels(data[[outcome.str]]))==2){
|
if (length(levels(data[[outcome.str]])) == 2) {
|
||||||
fun <- "stats::glm"
|
fun <- "stats::glm"
|
||||||
args.list = list(family = binomial(link = "logit"))
|
args.list <- list(family = binomial(link = "logit"))
|
||||||
|
} else if (length(levels(data[[outcome.str]])) > 2) {
|
||||||
} else if (length(levels(data[[outcome.str]]))>2){
|
|
||||||
fun <- "MASS::polr"
|
fun <- "MASS::polr"
|
||||||
args.list = list(
|
args.list <- list(
|
||||||
Hess = TRUE,
|
Hess = TRUE,
|
||||||
method = "logistic"
|
method = "logistic"
|
||||||
)
|
)
|
||||||
|
@ -76,7 +75,6 @@ regression_model <- function(data,
|
||||||
} else {
|
} else {
|
||||||
stop("Output variable should be either numeric or factor for auto.mode")
|
stop("Output variable should be either numeric or factor for auto.mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assertthat::assert_that("character" %in% class(fun),
|
assertthat::assert_that("character" %in% class(fun),
|
||||||
|
|
Loading…
Add table
Reference in a new issue