View source: R/gen_z_composite.R
gen_z_composite | R Documentation |
This function takes a matrix of weights .sch_weight
and a matrix
of predictor values .sch_predictor
and constructs the weighted
sum as diag(.sch_weight \%*\% t(.sch_predictor)).
gen_z_composite(.dat, .sch_weight, .sch_predictor)
.sch_weight |
Numeric matrix with dimensions n x h (where n is the
number of persons and h is the maximum number of schools attended by any
person in the dataset). Rows should sum to 1 (that is, for each student,
the weights assigned to their schools attended should sum to 1). For a school
a student did not attend, the weight should be 0 (that is, if the maximum
number of schools attended was 2 and person A only attended 1 school, then
the weight for their "second school" should be 0, while the weight for
their "first school" should be 1). To simulate the data, all students were
initially assigned a mobility profile (meaning that all students were
assigned h schools to attend), and then only a certain proportion of
students were coded as mobile. For the students who were coded as mobile,
their |
.sch_predictor |
Numeric matrix or dataframe. Contains the values of
the school-level predictor, z, generated in |
This function returns a numeric vector of length equal to
NROW(.sch_weight)
(or, equivalently, NROW(.sch_predictor)
).
These values are the weighted sum of the predictors constructed for the
two schools assigned to all students. For non-mobile students, the
z_composite value should be equal to the predictor z from their first
school attended.
## Not run: sch_inf <- gen_u_mmrem( .n_sch = 5, .clust_cov = c(.8, .1) ) %>% expand_sch(., .n_sch = 5, .n_stu = 5) %>% assign_mobility(., .n_sch = 5) %>% dplyr::mutate( .data = ., z_composite = gen_z_composite( dplyr::select(., sch_wt_1, sch_wt_2), dplyr::select(., z_predictor_1, z_predictor_2) ) ) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.