Open hadley opened 9 years ago
We order the levels of QSB so communities are sorted by proportion of attached people in the plots. To compute the proportion we combine data from three different years, that is why we divide by 3. Will be the same that expand the sample from each year to the total population and average the three of them. Along the paper in the plots which the information of each year is not combine we use WEIGHT but if te plot combine the information of the three years we use WEIGHT/3.
I wish this code is no so confusing now:
wt <- soul %>% filter(!is.na(WEIGHT)) %>% transmute(wt = WEIGHT/3)
des.wt <- svydesign(ids = ~1, strata = ~QSB, weights = ~as.numeric(wt$wt), data = subset(soul, !is.na(WEIGHT)) ) att.pr <- svyby(~CCEGRP2, ~QSB, des.wt, svymean, keep.var = TRUE, na.rm = T)
soul <- soul%>% left_join(att.pr[, 1:2], by = "QSB") %>% mutate(QSB = reorder(QSB, CCEGRP2Attached))
soul$CCEGRP2Attached <- NULL
I think this is
which begs the question, why 3?
The whole "Compute attachment proportion for ordering QSB levels" block is a bit confusing - I'm not sure what you're trying to achieve here