scale_scores: scale_scores: Automated Scale Score Calculations

Description Usage Arguments Value Examples

View source: R/scale_scores.R

Description

Uses regular expressions and tidyeval to calculate the composite scores for multi-item survey scales. Uses regular expressions to identify scales and items. Calculates the mean of the items given that respondents completed the requisite number of items.

Usage

1
2
3
scale_scores(data, ..., completed_thresh = 0.75, scales_only = FALSE,
  scale_regex = "^[A-Za-z[:punct:]]*",
  item_regex = "[0-9]+$|[0-9]+r$|[0-9]+_r")

Arguments

data

A data frame that has been renamed in a way that the column names contain information about the scale and the item number.

...

Variables that share the naming convention of a subscale but should be dropped from scale calculations. These may include attention check items or raw scores for reverse coded items.

completed_thresh

The proportion of scale items that must be completed to calculate scale scores. Defaults to .75

scales_only

A logical value indicating whether only the scales should be returned. Defaults to FALSE where scales are bound to the original data frame as new columns.

scale_regex

A regular expression that is associated with the scale naming conventions. Defaults to the first capitalized or uncapitalized alphabetic characterers or punctuation.

item_regex

A regular expression that is associated with the item naming conventions. Defaults to the last numeric values, r, or _r.

Value

Data frame containing scale scores.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Example utlizes the bfi data that loads with the psych package
library(tidyverse)
bfi<-psych::bfi

# Several of the items need to be reverse coded.
# I do this by creating new items but retain the old columns in the complete data frame.
personality<-bfi%>%
              mutate_at(vars(A1, E1, E2, O2, O5, C4, C5),
                        .funs = list(r = function(x){7-x}))

cleaned<-scale_scores(data = personality, A1, E1, E2, O2, O5, C4, C5)

jimmyrigby94/regcleaner documentation built on March 26, 2020, 8:16 a.m.