Reputation: 136
How do you ensure the lower confidence interval limit is non-negative for a proportion when dealing with survey weighted data?
This is the code:
svy_design <- svydesign(ids = ~block, strata = ~strata_study, weights = ~wt, data = data, nest = TRUE, fpc = NULL)
svyby(~binary_outcome,by=~binary_exposure, design=svy_design, FUN=svymean, data=data,keep.var = TRUE, vartype = "ci")
Result as follows:
binary_exposure binary_outcome0 binary_outcome1 ci_l.binary_outcome0 ci_l.binary_outcome1 ci_u.binary_outcome0 ci_u.binary_outcome1
1 1 0.9858986 0.01410138 0.9782720 0.006474771 0.9935252 0.02172798
2 2 0.9264685 0.07353151 0.8489539 -0.003983028 1.0039830 0.15104605
The lower confidence interval for the proportion is reported as -0.003983028. How to ensure that the estimates are bounded 0 and above?
Upvotes: 2
Views: 349
Reputation: 2765
You can use svyciprop
: eg, compare
> svyby(~I(emer==0), ~stype, svyciprop, design=dclus1, method="mean",vartype="ci")
stype I(emer == 0) ci_l ci_u
E E 0.2083333 0.08601926 0.3306474
H H 0.2142857 -0.04681564 0.4753871
M M 0.0800000 -0.04023591 0.2002359
> svyby(~I(emer==0), ~stype, svyciprop, design=dclus1, method="logit",vartype="ci")
stype I(emer == 0) ci_l ci_u
E E 0.2083333 0.11139102 0.3558571
H H 0.2142857 0.05467787 0.5625459
M M 0.0800000 0.01669209 0.3081661
Upvotes: 3
Reputation: 174
svyby
uses confint
function with method='Wald'
argument to process confidence interval. Wald method can lead to negative values. You should use method='likelihood'
instead.
I haven't find a way to change the method directly from svyby
in the documentation, but you can call confint()
directly on a svyglm
object with method='likelihood'
.
Upvotes: 1