I used WeightIt
to balance the characteristics of my population dividing into treated and non-treated as in this example:
library(cobalt)
library(WeightIt)
data("lalonde", package = "cobalt")
head(lalonde)
W.out <- weightit(treat ~ age + educ + race + married + nodegree + re74 + re75,
data = lalonde, estimand = "ATT", method = "ps")
My outcome is re78
. I would like to calculate the RISK RATIO with 95% CONFIDENCE INTERVALS.
How can I do it?
For odds ratio I know that I can use the survey
package and the svyglm
function as in this example:
library(survey)
d.w <- svydesign(~1, weights = W.out$weights, data = lalonde)
fit <- svyglm(re78 ~ treat, design = d.w)
coef(fit)
but how can I compute risk ratios with their 95% CI instead of odds ratio in my weighted dataset?
Since re78
is not integer you need to use quasipoisson
instead of poisson
if you want to avoid warnings, although the software gives the dame results.
fit <- svyglm(re78 ~ treat, design = d.w, family="quasipoisson")
coef(fit)
(Intercept) treat
8.543849 0.212226
coef(summary(fit))
Estimate Std. Error t value Pr(>|t|)
(Intercept) 8.543849 0.1146916 74.494128 4.321164e-309
treat 0.212226 0.1463640 1.449987 1.475743e-01
The risk ratio is just exp(coef(fit)[2])
and it's CI is just this pseudo code.
exp( coef(fit)[2] +/- 1.96*coef( summary(fit))[2,2] )