Skip to content

Commit

Permalink
update lint
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkliming committed Aug 13, 2024
1 parent 84c794b commit a45adf8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions R/robin_glm.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Covariate adjusted glm model
#' @param formula (`formula`) A formula of analysis.
#' @param data (`data.frame`) Input data frame.
#' @param treatment (`formula` or `character(1)`) A formula of treatment assignment or assignment by stratifications,
#' @param treatment (`formula` or `character(1)`) A formula of treatment assignment or assignment by stratification,
#' or a string name of treatment assignment.
#' @param contrast (`function` or `character(1)`) A function to calculate the treatment effect, or character of
#' "difference", "risk_ratio", "odds_ratio" for default contrasts.
Expand All @@ -15,7 +15,9 @@
#' @export
#' @examples
#' robin_glm(y ~ treatment * s1, data = dummy_data, treatment = treatment ~ s1, contrast = "difference", vcov = vcovHC)
robin_glm <- function(formula, data, treatment, contrast = "difference", contrast_jac = NULL, vcov = vcovANHECOVA, family = gaussian, ...) {
robin_glm <- function(
formula, data, treatment, contrast = "difference",
contrast_jac = NULL, vcov = vcovANHECOVA, family = gaussian, ...) {
attr(formula, ".Environment") <- environment()
fit <- glm(formula, family = family, data = data)
pc <- predict_counterfactual(fit, treatment, data, unbiased = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion man/robin_glm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions tests/testthat/test-robin_glm.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ test_that("h_interaction works correctly", {
# robin_glm ----

test_that("robin_glm works correctly", {
expect_silent(robin_glm(y ~ treatment * s1, data = dummy_data, treatment = treatment ~ s1, contrast = "difference", vcov = vcovHC))
expect_silent(
robin_glm(
y ~ treatment * s1, data = dummy_data, treatment = treatment ~ s1,
contrast = "difference", vcov = vcovHC
)
)
expect_silent(robin_glm(y_b ~ treatment * s1, data = dummy_data, treatment = treatment ~ s1, contrast = "difference"))
expect_silent(robin_glm(y_b ~ treatment * s1, data = dummy_data, treatment = treatment ~ s1, contrast = "risk_ratio"))
expect_silent(robin_glm(y_b ~ treatment * s1, data = dummy_data, treatment = treatment ~ s1, contrast = "odds_ratio"))
expect_error(
robin_glm(y_b ~ treatment * s1, data = dummy_data, treatment = treatment ~ s1, contrast = "odds_ratio", vcov = vcovHC),
robin_glm(
y_b ~ treatment * s1, data = dummy_data, treatment = treatment ~ s1,
contrast = "odds_ratio", vcov = vcovHC
),
"Huber-White standard error only works for difference contrasts in models without interaction term."
)
expect_silent(robin_glm(y_b ~ treatment * s1, data = dummy_data, treatment = treatment ~ s1, contrast = h_diff))
Expand Down

0 comments on commit a45adf8

Please sign in to comment.