Run a weighted logistic-regression analysis
Source:R/investigation.R
morie_run_weighted_logistic_analysis.RdMirrors 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.
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"
#>