简体   繁体   中英

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. Here's an example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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