Skip to contents

Mirrors the Python morie.run_weighted_logistic_analysis(). Fits a binary-outcome model using survey weights via survey::svyglm() if the suggested survey package is available, otherwise falls back to base glm() with case weights.

Usage

morie_run_weighted_logistic_analysis(
  data,
  outcome,
  predictors,
  weights_col = NULL
)

Arguments

data

A data.frame containing outcome, predictors, and (optionally) a weights column.

outcome

Column name of the binary outcome.

predictors

Character vector of predictor column names.

weights_col

Optional column name of analytical weights.

Value

A list with components coefficients (named numeric vector), std_errors, p_values, n, method ("svyglm" or "glm-weighted").

Examples

set.seed(1)
df <- data.frame(
  y = rbinom(200, 1, 0.4),
  x1 = rnorm(200),
  x2 = rnorm(200),
  w = runif(200, 0.5, 1.5)
)
morie_run_weighted_logistic_analysis(df,
  outcome = "y", predictors = c("x1", "x2"), weights_col = "w"
)
#> $coefficients
#> (Intercept)          x1          x2 
#> -0.36207464 -0.07280759  0.14447336 
#> 
#> $std_errors
#> (Intercept)          x1          x2 
#>   0.1502282   0.1504163   0.1389928 
#> 
#> $p_values
#> (Intercept)          x1          x2 
#>  0.01686447  0.62889461  0.29987859 
#> 
#> $n
#> [1] 200
#> 
#> $method
#> [1] "svyglm"
#>