1

anesrake包在其汇总统计表中列出na而不是提供百分比下面粘贴了一个可重现的示例。我无法弄清楚是什么原因造成的。

data<-NULL
library(anesrake)
#Dummy data generation
data$Q35Gender<-c(1,1,1,2,2,2,2,2,2,2,2,2)
data$ID<-c(1,2,3,4,5,6,7,8,9,10,11,12)
data<-as.data.frame(data)

#Set weight targets
gentarg<-c(0.5094,0.4906)
names(gentarg)<-c("Male","Female")
targets<-list(gentarg)

#Names
names(targets)<-c("Q35Gender")

#Calculate weights
outsave <- anesrake(targets, data, caseid=data$ID,verbose=FALSE,force1=TRUE,type="nolim",cap = 4)

#Summary to check
summary(outsave)
4

1 回答 1

1

Anesrake 似乎要求变量是因子或逻辑变量,因此我将 Q35Gender 设置为因子。

data<-NULL
library(anesrake)
#Dummy data generation
data$Q35Gender<-c(1,1,1,2,2,2,2,2,2,2,2,2)
data$ID<-c(1,2,3,4,5,6,7,8,9,10,11,12)
data<-as.data.frame(data)

#Set as factor 

data$Q35Gender<-as.factor(data$Q35Gender)
levels(data$Q35Gender)<-c("Male","Female")

#Set weight targets
gentarg<-c(0.7,0.3)
names(gentarg)<-c("Male","Female")
targets<-list(gentarg)

#Names
names(targets)<-c("Q35Gender")

#Calculate weights

outsave <- anesrake(targets, data, caseid=data$ID,verbose=FALSE,force1=TRUE,type="nolim",cap = 4)
#Summary - check that it shows the % distribution for unweighted and weighted (not NA)
summary(outsave)
于 2020-04-10T12:03:47.323 回答