Learn R Programming

paar (version 1.0.1)

fuzzy_k_means: Fuzzy k-means clustering

Description

Performs a vectorized fuzzy k-means clustering, this procedure it is not spatial. The function is almost a wrapper of the function cmeans from the package e1071. Is intended to be used when `KM-sPC` procedure is not possible because data set has only 1 variable.

Usage

fuzzy_k_means(
  data,
  variables,
  number_cluster = 3:5,
  fuzzyness = 1.2,
  distance = "euclidean"
)

Value

a list with classification results and indices to select best number of clusters.

Arguments

data

sf object

variables

variables to use for clustering, if missing, all numeric variables will be used

number_cluster

numeric vector with number of final clusters

fuzzyness

A number greater than 1 giving the degree of fuzzification.

distance

character Must be one of the following: If "euclidean", the mean square error, if "manhattan", the mean absolute error is computed. Abbreviations are also accepted.

Examples

Run this code
library(sf)
data(wheat, package = 'paar')

# Transform the data.frame into a sf object
wheat_sf <- st_as_sf(wheat,
                     coords = c('x', 'y'),
                     crs = 32720)

# Run the fuzzy_k_means function
fuzzy_k_means_results <- fuzzy_k_means(wheat_sf,
                               variables = 'Tg',
                               number_cluster = 2:4)

# Print the summaryResults
fuzzy_k_means_results$summaryResults

# Print the indices
fuzzy_k_means_results$indices

# Print the cluster
head(fuzzy_k_means_results$cluster, 5)

# Combine the results in a single object
wheat_clustered <- cbind(wheat_sf, fuzzy_k_means_results$cluster)

# Plot the results
plot(wheat_clustered[, "Cluster_2"])

Run the code above in your browser using DataLab