Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: How to calculate proportion using survey package?

Tags:

r

survey

This is just a very simple question but I just cant find the right function to use from the web and books.

this is an example I got from one of the post here.

df <- data.frame(sex = c('F', 'M', 'F', 'M', 'M', 'M', 'F', 'F'),
             married = c(1,1,1,1,0,0,1,1),
             pens = c(0, 1, 1, 1, 1, 1, 0, 0),
             weight = c(1.12, 0.55, 1.1, 0.6, 0.23, 0.23, 0.66, 0.67))

d.s <- svydesign(ids=~1, data=df, weights=~weight)

I want to calculate the percentage variables such as married and calculate the standard error too?

also I want to do crosstab of married and pens and get the standard error of the resulting proportion?

how do i do that?

i tried svymean but it would treat the numeric values as integers instead of factors.

like image 535
dixi Avatar asked Feb 05 '23 10:02

dixi


1 Answers

use svytable

summary(d.s)
svytable(~married+pens, d.s)
svytable(married~pens, d.s)
svytable(married~., d.s) #with all variable
like image 102
s.brunel Avatar answered Feb 20 '23 14:02

s.brunel