Skip to content

Instantly share code, notes, and snippets.

@chris-prener
Last active December 12, 2017 20:39
Show Gist options
  • Save chris-prener/e8db299364b5ffbee68b960b71bd9d55 to your computer and use it in GitHub Desktop.
Save chris-prener/e8db299364b5ffbee68b960b71bd9d55 to your computer and use it in GitHub Desktop.
SOC 4930 & SOC 5050 - Week 11 - Creating Scale Variable
library(ggplot2)
library(dplyr)
# load data
autoData <- mpg
# subset to create data frame with only variables of interest for scale
autoSubset <- select(autoData, cyl, cty, hwy)
# visually inspect cronbach's alpha results
psych::alpha(autoSubset)
# re-calculate cronbach's alpha with check.keys argument
psych::alpha(autoSubset, check.keys = TRUE)
# store results of scale in object
alphaTest <- psych::alpha(autoSubset, check.keys = TRUE)
# use stored results to create new scale variable in original data frame
autoData <- mutate(autoData, scale = alphaTest$scores)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment