lsa_weights: lsa_weights() computes normalized and effective sample size...

View source: R/lsa_weights.R

lsa_weightsR Documentation

lsa_weights() computes normalized and effective sample size weights for pseudo maximum likelihood mixed models, with large scale assessment data

Description

lsa_weights() computes normalized and effective sample size weights for pseudo maximum likelihood mixed models, with large scale assessment data

Usage

lsa_weights(data, id_i, id_j, id_k, wt, wi, wj)

Arguments

data

data frame object which contains the rest of the arguments

id_i

a numeric vector of a single variable

id_j

a numeric vector of a single variable

id_k

a numeric vector of a single variable

wt

observations final weight

wi

observations weigth within the primary sampling unit (i.e. students eight within the school)

wj

cluster weights (i.e. school weights)

Details

a collection of dplyr::mutate sequences to create normalized and effective sample weights (see Rabe-Hesketh & Skrondal, 2006; Snijder & Bosker, 2012)

Value

the original data frame with the new weights at the end, where 'wa1' and 'wa2' are level 1 and level 2 normalized weights; 'wb1' and 'wb2' are level 1 and level 2 effectives sample weights.

Examples

library(dplyr)
data_frame_with_weights <- erce::erce_2019_qa6 %>%
                           erce::remove_labels() %>%
                           mutate(id_k = as.numeric(as.factor(paste0(IDCNTRY)))) %>%
                           mutate(id_s = as.numeric(as.factor(paste0(IDCNTRY, "_", STRATA)))) %>%
                           mutate(id_j = as.numeric(as.factor(paste0(IDCNTRY, "_", IDSCHOOL)))) %>%
                           mutate(id_i = seq(1:nrow(.))) %>%
                           erce::lsa_weights(.,
                           id_i = 'id_i',
                           id_j = 'id_j',
                           id_k = 'id_k',
                           wt = 'WT',
                           wi = 'WI',
                           wj = 'WJ' )

dacarras/erce documentation built on Oct. 2, 2023, 1:54 p.m.