assign_mobility: assign_mobility

View source: R/assign_mobility.R

assign_mobilityR Documentation

assign_mobility

Description

This function uses mobility assignments simulated by simulate_mobility to identify a student's second school information. If the student is not mobile, their second school will be equal to their first school. If they are mobile, their second school ID will be determined by their first school ID plus their mobility indicator (i.e., representing a change to an adjacent, or nearly adjacent, school). For students attending the first school (i.e., ID = 1) or the last school (i.e., ID = total number of schools), their second school, if they are mobile, will be schools above (for ID = 1) or schools below (for ID = max school ID).

Usage

assign_mobility(
  .sch_exp,
  .n_sch,
  .wt_vec,
  .wt_nonmob = FALSE,
  .id_nonmob = FALSE,
  ...
)

Arguments

.sch_exp

A matrix or dataframe. The school-level information created by the gen_u_mmrem function and expanded by the expand_sch_info function.

.n_sch

Numeric scalar. Gives the total number of schools in the dataset. The variance-covariance matrix for predictor z will have dimensions .n_sch x .n_sch.

.wt_vec

A numeric vector with length equal to the maximum number of schools attended by students in the data (in this simulation, the maximum number is 2). The values in .wt_vec are used to weight the effects of different schools attended on students. For this study, all mobile students must have the same weights. If different weighting patterns are desired, the code will need to be updated.

.wt_nonmob

Logical. Indicates whether non-mobile students should receive the same weights as mobile students. Technically, it shouldn't matter if non-mobile students are given the same weights because their first and second schools are the same, so all weighting schemes should be equivalent, but it may matter for passing data to MLwiN for estimation. See runMLwiN for more information.

.id_nonmob

Logical. Indicates whether non-mobile students should receive a non-zero school ID for their second school. Technically, it shouldn't matter if non-mobile students have a non-zero school ID (i.e., if first and second schools are the same), so all ID schemes should be equivalent, but it may matter for passing data to MLwiN for estimation. See runMLwiN for more information.

...

Other parameters passed to simulate_mobility.

Details

Note: this function was designed for a simulation in which the maximum number of schools attended by each student is equal to 2. The code would need to be updated if it is desired that students could attend more than 2 schools.

Value

This function returns a dataframe with a number of columns equal to NCOL(.sch_exp) * 2 + 3. The columns from .sch_exp are repeated for the second school, and the mobility assignments from simulate_mobility along with the first and second school weights are appended as the final 3 columns.

Examples

## Not run: 

library(magrittr)

sch_inf <-
  gen_u_mmrem(
    .n_sch = 50,
    clust_cov = c(0.8, 0.2, 0.1)
  ) %>%
  expand_sch(., .n_sch = 50, n_stu = 50) %>%
  assign_mobility(., .n_sch = 50, .wt_vec = c(0.5, 0.5))


## End(Not run)

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