gmfd_kmeans {gmfd} | R Documentation |
k-means clustering algorithm
Description
This function performs a k-means clustering algorithm on an univariate or multivariate functional data using a generalization of Mahalanobis distance.
Usage
gmfd_kmeans(FD, n.cl = 2, metric, p = NULL, k_trunc = NULL)
Arguments
FD |
a functional data object of type |
n.cl |
an integer representing the number of clusters. |
metric |
the chosen distance to be used: |
p |
a positive numeric value containing the parameter of the regularizing function for the generalized Mahalanobis distance. |
k_trunc |
a positive numeric value representing the number of components at which the truncated mahalanobis distance must be truncated |
Value
The function returns a list with the following components:
cluster
: a vector of integers (from 1
to n.cl
) indicating the cluster to which each curve is allocated;
centers
: a list of d
matrices (k
x T
) containing the centroids of the clusters
References
Martino A., Ghiglietti A., Ieva F., Paganoni A. M. (2017). A k-means procedure based on a Mahalanobis type distance for clustering multivariate functional data, MOX report 44/2017
Ghiglietti A., Ieva F., Paganoni A. M. (2017). Statistical inference for stochastic processes: Two-sample hypothesis tests, Journal of Statistical Planning and Inference, 180:49-68.
Ghiglietti A., Paganoni A. M. (2017). Exact tests for the means of gaussian stochastic processes. Statistics & Probability Letters, 131:102–107.
See Also
Examples
# Define parameters
n <- 50
P <- 100
K <- 150
# Grid of the functional dataset
t <- seq( 0, 1, length.out = P )
# Define the means and the parameters to use in the simulation
m1 <- t^2 * ( 1 - t )
rho <- rep( 0, K )
theta <- matrix( 0, K, P )
for ( k in 1:K) {
rho[k] <- 1 / ( k + 1 )^2
if ( k%%2 == 0 )
theta[k, ] <- sqrt( 2 ) * sin( k * pi * t )
else if ( k%%2 != 0 && k != 1 )
theta[k, ] <- sqrt( 2 ) * cos( ( k - 1 ) * pi * t )
else
theta[k, ] <- rep( 1, P )
}
s <- 0
for (k in 4:K) {
s <- s + sqrt( rho[k] ) * theta[k, ]
}
m2 <- m1 + s
# Simulate the functional data
x1 <- gmfd_simulate( n, m1, rho = rho, theta = theta )
x2 <- gmfd_simulate( n, m2, rho = rho, theta = theta )
# Create a single functional dataset containing the simulated datasets:
FD <- funData(t, rbind( x1, x2 ) )
output <- gmfd_kmeans( FD, n.cl = 2, metric = "mahalanobis", p = 10^6 )