如何在R中运行带有聚类标准误差和测量权重的固定效应logit模型?

问题描述 投票:0回答:1

我正在使用Afrobarometer调查数据,使用10个国家的2轮数据。我的DV是二进制0-1变量。我需要使用逻辑回归,固定效应,聚类标准错误(在国家/地区)和加权调查数据。权重的变量已存在于数据框中。

我一直在寻找以下软件包的帮助文件:clogit,glm,pglm,glm2,zelig,bife等。典型的错误包括:不能添加重量,不能做固定效果,不能做任何一种等等。


#Glm 

t3c1.fixed <- glm(formula = ethnic ~ elec_prox + 
elec_comp + round + country, data=afb, 
weights = afb$survey_weight, 
index c("country", "round"), 
family=binomial(link='logit'))

#clogit 

t3c1.fixed2 <- clogit(formula = ethnic ~ elec_prox + 
elec_comp + round + country, data=afb, 
weights = afb$survey_weight, 
method=c("within"))


#bife attempt 

library(bife)
t3c1.fixed3 <- bife(ethnic ~ elec_prox + elec_comp + round + 
country, model = logit,data=afb, 
weights = afb$survey_weight, 
bias_corr = "ana")

我要么收到错误消息,要么代码不包含我需要包含的条件之一,所以我不能使用它们。在Stata看来,这个过程非常简单,但在R中似乎相当乏味。任何帮助,将不胜感激!

r logistic-regression weighted
1个回答
0
投票

我会查看survey包,它提供了你要求的一切。第一步是创建调查对象,指定调查权重,然后您将参加比赛。

library(survey)
my_survey <- svydesign(ids= ~1, strata = ~country, wts = ~wts, data = your_data)

# Then you can use the survey glm to do what you want via

svy_fit <- svy_glm(ethnic ~ elec_prox + 
elec_comp + round + country, data = my_survey, family = binomial())

或者至少我会沿着这条路走下去,因为你正在使用调查数据。

© www.soinside.com 2019 - 2024. All rights reserved.