View source: R/mutual_expected.R
mutual_expected | R Documentation |
When sample sizes are small, one group has a small proportion, or when there are many units, segregation indices are typically upwardly biased, even when true segregation is zero. This function simulates tables with zero segregation, given the marginals of the dataset, and calculates segregation. If the expected values are large, the interpretation of index scores might have to be adjusted.
mutual_expected(
data,
group,
unit,
weight = NULL,
within = NULL,
fixed_margins = TRUE,
n_bootstrap = 100,
base = exp(1)
)
data |
A data frame. |
group |
A categorical variable or a vector of variables
contained in |
unit |
A categorical variable or a vector of variables
contained in |
weight |
Numeric. (Default |
within |
Apply algorithm within each group defined by this variable,
and report the weighted average. (Default |
fixed_margins |
Should the margins be fixed or simulated? (Default |
n_bootstrap |
Number of bootstrap iterations. (Default |
base |
Base of the logarithm that is used in the calculation. Defaults to the natural logarithm. |
A data.table with two rows, corresponding to the expected values of segregation when true segregation is zero.
## Not run:
# the schools00 dataset has a large sample size, so expected segregation is close to zero
mutual_expected(schools00, "race", "school", weight = "n")
# but we can build a smaller table, with 100 students distributed across
# 10 schools, where one racial group has 10% of the students
small <- data.frame(
school = c(1:10, 1:10),
race = c(rep("r1", 10), rep("r2", 10)),
n = c(rep(1, 10), rep(9, 10))
)
mutual_expected(small, "race", "school", weight = "n")
# with an increase in sample size (n=1000), the values improve
small$n <- small$n * 10
mutual_expected(small, "race", "school", weight = "n")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.