# cNORM features a dataset on vocabulary development (ppvt)
# that includes variables like sex or migration. In order
# to weight the data, we have to specify the population shares.
# According to census, the population includes 52% boys
# (factor level 1 in the ppvt dataset) and 70% / 30% of persons
# without / with a a history of migration (= 0 / 1 in the dataset).
# First we set up the popolation margins with all shares of the
# different levels:
margins <- data.frame(variables = c("sex", "sex",
"migration", "migration"),
levels = c(1, 2, 0, 1),
share = c(.52, .48, .7, .3))
head(margins)
# Now we use the population margins to generate weights
# through raking
weights <- computeWeights(ppvt, margins)
# There are as many different weights as combinations of
# factor levels, thus only four in this specific case
unique(weights)
# To include the weights in the cNORM modelling, we have
# to pass them as weights. They are then used to set up
# weighted quantiles and as weights in the regession.
model <- cnorm(raw = ppvt$raw,
group=ppvt$group,
weights = weights)
Run the code above in your browser using DataLab