Codebook component for scales

codebook_component_scale(scale, scale_name, items, reliabilities,
  indent = "##")

Arguments

scale

a scale with attributes set

scale_name

the variable name of this scale

items

a data.frame with the items constituting the scale

reliabilities

a list with one or several results from calls to psych package functions for computing reliability

indent

add # to this to make the headings in the components lower-level. defaults to beginning at h2

Examples

# will generate figures in a temporary directory old_base_dir <- knitr::opts_knit$get("base.dir") knitr::opts_knit$set(base.dir = tempdir()) on.exit(knitr::opts_knit$set(base.dir = old_base_dir)) data("bfi") bfi <- bfi[,c("BFIK_open", paste0("BFIK_open_", 1:4))] codebook_component_scale(bfi[,1], "BFIK_open", bfi[,-1], reliabilities = list(BFIK_open = psych::alpha(bfi[,-1])))
#> #> #> #> #### Scale: BFIK_open {#BFIK_open .tabset} #> <a name="BFIK_open_2"></a><a name="BFIK_open_1"></a><a name="BFIK_open_4"></a><a name="BFIK_open_3"></a> #> #> ##### Overview {#BFIK_open_likert} #> #> __Reliability__: Cronbach's α [95% CI] = 0.53 [0.25;0.81]. #> #> __Missing__: 0. #> #> #> ```r #> old_height <- knitr::opts_chunk$get("fig.height") #> new_height <- length(scale_info$scale_item_names) #> new_height <- ifelse(new_height > 20, 20, new_height) #> new_height <- ifelse(new_height < 1, 1, new_height) #> new_height <- ifelse(is.na(new_height) | is.nan(new_height), #> old_height, new_height) #> knitr::opts_chunk$set(fig.height = new_height) #> ``` #> #> ```r #> likert_plot <- likert_from_items(items) #> if (!is.null(likert_plot)) { #> graphics::plot(likert_plot) #> } #> ``` #> #> ![plot of chunk likert](figure/BFIK_open_likert-1.png) #> #> ```r #> knitr::opts_chunk$set(fig.height = old_height) #> ``` #> #> #> ```r #> binwidth <- mean(diff(sort(unique(scale)))) #> #> wrap_at <- knitr::opts_chunk$get("fig.width") * 10 #> ``` #> #> ```r #> dist_plot <- plot_labelled(scale, scale_name, wrap_at) #> #> choices <- attributes(items[[1]])$item$choices #> breaks <- as.numeric(names(choices)) #> if (length(breaks)) { #> suppressMessages( # ignore message about overwriting x axis #> dist_plot <- dist_plot + #> ggplot2::scale_x_continuous("values", #> breaks = breaks, #> labels = stringr::str_wrap(unlist(choices), ceiling(wrap_at * 0.21))) + #> ggplot2::expand_limits(x = range(breaks))) #> #> } #> #> dist_plot #> ``` #> #> ![plot of chunk distribution](figure/BFIK_open_distribution-1.png) #> #> ##### Reliability details {#BFIK_open_reliability} #> #> ```r #> for (i in seq_along(reliabilities)) { #> rel <- reliabilities[[i]] #> cat(knitr::knit_print(rel, indent = paste0(indent, "####"))) #> } #> ``` #> #> #> #> #> #> ###### Reliability #> #> ###### 95% Confidence Interval #> #> ```r #> if (!is.null(x$total$ase)) { #> pander::pander(data.frame(lower = x$total$raw_alpha - 1.96 * x$total$ase, #> estimate = x$total$raw_alpha, #> upper = x$total$raw_alpha + 1.96 * #> x$total$ase)) #> } #> ``` #> #> #> ---------------------------- #> lower estimate upper #> -------- ---------- -------- #> 0.2473 0.5271 0.8068 #> ---------------------------- #> #> ```r #> pander::pander(x$total) #> ``` #> #> #> ------------------------------------------------------------------------------- #> raw_alpha std.alpha G6(smc) average_r S/N ase mean sd #> ----------- ----------- --------- ----------- ------- -------- ------- -------- #> 0.5271 0.513 0.5384 0.2085 1.054 0.1427 4.259 0.5631 #> ------------------------------------------------------------------------------- #> #> Table: Table continues below #> #> #> ---------- #> median_r #> ---------- #> 0.1771 #> ---------- #> #> ###### Reliability if an item is dropped: #> #> ```r #> rownames(x$alpha.drop) <- recursive_escape(rownames(x$alpha.drop)) #> pander::pander(x$alpha.drop) #> ``` #> #> #> ------------------------------------------------------------------------ #> &nbsp; raw_alpha std.alpha G6(smc) average_r S/N #> ----------------- ----------- ----------- --------- ----------- -------- #> **BFIK_open_1** 0.5787 0.5594 0.513 0.2973 1.269 #> #> **BFIK_open_2** 0.5187 0.5019 0.5306 0.2515 1.008 #> #> **BFIK_open_3** 0.2202 0.2437 0.2042 0.09701 0.3223 #> #> **BFIK_open_4** 0.4119 0.4101 0.3218 0.1881 0.6952 #> ------------------------------------------------------------------------ #> #> Table: Table continues below #> #> #> ------------------------------------------------ #> &nbsp; alpha se var.r med.r #> ----------------- ---------- ---------- -------- #> **BFIK_open_1** 0.1308 0.05045 0.1948 #> #> **BFIK_open_2** 0.1551 0.0956 0.2626 #> #> **BFIK_open_3** 0.2572 0.01955 0.1594 #> #> **BFIK_open_4** 0.1885 0.004236 0.1594 #> ------------------------------------------------ #> #> ###### Item statistics #> #> ```r #> rownames(x$item.stats) <- recursive_escape(rownames(x$item.stats)) #> pander::pander(x$item.stats) #> ``` #> #> #> --------------------------------------------------------------------------- #> &nbsp; n raw.r std.r r.cor r.drop mean sd #> ----------------- ---- -------- -------- -------- -------- ------- -------- #> **BFIK_open_1** 28 0.5063 0.5329 0.2761 0.1569 4.393 0.8317 #> #> **BFIK_open_2** 28 0.5298 0.5869 0.3017 0.2318 4.214 0.7382 #> #> **BFIK_open_3** 28 0.8041 0.7686 0.7253 0.538 4.214 0.9567 #> #> **BFIK_open_4** 28 0.701 0.6614 0.5679 0.3612 4.214 0.9567 #> --------------------------------------------------------------------------- #> #> ###### Non missing response frequency for each item #> #> ```r #> rownames(x$response.freq) <- recursive_escape(rownames(x$response.freq)) #> pander::pander(x$response.freq) #> ``` #> #> #> ------------------------------------------------------------------------ #> &nbsp; 1 2 3 4 5 miss #> ----------------- --------- --------- --------- -------- -------- ------ #> **BFIK_open_1** 0 0.03571 0.1071 0.2857 0.5714 0 #> #> **BFIK_open_2** 0 0.03571 0.07143 0.5357 0.3571 0 #> #> **BFIK_open_3** 0 0.07143 0.1429 0.2857 0.5 0 #> #> **BFIK_open_4** 0.03571 0 0.1429 0.3571 0.4643 0 #> ------------------------------------------------------------------------ #> #> #> ##### Summary statistics {#BFIK_open_summary} #> #> ```r #> for (i in seq_along(names(items))) { #> attributes(items[[i]]) = recursive_escape(attributes(items[[i]])) #> } #> escaped_table(codebook_table(items)) #> ``` #> #> #> #> |name |label |type |type_options |data_type |value_labels |optional |item_order |missing |complete |n |mean |sd |p0 |p25 |p50 |p75 |p100 |hist | #> |:-----------|:--------------------------------------------------------------|:-------------|:------------|:---------|:-------------------------------------------------------------------------------------------------------------------------------------------|:--------|:----------|:-------|:--------|:--|:----|:----|:--|:---|:---|:---|:----|:--------| #> |BFIK_open_1 |__Ich bin vielseitig interessiert.__ |rating_button |5 |numeric |1. 1: Trifft überhaupt nicht zu,<br>2. 2,<br>3. 3,<br>4. 4,<br>5. 5: Trifft voll und ganz zu,<br>NA. Item was never rendered for this user. |0 |8 |0 |28 |28 |4.39 |0.83 |2 |4 |5 |5 |5 |▁▁▂▁▁▃▁▇ | #> |BFIK_open_2 |__Ich bin tiefsinnig, denke gerne über Sachen nach.__ |rating_button |5 |numeric |1. 1: Trifft überhaupt nicht zu,<br>2. 2,<br>3. 3,<br>4. 4,<br>5. 5: Trifft voll und ganz zu,<br>NA. Item was never rendered for this user. |0 |4 |0 |28 |28 |4.21 |0.74 |2 |4 |4 |5 |5 |▁▁▁▁▁▇▁▅ | #> |BFIK_open_3 |__Ich habe eine aktive Vorstellungskraft, bin phantasievoll.__ |rating_button |5 |numeric |1. 1: Trifft überhaupt nicht zu,<br>2. 2,<br>3. 3,<br>4. 4,<br>5. 5: Trifft voll und ganz zu,<br>NA. Item was never rendered for this user. |0 |22 |0 |28 |28 |4.21 |0.96 |2 |4 |4.5 |5 |5 |▁▁▂▁▁▅▁▇ | #> |BFIK_open_4 |__Ich schätze künstlerische und ästhetische Eindrücke.__ |rating_button |5 |numeric |1. 1: Trifft überhaupt nicht zu,<br>2. 2,<br>3. 3,<br>4. 4,<br>5. 5: Trifft voll und ganz zu,<br>NA. Item was never rendered for this user. |0 |19 |0 |28 |28 |4.21 |0.96 |1 |4 |4 |5 |5 |▁▁▁▂▁▆▁▇ |