View source: R/assign_mobility.R
assign_mobility | R Documentation |
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).
assign_mobility( .sch_exp, .n_sch, .wt_vec, .wt_nonmob = FALSE, .id_nonmob = FALSE, ... )
.sch_exp |
A matrix or dataframe. The school-level information created
by the |
.n_sch |
Numeric scalar. Gives the total number of schools in the
dataset. The variance-covariance matrix for predictor z will have dimensions
|
.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_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 |
.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 |
... |
Other parameters passed to |
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.
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.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.