R k-means cluster with pearson (ClusterR)

33 Views Asked by At

I'm trying to replicate a feature in Systat, which is k-means clustering with Pearson correlation.I've attempted to use the package called ClusterR as it allows me to modify some parameters. I have a file with 96 rows and five columns, one from Panelist, the other of regression coefficients (Coeff1, Coeff2, Coeff3, Coeff4). My aim is to create 2 clusters and have one of them assigned to each Panelist. I've tried multiple modifications of the code below, but nothing seems to work. Help would be greatly appreciated. Bonus if I could specify iterations = 20 (Clara_Medoids does not seem to support this argument) Thanks again!

    library(ClusterR)
    library(dplyr)

# Load data
    data <- Coefficients

# Subset data to columns Coeff1 to Coeff4
    data <- Coefficients[, c("Coeff1", "Coeff2", "Coeff3", "Coeff4")]

# Define entire sample
    entire_sample <- nrow(data)

# Run ClusterR k-means with Pearson correlation
clusters <- Clara_Medoids(
  data = data,
  clusters = 2,
  samples = entire_sample,
  sample_size = 1,
  distance_metric = "pearson_correlation",
  minkowski_p = 1,
  threads = 1,
  swap_phase = TRUE,
  fuzzy = FALSE,
  verbose = FALSE,
  seed = 1)

# Add cluster assignments to original dataset
`Coefficients$clusterID <- clusters$clusterID`

# Write results to file
    write.csv(Coefficients, "path/to/results.csv")

gives me output with no cluster membership
0

There are 0 best solutions below