# NOT RUN {
(within <- mutual_within(schools00, "race", "school", within = "state",
weight = "n", wide = TRUE))
# the M for state "A" is .409
# manual calculation
schools_A <- schools00[schools00$state=="A",]
mutual_total(schools_A, "race", "school", weight = "n") # M => .409
# to recover the within M and H from the output, multiply
# p * M and p * ent_ratio * H, respectively
sum(within$p * within$M) # => .326
sum(within$p * within$ent_ratio * within$H) # => .321
# compare with:
mutual_total(schools00, "race", "school", within = "state", weight = "n")
# }
Run the code above in your browser using DataLab