How exactly to create factor columns in original data after performing iclust clustering in R?

28 views Asked by At

I have created a reprex below. From the iclust function in the psych package. They show how you can get an equivalent of a factor solution from fa.diagram. I want to use these loadings and create the corresponding factor columns in my data. You will see below I have created a data.frame called dummy_data which has corresponding columns and dummy data to the items we originally performed the clustering on. Harman74.cor doesn't contain the original data but instead the correlation matrix.

library(psych)
library(datasets)


# Steps from iclust -------------------------------------------------------
test_data <- Harman74.cor


#use all defaults and stop at 4 clusters
ic_out4 <- psych::iclust(test_data$cov, nclusters =4, title="Force 4 clusters")  

summary(ic_out4)
#> ICLUST (Item Cluster Analysis)Call: psych::iclust(r.mat = test_data$cov, nclusters = 4, title = "Force 4 clusters")
#> Force 4 clusters 
#> 
#> Purified Alpha:
#>  C13  C20  C15   V2 
#> 0.90 0.84 0.81 0.48 
#> 
#>  Guttman Lambda6* 
#>  C13  C20   V2  C15 
#> 0.90 0.87 0.52 0.84 
#> 
#> Original Beta:
#>  C13  C20   V2  C15 
#> 0.79 0.74   NA 0.74 
#> 
#> Cluster size:
#> C13 C20 C15  V2 
#>   5  12   5   2 
#> 
#> Purified scale intercorrelations
#>  reliabilities on diagonal
#>  correlations corrected for attenuation above diagonal: 
#>      C13  C20  C15   V2
#> C13 0.90 0.69 0.54 0.52
#> C20 0.60 0.84 0.71 0.75
#> C15 0.46 0.59 0.81 0.39
#> V2  0.34 0.48 0.24 0.48

#use a dot graphics viewer on the out.file
#dot.graph <- ICLUST.graph(ic.out,out.file="test.ICLUST.graph.dot")  
#show the equivalent of a factor solution 
psych::fa.diagram(ic_out4$pattern,Phi=ic_out4$Phi,main="Pattern taken from iclust") 



# Dummy data for use ------------------------------------------------------
# Set the seed for reproducibility
set.seed(42)

# Create the column names
columns <- c(
  "VisualPerception", "Cubes", "PaperFormBoard", "Flags", "GeneralInformation", "ParagraphComprehension",
  "SentenceCompletion", "WordClassification", "WordMeaning", "Addition", "Code", "CountingDots",
  "StraightCurvedCapitals", "WordRecognition", "NumberRecognition", "FigureRecognition",
  "ObjectNumber", "NumberFigure", "FigureWord", "Deduction", "NumericalPuzzles",
  "ProblemReasoning", "SeriesCompletion", "ArithmeticProblems"
)

# Create the dummy data
n <- 145
dummy_data <- data.frame(matrix(rnorm(n * length(columns)), nrow = n))
colnames(dummy_data) <- columns

Created on 2023-06-14 by the reprex package (v2.0.1)

0

There are 0 answers