Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jun 23, 2024
1 parent 94aa04d commit 4d3fc45
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions R/common_language.R
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ wmw_odds <- function(x, y = NULL, data = NULL,
y <- data[data$g == "y", "r"]

.foo <- function(p) {
diff <- stats::quantile(x, probs = c(p, 1 - p)) - stats::quantile(y, probs = c(1 - p, p))
min(abs(diff))
difference <- stats::quantile(x, probs = c(p, 1 - p)) - stats::quantile(y, probs = c(1 - p, p))
min(abs(difference))
}

stats::optim(
Expand Down
44 changes: 22 additions & 22 deletions R/convert_between_odds_to_probs.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ probs_to_odds.data.frame <- function(probs, log = FALSE, select = NULL, exclude
#' @keywords internal
.odds_to_probs_df <- function(odds = NULL, probs = NULL, log = FALSE, select = NULL, exclude = NULL, ...) {
# If vector
if (!is.null(odds)) {
df <- odds
if (is.null(odds)) {
mydata <- probs
} else {
df <- probs
mydata <- odds
}

# check for formula notation, convert to character vector
Expand All @@ -93,55 +93,55 @@ probs_to_odds.data.frame <- function(probs, log = FALSE, select = NULL, exclude
}

# Variable order
var_order <- names(df)
var_order <- names(mydata)

# Keep subset
if (!is.null(select) && select %in% names(df)) {
if (!is.null(select) && select %in% names(mydata)) {
select <- as.vector(select)
to_keep <- as.data.frame(df[!names(df) %in% select])
df <- df[names(df) %in% select]
to_keep <- as.data.frame(mydata[!names(mydata) %in% select])
mydata <- mydata[names(mydata) %in% select]
} else {
to_keep <- NULL
}

# Remove exceptions
if (!is.null(exclude) && exclude %in% names(df)) {
if (!is.null(exclude) && exclude %in% names(mydata)) {
exclude <- as.vector(exclude)
if (is.null(to_keep)) {
to_keep <- as.data.frame(df[exclude])
to_keep <- as.data.frame(mydata[exclude])
} else {
to_keep <- cbind(to_keep, as.data.frame(df[exclude]))
to_keep <- cbind(to_keep, as.data.frame(mydata[exclude]))
}

df <- df[!names(df) %in% exclude]
mydata <- mydata[!names(mydata) %in% exclude]
}

# Remove non-numerics
is_num <- vapply(df, is.numeric, logical(1))
dfother <- df[!is_num]
dfnum <- df[is_num]
is_num <- vapply(mydata, is.numeric, logical(1))
dfother <- mydata[!is_num]
dfnum <- mydata[is_num]

# Tranform
if (!is.null(odds)) {
dfnum <- data.frame(lapply(dfnum, odds_to_probs.numeric, log = log))
} else {
if (is.null(odds)) {
dfnum <- data.frame(lapply(dfnum, probs_to_odds.numeric, log = log))
} else {
dfnum <- data.frame(lapply(dfnum, odds_to_probs.numeric, log = log))
}

# Add non-numerics
if (is.null(ncol(dfother))) {
df <- dfnum
mydata <- dfnum
} else {
df <- cbind(dfother, dfnum)
mydata <- cbind(dfother, dfnum)
}

# Add exceptions
if (!is.null(select) || !is.null(exclude) && exists("to_keep")) {
df <- cbind(df, to_keep)
mydata <- cbind(mydata, to_keep)
}

# Reorder
df <- df[var_order]
mydata <- mydata[var_order]

return(df)
mydata
}
2 changes: 1 addition & 1 deletion data-raw/df data.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ screening_test <- data.frame(
Test1 = rep(screening_test[[1]], times = screening_test$Freq),
Test2 = rep(screening_test[[2]], times = screening_test$Freq)
)
i <- sample(1600, size = 800)
i <- sample.int(1600, size = 800)
screening_test$Diagnosis[i] <- screening_test$Test1[i]
screening_test$Diagnosis[-i] <- screening_test$Test2[-i]
screening_test$Diagnosis <- factor(screening_test$Diagnosis, labels = c("Neg", "Pos"))
Expand Down

0 comments on commit 4d3fc45

Please sign in to comment.