简体   繁体   English

如何使用样本权重和分类数据进行可视化?

[英]How to use sample weights with categorical data for visualization?

If one has a data set that looks as follows: 如果一个人的数据集如下所示:

data <- data.frame()
data$gender <- c(F,F,F,M,F)
data$province <- c(G,N,K,L,K)
data$volume <- c(500,750,1250,NA,300)
data$weight <- c(1.36,0.67,5.22,1.66,1.14)

How do I apply these weights to the data set? 如何将这些权重应用于数据集? Is it enough to just multiply the sample weights with the numerical variables or do the categorical variables also have to be weighted? 仅将样本权重与数字变量相乘就足够了吗,还是必须对分类变量进行加权?

The questionr and survey packages handle weighting. questionrsurvey包处理权重。 Here's an example: 这是一个例子:

library("questionr")
table <- wtd.table(data$gender, weights = data$weight)
barplot(as.matrix(table))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM