Package {fcmfd}


Type: Package
Title: Fuzzy C-Means for Fuzzy Data
Version: 0.1.0
Description: Implements a fuzzy clustering approach for ordinal Likert-type data using triangular fuzzy numbers (TFNs). The package extends the classical fuzzy C-means algorithm to better handle uncertainty in ordinal scales and includes automatic selection of the number of clusters using the Xie-Beni validity index. References: Coppi, R., D'Urso, P., and Giordani, P. (2012), Fuzzy and possibilistic clustering for fuzzy data, <doi:10.1016/j.csda.2010.09.013>. Xie, X. L. and Beni, G. (1991), A validity measure for fuzzy clustering, <doi:10.1109/34.85677>.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Depends: R (≥ 3.5)
Imports: stats, graphics
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
RoxygenNote: 7.3.3
NeedsCompilation: no
Packaged: 2026-04-30 17:50:24 UTC; pepeo
Author: José Ortigas [aut, cre]
Maintainer: José Ortigas <jose.ortigas@unmsm.edu.pe>
Repository: CRAN
Date/Publication: 2026-05-05 13:54:10 UTC

Build Fuzzy Dictionary

Description

Constructs a fuzzy dictionary based on the selected scale type (symmetric or asymmetric).

Usage

build_dictionary(type, option, dictionary = NULL)

Arguments

type

Character. Dictionary type ("symmetric" or "asymmetric").

option

Character. Scale option ("A", "B", "C", or "D").

dictionary

Optional matrix for asymmetric dictionaries.

Details

For symmetric dictionaries, predefined TFN structures are generated. For asymmetric dictionaries, user-defined matrices are validated and converted to list format.

Value

A list representing the fuzzy dictionary.


Check Convergence of Membership Matrix

Description

Evaluates convergence based on the Frobenius norm between two membership matrices.

Usage

check_convergence(U_old, U_new, epsilon = 1e-06)

Arguments

U_old

Previous membership matrix.

U_new

Updated membership matrix.

epsilon

Convergence tolerance.

Value

Logical value indicating convergence.


Hard Cluster Assignment

Description

Assigns each observation to the cluster with the highest membership value.

Usage

cluster_assignment(object)

Arguments

object

An object of class "fcmTFN".

Value

A factor indicating cluster labels.


Compute Cluster Prototypes

Description

Computes fuzzy cluster prototypes (centroids) using membership degrees and triangular fuzzy numbers.

Usage

compute_prototypes(fuzzy_data, U, m = 2)

Arguments

fuzzy_data

A list of TFN matrices.

U

Membership matrix.

m

Numeric. Fuzzifier parameter (default = 2).

Details

Each prototype is calculated as a weighted average of fuzzy observations using membership degrees raised to the fuzzifier parameter m.

Value

A list of prototype matrices.


Compute Adaptive Weights

Description

Computes adaptive weights for modal (wc) and spread (ws) components based on fuzzy distances and membership degrees.

Usage

compute_weights(fuzzy_data, prototypes, U, m = 2)

Arguments

fuzzy_data

List of TFN matrices.

prototypes

List of prototype matrices.

U

Membership matrix.

m

Fuzzifier parameter.

Value

A list with wc and ws.


Compute Xie-Beni Cluster Validity Index

Description

Computes the Xie-Beni (XB) index used to evaluate the compactness and separation of fuzzy clusters.

Usage

compute_xie_beni_index(fuzzy_data, U, prototypes, wc, ws, m = 2)

Arguments

fuzzy_data

List of triangular fuzzy numbers representing the dataset.

U

Membership matrix (n x k).

prototypes

List of cluster prototypes.

wc

Modal weight.

ws

Spread weight.

m

Fuzzifier parameter.

Details

The Xie-Beni index is defined as:

XB = \frac{ \sum_{i=1}^{n} \sum_{g=1}^{k} u_{ig}^{m} d^{2}(x_i, h_g) }{ n \min_{g \ne g'} d^{2}(h_g, h_{g'}) }

Lower values indicate better clustering performance.

Value

Numeric value representing the Xie-Beni index.


Convert Matrix to Dictionary List

Description

Converts a matrix representation of triangular fuzzy numbers (TFN) into a named list format used internally by the system.

Usage

convert_matrix_to_list(matrix)

Arguments

matrix

A numeric matrix with columns (l, c, r).

Details

The input matrix must contain three columns: (l, c, r), where: l = left spread c = modal value r = right spread

Value

A named list containing triangular fuzzy numbers.


Convert Data to Triangular Fuzzy Numbers (TFN)

Description

Converts ordinal data into triangular fuzzy numbers using the provided fuzzy dictionary.

Usage

convert_to_tfn(data, dictionary)

Arguments

data

A data.frame or matrix containing ordinal values.

dictionary

A named list representing the fuzzy dictionary.

Details

Each observation is transformed into a matrix where rows represent variables and columns correspond to (l, c, r) values.

Value

A list of matrices containing TFN representations.


Default Symmetric Fuzzy Dictionary

Description

Generates predefined symmetric triangular fuzzy number (TFN) dictionaries for ordinal Likert-type scales.

Usage

default_symmetric_dictionary(option = "A")

Arguments

option

Character. Dictionary option ("A", "B", "C", or "D").

Details

Available options: A: 5-point scale B: 7-point scale C: 10-point scale (1–10) D: 11-point scale (0–10)

Value

A list containing triangular fuzzy numbers (l, c, r).


Fuzzy C-Means Clustering for Triangular Fuzzy Numbers

Description

Performs fuzzy clustering on ordinal Likert-type data represented as triangular fuzzy numbers (TFNs).

Usage

fcmTFN(
  data,
  type = "symmetric",
  option = "B",
  dictionary = NULL,
  k_values = 2:6,
  m = 2,
  epsilon = 1e-06,
  max_iter = 1000,
  verbose = TRUE
)

Arguments

data

A data.frame or matrix containing ordinal Likert-type values.

type

Dictionary type ("symmetric" or "asymmetric").

option

Dictionary option ("A", "B", "C", or "D").

dictionary

Optional custom dictionary for asymmetric definitions.

k_values

Numeric vector of candidate numbers of clusters.

m

Fuzzifier parameter (m > 1).

epsilon

Convergence tolerance.

max_iter

Maximum number of iterations.

verbose

Logical; if TRUE, prints progress messages.

Details

The function automatically determines the optimal number of clusters based on the Xie-Beni validity index.

Value

An object of class '"fcmTFN"' and '"fcm"'.

References

Coppi, R., D'Urso, P., & Giordani, P. (2012). Fuzzy and possibilistic clustering for fuzzy data. <doi:10.1016/j.csda.2010.09.013>

Xie, X. L., & Beni, G. (1991). A validity measure for fuzzy clustering. <doi:10.1109/34.85677>


Fuzzy K-Means for TFN Data

Description

Core iterative algorithm for fuzzy clustering using triangular fuzzy numbers.

Usage

fkm_f_algorithm(fuzzy_data, k, m = 2, epsilon = 1e-06, max_iter = 1000)

Arguments

fuzzy_data

List of TFN matrices.

k

Number of clusters.

m

Fuzzifier parameter.

epsilon

Convergence tolerance.

max_iter

Maximum iterations.

Value

List containing clustering results.


Compute Fuzzy Distance Between TFNs

Description

Computes the distance between two triangular fuzzy number (TFN) matrices using weighted Euclidean distance.

Usage

fuzzy_distance(x, h, wc, ws)

Arguments

x

A TFN matrix (observation).

h

A TFN matrix (prototype).

wc

Numeric. Weight for modal component.

ws

Numeric. Weight for spread components.

Details

The distance accounts for differences in modal values and spreads, controlled by weights wc and ws.

Value

A numeric distance value.


Initialize Membership Matrix

Description

Generates an initial fuzzy membership matrix (U) with random values and normalizes each row so that memberships sum to 1.

Usage

initialize_U(n, k)

Arguments

n

Integer. Number of observations.

k

Integer. Number of clusters.

Value

A numeric matrix of size n × k representing initial membership degrees.


Extract Membership Matrix

Description

Returns the fuzzy membership matrix obtained from the Fuzzy C-Means clustering process.

Usage

membership(object)

Arguments

object

An object of class "fcmTFN".

Value

A matrix where rows represent observations and columns represent clusters.


Plot Fuzzy Dictionary

Description

Plots the triangular fuzzy numbers defining the Likert-scale dictionary.

Usage

plot_dictionary(object)

Arguments

object

An object of class "fcmTFN".

Value

A plot showing triangular membership functions.


Plot Cluster Prototypes

Description

Visualizes cluster prototypes as interval plots using triangular fuzzy numbers (l, c, r).

Usage

plot_prototypes(
  object,
  cluster = 1,
  use_var_names = FALSE,
  var_names = NULL,
  ...
)

Arguments

object

An object of class "fcmTFN".

cluster

Integer cluster to plot.

use_var_names

Logical.

var_names

Optional variable names.

...

Additional graphical parameters.

Value

Invisibly returns NULL.


Plot Xie-Beni Index

Description

Plots the Xie-Beni validity index across candidate numbers of clusters.

Usage

plot_xb(object, mark_optimal = TRUE, type = "b", ...)

Arguments

object

An object of class "fcmTFN".

mark_optimal

Logical. Whether to highlight the optimal k.

type

Plot type (default = "b").

...

Additional graphical parameters.

Value

Invisibly returns NULL.


Prepare Input System

Description

Prepares and validates all input components required for fuzzy clustering analysis.

Usage

prepare_input_system(data, type = "symmetric", option = "A", dictionary = NULL)

Arguments

data

A data.frame or matrix containing ordinal values.

type

Character. Dictionary type ("symmetric" or "asymmetric").

option

Character. Scale option ("A", "B", "C", or "D").

dictionary

Optional matrix for asymmetric dictionaries.

Details

The function performs the following steps: 1. Validates raw data 2. Builds fuzzy dictionary 3. Validates data values against dictionary 4. Converts data into triangular fuzzy numbers (TFN)

Value

A list containing processed system inputs.


Description

Displays a concise summary of a fitted fuzzy C-means model using triangular fuzzy numbers.

Usage

print_fcmTFN(x, ...)

Arguments

x

An object of class "fcmTFN".

...

Additional arguments (not used).

Value

The input object (invisibly).


Prototype Matrix Extraction

Description

Returns cluster prototypes as a readable matrix containing l, c, r values for each variable.

Usage

prototype_matrix(object, use_var_names = FALSE, var_names = NULL)

Arguments

object

An object of class "fcmTFN".

use_var_names

Logical.

var_names

Optional variable names.

Value

A data.frame containing prototype values.


Select Optimal Number of Clusters

Description

Runs the fuzzy clustering algorithm for multiple candidate values of k and selects the optimal one using the Xie-Beni index.

Usage

select_optimal_k(
  fuzzy_data,
  k_values,
  m = 2,
  epsilon = 1e-06,
  max_iter = 100,
  verbose = TRUE
)

Arguments

fuzzy_data

List of TFN matrices.

k_values

Numeric vector of candidate cluster numbers.

m

Fuzzifier parameter.

epsilon

Convergence tolerance.

max_iter

Maximum number of iterations.

verbose

Logical; if TRUE, prints progress messages.

Value

A list containing:


Simulated Likert 1–7 Survey Dataset

Description

A simulated Likert-type dataset with three well-separated clusters. Designed for testing fuzzy clustering of ordinal data.

Usage

sim_likert7

Format

A data.frame with 300 rows and 12 variables:

Q1

Likert response (1–7)

Q2

Likert response (1–7)

Q3

Likert response (1–7)

Q4

Likert response (1–7)

Q5

Likert response (1–7)

Q6

Likert response (1–7)

Q7

Likert response (1–7)

Q8

Likert response (1–7)

Q9

Likert response (1–7)

Q10

Likert response (1–7)

Q11

Likert response (1–7)

Q12

Likert response (1–7)

Details

The dataset contains responses measured on a 1–7 Likert scale across 12 variables.

The dataset was generated using three latent profiles centered approximately at:

• Low agreement (\approx 2) • Moderate agreement (\approx 4) • High agreement (\approx 6)

Each cluster contains 100 observations.

Source

Simulated data generated for package examples.


Simulated Likert Data (0–10 Scale)

Description

A synthetic dataset representing ordinal Likert-type responses measured on a 0–10 scale.

Usage

sim_likert_0_10

Format

A data.frame with 500 observations and 10 variables:

life_satisfaction

Overall life satisfaction

happiness

Self-reported happiness

anxiety

Anxiety level

depression

Depression level

health

Self-rated health

income_satisfaction

Income satisfaction

job_satisfaction

Job satisfaction

social_relationships

Social relationships quality

trust_in_others

Trust in others

future_expectations

Future expectations

Details

The dataset is designed with an underlying cluster structure (low, medium, high profiles) to support clustering validation.

The dataset contains three latent groups representing different levels of well-being.

Source

Simulated data


Summary for fcmTFN Objects

Description

Displays a summary of the Fuzzy C-Means clustering results for triangular fuzzy numbers.

Usage

## S3 method for class 'fcmTFN'
summary(object, ...)

Arguments

object

An object of class "fcmTFN".

...

Additional arguments (not used).

Value

Prints a formatted summary of the clustering result.


Update Membership Matrix

Description

Updates the fuzzy membership matrix (U) based on distances between observations and cluster prototypes.

Usage

update_membership(fuzzy_data, prototypes, wc, ws, m = 2)

Arguments

fuzzy_data

List of TFN matrices.

prototypes

List of cluster prototypes.

wc

Modal weight.

ws

Spread weight.

m

Fuzzifier parameter.

Value

Updated membership matrix U.


Validate Asymmetric Fuzzy Dictionary

Description

Validates a user-defined asymmetric triangular fuzzy number (TFN) dictionary to ensure structural consistency with the selected scale.

Usage

validate_asymmetric_dictionary(matrix, option)

Arguments

matrix

A numeric matrix with columns (l, c, r).

option

Character. Scale option ("A", "B", "C", or "D").

Details

The function verifies: - Object type (matrix) - Number of columns (l, c, r) - Number of rows according to selected option - Valid modal values - Logical ordering (l <= c <= r) - Value bounds within allowed scale limits

Value

Invisibly returns TRUE if validation passes.


Validate Input Data

Description

Checks that the input data object is valid for fuzzy clustering analysis.

Usage

validate_data(data)

Arguments

data

A data.frame or matrix.

Details

The function verifies: - Object type (data.frame or matrix) - Non-zero dimensions - Absence of missing values

Value

Invisibly returns TRUE if validation passes.


Validate Data Values Against Dictionary

Description

Checks that all values in the input data are present in the fuzzy dictionary modes.

Usage

validate_data_values(data, dictionary)

Arguments

data

A data.frame or matrix containing ordinal values.

dictionary

A named list representing the fuzzy dictionary.

Details

The function verifies that every unique value in the dataset matches a valid dictionary key.

Value

Invisibly returns TRUE if validation passes.