R anesrake 包在汇总统计中产生 NA table
R anesrake package producing NA in summary statistics table
r anesrake
package is listing na 在其摘要统计中 table 而不是提供百分比。下面粘贴了一个可重现的示例。我不知道是什么原因造成的。
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)
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)
r anesrake
package is listing na 在其摘要统计中 table 而不是提供百分比。下面粘贴了一个可重现的示例。我不知道是什么原因造成的。
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)
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)