The R package psych was developed by William Revelle and others to facilitate the analysis of psychological and social science data more generally. It provides you with extensive tools for:
- Descriptive statistics (e.g., describe, pairs.panels)
- Reliability and item analyses (e.g., Cronbach’s alpha with alpha)
- Factor analysis (e.g., via fa)
- Principal component analysis (e.g., via principal)
- Data transformation and scoring (e.g., for psychological scales)
Whether you work in psychology, education, social research, or another field—as soon as you deal with scales, items, factor structures, or reliabilities, the psych package can save you a lot of work.
Installation and Getting Started
Installation
install.packages("psych", dependencies = TRUE)
library(psych)
- The argument dependencies=TRUE ensures that any additional packages that may be needed are installed at the same time.
Getting Started
- Website: https://personality-project.org/r/psych/
- Documentation: ?psych in the R console or help(package=”psych”)
- Vignettes/Tutorials: Some functions include detailed examples, e.g. ?alpha.
(Tip: Be sure to check out the PDF documentation on the project website if you want to explore the topic in greater depth.)
Core Functions
Below, you will learn about some of the best-known functions in psych. There are, of course, many more, but these are a good starting point.
describe()
If you need descriptive statistics (mean, standard deviation, median, minimum, maximum, etc.) for your variables quickly, describe() is very useful:
library(psych)
# Beispiel-Datensatz
set.seed(123)
df <- data.frame(
score1 = rnorm(30, mean=50, sd=10),
score2 = rnorm(30, mean=60, sd=15)
)
describe(df)
The output includes, among other things, the number of observations (n), Mean, SD, Median, MAD (Median Absolute Deviation), Min, Max, and Skew (skewness). Perfect for getting a first overview of your variables.
pairs.panels()
A small highlight: combined visualizations of correlations, scatterplots, density curves, and p-values in a clear matrix.
pairs.panels(df)
- For each pair of columns, you get a scatterplot with a regression line, the correlation coefficient (Pearson r), and a significance indicator.
- Additionally, the distribution of each variable is visualized on the diagonal.
This is ideal for quickly checking relationships between several variables.
alpha() – Reliability analysis
Especially in psychology (or other scale-based disciplines), you often want to determine Cronbach’s alpha to assess a scale’s internal consistency. This is where alpha() comes in.
# Simulierter Beispiel-Datensatz für eine Skala mit 5 Items
scale_data <- data.frame(
item1 = rnorm(50, 3.5, 1),
item2 = rnorm(50, 3.3, 1),
item3 = rnorm(50, 3.7, 1),
item4 = rnorm(50, 3.4, 1),
item5 = rnorm(50, 3.6, 1)
)
alpha_result <- alpha(scale_data)
alpha_result
Important values:
- total$raw_alpha: Cronbach’s alpha in “raw” form
- total$std.alpha: Standardized alpha (if items have very different variances)
- alpha.drop: What happens to alpha if an item is removed?
This lets you see whether individual items reduce the scale’s reliability.
fa() – Factor analysis
To uncover latent dimensions, factor analysis (FA) is often used in psychology. fa() in psych offers you various rotation techniques and extraction methods.
# Beispiel: Wir haben 6 Items, die 2 Faktoren bilden sollen
items <- data.frame(
F1_item1 = rnorm(50, 5, 2),
F1_item2 = rnorm(50, 6, 2),
F2_item1 = rnorm(50, 10, 3),
F2_item2 = rnorm(50, 11, 3),
cross_item1 = rnorm(50, 8, 2),
cross_item2 = rnorm(50, 9, 2)
)
fa_result <- fa(items, nfactors=2, rotate="oblimin")
fa_result
Parameters:
- nfactors=2: Number of factors to extract
- rotate=”oblimin”: Oblique rotation (factors may be correlated)
Result: You obtain factor loadings (which item loads strongly on which factor?), communalities, eigenvalues, and more. Essential for dimensional analyses.
principal() – Principal component analysis (PCA)
If you prefer a principal component analysis (PCA) instead of an FA (e.g., for data reduction), you can use principal():
pca_result <- principal(items, nfactors=2, rotate="varimax")
pca_result
- nfactors=2: Extract two principal components
- rotate=”varimax”: Orthogonal rotation
You obtain factor loadings, proportions of explained variance, etc.
Brief practical example
Suppose you want to check the internal consistency of an 8-item scale in a study on personality research (Big Five) and then conduct a factor analysis.
#Import data:
mydata <- read.csv(“bigfive_sample.csv”)
#Descriptive overview:
describe(mydata[, 1:8]) # Assuming items 1–8 belong to one scale
#Cronbach’s alpha:
alpha(mydata[, 1:8])
#Factor analysis:
fa_result <- fa(mydata[, 1:8], nfactors=2, rotate=”oblimin”)
print(fa_result)
Interpretation:
- Look at the factor loadings: Do the items load on Factor 1 and Factor 2 as expected?
- Are certain items misfitting?
Conclusion
The psych package offers you an all-in-one package for many applications in psychology and the social sciences. Whether you are conducting reliability analysis, factor analysis, or simply need quick descriptive reporting—with alpha(), fa(), describe(), and related functions, you can obtain solid results in no time.
Especially when you work with scales, items, and factors, psych saves you a great deal of time because many features are already preconfigured—things you would otherwise have to build yourself at considerable effort.
Further information:
- Official website: https://personality-project.org/r/psych/
- PDF manual & examples on the same website.
- Function help: ?alpha, ?fa, ?pairs.panels, ?describe.
Good luck exploring the psych functions in R!
