data(faux.mesa.high)
fmh.ego <- as.egor(faux.mesa.high)
# Create a tiny weighted sample:
(s3 <- sample(fmh.ego, 3, replace=TRUE, prob=1:nrow(fmh.ego$ego)))
# Resampling with prob=weights(egor) creates a self-weighted
# sample:
(sample(s3, 3, replace=TRUE, prob=weights(s3)))
# Create a large weighted sample, oversampling 12th-graders:
p <- ifelse(as_tibble(fmh.ego$ego)$Grade==12, 2, 1)
s2000 <- sample(fmh.ego, 2000, replace=TRUE, prob=p)
# Summary function adjusts for weights:
(summ.net <- summary(faux.mesa.high ~ edges + nodematch("Grade") +
nodefactor("Race") + gwesp(0,fix=TRUE)))
(summ.ego <- summary(s2000 ~ edges + nodematch("Grade") +
nodefactor("Race") + gwesp(0,fix=TRUE),
scaleto=network.size(faux.mesa.high)))
# \dontshow{
stopifnot(isTRUE(all.equal(
as.vector(summ.net),
as.vector(summ.ego),
tolerance=.05,
check.attributes=FALSE
)))
# }
Run the code above in your browser using DataLab