simulate_mobility: simulate_mobility

View source: R/simulate_mobility.R

simulate_mobilityR Documentation

simulate_mobility

Description

simulate_mobility

Usage

simulate_mobility(
  .draws,
  .max_dist = 1,
  .p_success = 0.5,
  .mob_option = c("center", "np"),
  .pct_mobile = 0.2,
  .pop_size = 250000L,
  .output_details = FALSE
)

Arguments

.draws

Numeric scalar. The number of draws from the distribution, likely the number of persons in the data.

.max_dist

Numeric scalar. The general number of schools away from a student's home school that they should be allowed to move. Defaults to 1.

.p_success

Numeric scalar between 0 and 1. The probability of a success. The way this is coded, success translates to mobility, so lower probabilities result in lower mobility rates. In addition, higher numbers of successes are used to assign mobile students to schools that are farther away from home school. Defaults to 0.5.

.mob_option

A string. Indicates the mobility simulation option. The choices are c("center", "np"). The first choice, "center", indicates that a large, population distribution will be generated and median centered, students will be drawn from it, and afterward, some proportion of students should be determined to be non-mobile. The second choice, "np", indicates that students' mobility will be drawn directly from a binomial distribution with known properties (namely that the expected value of success is n * p). Those with higher successes will be sent to schools farther away. To determine if schools are above or below the current home school, draws will be randomly and uniformly multiplied by -1 or 1.

.pct_mobile

A numeric scalar between 0 and 1. Gives the proportion of mobile students to be saved in the "center" option of .mob_option.

.pop_size

A large numeric scalar. Gives the size of the population distribution to be constructed for .mob_option = "center". Defaults to 250000L.

.output_details

Logical. Indicates whether the sampling information (including the number of draws and trials, the probability of success, etc.) should be included in the output. If FALSE, only the mobility assignment vector will be returned. Defaults to FALSE.

Value

This function returns a list (or vector) that varies depending on the option selected in .mob_option and whether the simulation details should be output. If details are requested, the list outputs the mobility pattern vectors with length equal to .draws. The numbers given are the number of schools away from the current school to which a mobile child is assigned. For example, if the output vector looks like c(0, 0, -2), then the first two children are not mobile, while the third moves two schools away below their current school in the school residual matrix.

Examples

## Not run: 

simulate_mobility(50)


## End(Not run)

tessaleejohnson/corclus documentation built on Oct. 11, 2022, 3:46 a.m.