prcr
is an R
package for person-centered analysis. Person-centered analyses focus on clusters, or profiles, of observations, and their change over time or differences across factors. See Bergman and El-Khouri (1999) for a description of the analytic approach. See Corpus and Wormington (2014) for an example of person-centered analysis in psychology and education.
In this example using the built-in to R mtcars
data for fuel consumption and other information for 32 automobiles, the variables disp
(for engine displacement, in cu. in.), qsec
(for the 1/4 mile time, in seconds), and wt
for weight (in 1000 lbs.) are clustered with a 2
cluster solution specified. Because the variables are in very different units, the to_scale
argument is set to TRUE
.
library(prcr)
mtcars_df <- as.data.frame(mtcars[, c("disp", "hp", "wt")])
two_profile_solution <- create_profiles(mtcars_df, 2, to_scale = T)
## Prepared data: Removed 0 incomplete cases
## Clustered data: Using a 2 cluster solution
## Calculated statistics: R-squared = 0.694
summary(two_profile_solution)
## 2 cluster solution (R-squared = 0.694)
##
## Profile n and means:
##
## # A tibble: 2 × 4
## Cluster disp hp wt
## <chr> <dbl> <dbl> <dbl>
## 1 Cluster 1 (18 obs.) 0.5111562 0.5977198 0.764663
## 2 Cluster 2 (14 obs.) 1.3316418 1.2753130 1.172091
print(two_profile_solution)
## $clustered_processed_data
##
## # A tibble: 2 × 4
## Cluster disp hp wt
## <chr> <dbl> <dbl> <dbl>
## 1 Cluster 1 (18 obs.) 0.5111562 0.5977198 0.764663
## 2 Cluster 2 (14 obs.) 1.3316418 1.2753130 1.172091
##
## $clustered_raw_data
##
## # A tibble: 32 × 4
## disp hp wt cluster
## <dbl> <dbl> <dbl> <int>
## 1 0.6034061 0.6705299 0.7678706 1
## 2 0.6034061 0.6705299 0.8426061 1
## 3 0.4072991 0.5669025 0.6799465 1
## 4 0.9729923 0.6705299 0.9422535 1
## 5 1.3576637 1.0667521 1.0081965 2
## 6 0.8485398 0.6400513 1.0140582 1
## 7 1.3576637 1.4934529 1.0462970 2
## 8 0.5532480 0.3779350 0.9349264 1
## 9 0.5309974 0.5790940 0.9232032 1
## 10 0.6320679 0.7497743 1.0081965 1
## # ... with 22 more rows
plot(two_profile_solution)
The output has the class prcr
and has slots for additional information that can be extracted from it, such as the r-squared (for comparing the relative fit of different cluster solutions) raw clustered data (i.e., for conducting statistical tests to determine whether the cluster centroids are different from one another and for use in additional analyses) and the processed data (i.e., for creating different plots of the cluster centroids).
two_profile_solution$r_squared
## [1] 0.6937963
two_profile_solution$clustered_raw_data
## # A tibble: 32 × 4
## disp hp wt cluster
## <dbl> <dbl> <dbl> <int>
## 1 0.6034061 0.6705299 0.7678706 1
## 2 0.6034061 0.6705299 0.8426061 1
## 3 0.4072991 0.5669025 0.6799465 1
## 4 0.9729923 0.6705299 0.9422535 1
## 5 1.3576637 1.0667521 1.0081965 2
## 6 0.8485398 0.6400513 1.0140582 1
## 7 1.3576637 1.4934529 1.0462970 2
## 8 0.5532480 0.3779350 0.9349264 1
## 9 0.5309974 0.5790940 0.9232032 1
## 10 0.6320679 0.7497743 1.0081965 1
## # ... with 22 more rows
two_profile_solution$clustered_processed_data
## # A tibble: 2 × 4
## Cluster disp hp wt
## <chr> <dbl> <dbl> <dbl>
## 1 Cluster 1 (18 obs.) 0.5111562 0.5977198 0.764663
## 2 Cluster 2 (14 obs.) 1.3316418 1.2753130 1.172091
Functions for easily comparing the r-squared value for a range of cluster solutions, and for carrying out cross-validation of the clustering solution, will be added in future updates to the package.