楼主: ReneeBK
1358 1

[Survey Sampling Questions]crosstables for survey data (weighted and unweighted) [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4900份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49655 个
通用积分
55.9937
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2014-4-30 00:12:21 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

I have survey data that I am working on. I need to make some tables and regression analyses on the data. After attaching the data, this is the code I use for tables for four variables:

ftable(var1, var2, var3, var4)

And this is the regression code that I use for the data:

logit.1 <- glm(var4 ~ var3 + var2 + var1, family = binomial(link = "logit")) summary(logit.1)

So far so good for the unweighted analyses. But how can I do the same analyses for the weighted data? Here is some additional info: There are four variables in the dataset that reflect the sampling structure. These are

strat: stratum (urban or (sub-county) rural).

clust: batch of interviews that were part of the same random walk

vill_neigh_code: village or neighbourhood code

sweight: weights


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:crosstable questions weighted question Sampling additional family survey tables

沙发
ReneeBK 发表于 2014-4-30 00:13:01
library(survey)

data(api)

# example data set
head( apiclus2 )

# instead of var1 - var4, use these four variables:
ftable( apiclus2[ , c( 'sch.wide' , 'comp.imp' , 'both' , 'awards' ) ] )

# move it over to x for faster typing
x <- apiclus2


# also give x a column of all ones
x$one <- 1

# run the glm() function specified.
logit.1 <-
    glm(
        comp.imp ~ target + cnum + growth ,
        data = x ,
        family = binomial( link = 'logit' )
    )

summary( logit.1 )

# now create the survey object you've described
dclus <-
    svydesign(
        id = ~dnum + snum , # cluster variable(s)
        strata = ~stype ,   # stratum variable
        weights = ~pw ,     # weight variable
        data = x ,
        nest = TRUE
    )

# weighted counts
svyby(
    ~one ,
    ~ sch.wide + comp.imp + both + awards ,
    dclus ,
    svytotal
)


# weighted counts formatted differently
ftable(
    svyby(
        ~one ,
        ~ sch.wide + comp.imp + both + awards ,
        dclus ,
        svytotal ,
        keep.var = FALSE
    )
)


# run the svyglm() function specified.
logit.2 <-
    svyglm(
        comp.imp ~ target + cnum + growth ,
        design = dclus ,
        family = binomial( link = 'logit' )
    )

summary( logit.2 )

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-29 03:21