
Scale Dictionary
scaledic-package.RdA collection of procedures to bring labels, scales, missing values etc. to a data frame.
Examples
# apply a dictionary file to a data frame
dat <- apply_dic(dat_itrf, dic_itrf)
#>
#> Cautions:
#> 1: 'type' attribute missing and replaced with an estimation (2x)
#> Found the following invalid values:
#>
#> 'itrf_I_1' is 7 at row 3192
#> 'itrf_I_2' is 9 at row 4651
#> 'itrf_I_13' is 4 at row 3699
#> 'itrf_I_20' is 4 at row 2799
#> 'itrf_E_4' is 6 at row 2621
#> 'itrf_E_6' is 9 at row 2599
#> 'itrf_E_7' is 9 at row 2599
#> 'itrf_E_8' is 9 at row 2599
#> 'itrf_E_9' is 9 at row 2599
#> 'itrf_E_10' is 9 at row 2599
#> 'itrf_E_11' is 9 at row 2599
#> 'itrf_E_12' is 9 at row 2599
#> 'itrf_E_13' is 9, 11 at rows 2599, 4146
#> 'itrf_E_14' is 9 at row 2599
#>
#> Cautions:
#> 1: Invalid values replaced with NA
#> 2: Missing values replaced with NA
#> 3: Scales scored
# check for typos (not allowed values)
dat <- check_values(dat, replace = NA)
#> No errors found.
# Single imputation (EM algorith from the Amelia package)
# based on the variables of the provided scale
dat <- impute_missing(dat, scale == "ITRF" & subscale == "Ext")
#> -- Imputation 1 --
#>
#> 1 2 3
#>
dat <- impute_missing(dat, scale == "ITRF" & subscale == "Int")
#> Warning: There are observations in the data that are completely missing.
#> These observations will remain unimputed in the final datasets.
#> -- Imputation 1 --
#>
#> 1 2 3
#>
# Show a table with all scales and scale labels included in the data frame
list_scales(dat, levels = c("scale_label", "subscale_label"))
#> scale_label subscale_label
#> 1 Integrated teacher report form Internalizing
#> 2 Integrated teacher report form Externalizing
# Example with pipeline syntax. Would be much easier to use the "describe" function
# from the psch packages instead of summarise_all here.
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
dat |>
select_items(scale == "ITRF" & subscale == "Ext") |>
rename_items(pattern = "{subscale_2}:{name}") |>
summarise_all(mean, na.rm = TRUE) |>
round(2) |>
t()
#> [,1]
#> OPP:itrf_I_20 0.55
#> APD:itrf_E_1 0.95
#> APD:itrf_E_2 0.76
#> APD:itrf_E_3 0.58
#> APD:itrf_E_4 0.57
#> APD:itrf_E_5 0.93
#> APD:itrf_E_6 0.53
#> OPP:itrf_E_7 0.35
#> OPP:itrf_E_8 0.49
#> OPP:itrf_E_9 0.83
#> OPP:itrf_E_10 0.40
#> OPP:itrf_E_11 0.77
#> OPP:itrf_E_12 0.46
#> OPP:itrf_E_13 0.47
#> APD:itrf_E_14 0.38
#> APD:itrf_E_15 0.70
#> OPP:itrf_E_16 0.35