Hi @mara, sorry about that oversight. Below is the output as a reprex.
library(tidyverse)
library(geepack)
# Create fake data
set.seed(1)
foo =
tibble(group = rep(1:2, each = 50),
cluster_id = sample(3, size = 100, replace = T),
outcome = rbinom(100, 1, 0.5),
treatment = rbinom(100, 1, 0.5),
weights = runif(100)) %>%
arrange(group, cluster_id)
# Example 1: when I explicitly write the formula, everything works
foo %>%
group_by(group) %>%
group_map(
~ geeglm(formula = outcome ~ treatment,
data = .x,
id = cluster_id,
family = "binomial",
weights = .x[["weights"]]))
#> Warning in eval(family$initialize): non-integer #successes in a binomial glm!
#> Warning in eval(family$initialize): non-integer #successes in a binomial glm!
#> [[1]]
#>
#> Call:
#> geeglm(formula = outcome ~ treatment, family = "binomial", data = .x,
#> weights = .x[["weights"]], id = cluster_id)
#>
#> Coefficients:
#> (Intercept) treatment
#> 0.1586733 0.7470728
#>
#> Degrees of Freedom: 50 Total (i.e. Null); 48 Residual
#>
#> Scale Link: identity
#> Estimated Scale Parameters: [1] 1
#>
#> Correlation: Structure = independence
#> Number of clusters: 3 Maximum cluster size: 19
#>
#>
#> [[2]]
#>
#> Call:
#> geeglm(formula = outcome ~ treatment, family = "binomial", data = .x,
#> weights = .x[["weights"]], id = cluster_id)
#>
#> Coefficients:
#> (Intercept) treatment
#> 0.5988678 -0.3821662
#>
#> Degrees of Freedom: 50 Total (i.e. Null); 48 Residual
#>
#> Scale Link: identity
#> Estimated Scale Parameters: [1] 1
#>
#> Correlation: Structure = independence
#> Number of clusters: 3 Maximum cluster size: 18
# Example 2: but the code throws an error when I try to input a pre-created formula
geeglm_formula = as.formula("outcome ~ treatment")
foo %>%
group_by(group) %>%
group_map(
~ geeglm(formula = geeglm_formula,
data = .x,
id = cluster_id,
family = "binomial",
weights = .x[["weights"]]))
#> Error in eval(extras, data, env): object '.x' not found
# Example 3: but when I drop the weights argument, it works, even
# with the pre-calculated formula
foo %>%
group_by(group) %>%
group_map(
~ geeglm(formula = geeglm_formula,
data = .x,
id = cluster_id,
family = "binomial"))
#> [[1]]
#>
#> Call:
#> geeglm(formula = geeglm_formula, family = "binomial", data = .x,
#> id = cluster_id)
#>
#> Coefficients:
#> (Intercept) treatment
#> -0.1823216 1.0577903
#>
#> Degrees of Freedom: 50 Total (i.e. Null); 48 Residual
#>
#> Scale Link: identity
#> Estimated Scale Parameters: [1] 1
#>
#> Correlation: Structure = independence
#> Number of clusters: 3 Maximum cluster size: 19
#>
#>
#> [[2]]
#>
#> Call:
#> geeglm(formula = geeglm_formula, family = "binomial", data = .x,
#> id = cluster_id)
#>
#> Coefficients:
#> (Intercept) treatment
#> 0.325422400 -0.006968669
#>
#> Degrees of Freedom: 50 Total (i.e. Null); 48 Residual
#>
#> Scale Link: identity
#> Estimated Scale Parameters: [1] 1
#>
#> Correlation: Structure = independence
#> Number of clusters: 3 Maximum cluster size: 18
Created on 2021-05-10 by the reprex package (v2.0.0)