COSTDataExpo2013 / DaSilvaAlvarez

This repository contains supplementary material for the paper "Clicks and Cliques. Exploring the Soul of the Community" to enable the reader to reproduce the analysis.
1 stars 0 forks source link

Confusing code #3

Open hadley opened 9 years ago

hadley commented 9 years ago
wt     <- with(subset(soul,!is.na(WEIGHT)), WEIGHT/3)

I think this is

wt <- soul$WEIGHT[!is.na(soul$WEIGHT] / 3

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

natydasilva commented 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.

natydasilva commented 9 years ago

I wish this code is no so confusing now:

Compute attachment proportion for ordering QSB levels

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