## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 4.5) has_cub <- requireNamespace("CUB", quietly = TRUE) knitr::opts_chunk$set(eval = has_cub) ## ----eval = !has_cub, echo = FALSE, results = "asis"-------------------------- # cat("**This vignette needs the 'CUB' package (for the `univer` data), which is not installed: code is shown but not run.**") ## ----------------------------------------------------------------------------- library(DDAWASS) ## ----------------------------------------------------------------------------- data(univer, package = "CUB") str(univer) ## ----------------------------------------------------------------------------- univer$Faculty <- factor(sprintf("F%02d", univer$faculty)) univer$Gender <- factor(univer$gender, levels = 0:1, labels = c("M", "W")) univer$User <- factor(univer$freqserv, levels = 0:1, labels = c("occasional", "regular")) items <- c("informat", "willingn", "officeho", "compete", "global") ## ----------------------------------------------------------------------------- by_faculty <- data2MatD(univer, unit = "Faculty", vars = items, support = 1:7) by_faculty ## ----------------------------------------------------------------------------- M <- data2MatD(univer, unit = c("Faculty", "Gender"), vars = items, support = 1:7, min.n = 10) dim(M@M) get.MatD.stats(M, "n")$mat[1:6, "global"] # group sizes ## ----------------------------------------------------------------------------- d <- get.cell.MatD(M, "F02_W", "global") d compQ(d, c(0.25, 0.5, 0.75)) # quartiles compP(d, 5) # proportion of scores <= 5 ## ----fig.height = 5----------------------------------------------------------- plot(M[c("F02_M", "F02_W", "F06_M", "F06_W"), ]) ## ----------------------------------------------------------------------------- round(get.MatD.stats(M, "mean")$mat[1:6, ], 2) round(get.MatD.stats(M, "std")$mat[1:6, ], 2) ## ----------------------------------------------------------------------------- tab <- as.data.frame(table(unit = univer$Faculty, value = univer$global)) tab$variable <- "global" head(tab) G <- long2MatD(tab, unit = "unit", variable = "variable", value = "value", freq = "Freq") G[1:3, ] ## ----------------------------------------------------------------------------- distributionD(x = 1:5, p = c(0.1, 0.1, 0.2, 0.3, 0.3)) distributionD(x = 1:5, counts = c(2, 2, 4, 6, 6)) distributionD(c(4, 5, 5, 3, 5, 4, 2)) ## ----------------------------------------------------------------------------- head(MatD2long(M))