
Scale Dictionary
scaledic-package.Rd
A 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)
#> Found the following invalid values:
#>
#> 'itrf_I_1'
#> Row: 3192
#> Value: 7
#>
#> 'itrf_I_2'
#> Row: 4651
#> Value: 9
#>
#> 'itrf_I_13'
#> Row: 3699
#> Value: 4
#>
#> 'itrf_I_20'
#> Row: 2799
#> Value: 4
#>
#> 'itrf_E_4'
#> Row: 2621
#> Value: 6
#>
#> 'itrf_E_6'
#> Row: 2599
#> Value: 9
#>
#> 'itrf_E_7'
#> Row: 2599
#> Value: 9
#>
#> 'itrf_E_8'
#> Row: 2599
#> Value: 9
#>
#> 'itrf_E_9'
#> Row: 2599
#> Value: 9
#>
#> 'itrf_E_10'
#> Row: 2599
#> Value: 9
#>
#> 'itrf_E_11'
#> Row: 2599
#> Value: 9
#>
#> 'itrf_E_12'
#> Row: 2599
#> Value: 9
#>
#> 'itrf_E_13'
#> Row: 2599 4146
#> Value: 9 11
#>
#> 'itrf_E_14'
#> Row: 2599
#> Value: 9
#>
#>
#> 1: 'type' attribute missing and replaced with an estimation (2x)
#> 2: Invalid values replaced with NA
#> 3: Missing values replaced with NA
#> 4: 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.58
#> 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