全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 HLM专版
1330 1
2014-04-30

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


二维码

扫码加我 拉你入群

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

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

全部回复
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 )
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群