Skip to content
Open
Changes from 1 commit
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
18 changes: 10 additions & 8 deletions R/caseduplicate.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
# (Miettinen/Schouten approach to directly estimating relative risks)
estimate_duplicate <- function(formula, data, ...) {
yvar <- as.character(all.vars(formula)[1])
data <- data %>%
dplyr::mutate(.clusterid = dplyr::row_number())
data <- dplyr::bind_rows(data,
data %>%
dplyr::rename(outc = dplyr::one_of(!!yvar)) %>%
dplyr::filter(.data$outc == 1) %>%
dplyr::mutate(outc = 0) %>%
dplyr::rename(!!yvar := "outc"))

data <- data |>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see earlier comment about base R pipe

dplyr::mutate(.clusterid = dplyr::row_number()) |>
dplyr::rename(outc = dplyr::one_of(!!yvar)) |>
tidyr::uncount(outc + 1) |>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The see the elegance in this approach! However, in the spirit of my comment in #10, it would be nice not to rely on tidyverse functions down the road. Let us focus on testing and bug fixes for now.

dplyr::group_by(.clusterid) |>
dplyr::mutate(outc = floor(outc / dplyr::row_number())) |>
dplyr::ungroup() |>
dplyr::rename(!!yvar := "outc")

fit <- eval(substitute(stats::glm(formula = formula,
family = binomial(link = "logit"),
data = data)))
Expand Down