Learn R Programming

funcy (version 1.0.1)

dist2centers: Calculates curve distances to the centers.

Description

Distance to all cluster centers is calculated for each curve. Dataset can be in general format "Format1" or matrix format "Format2" (see formatFuncy).

Usage

dist2centers(data, centers)

Arguments

data

Dataset in "Format1" or "Format2".

centers

Matrix with cluster center curves in columns.

Value

Matrix of dimension nr_curves x nr_clusters.

Details

Calculates the sum of the squared distances between the curves and the cluster centers on the available time points and divides it by the total number of time points for the corresponding curve. If the dataset is in irregular format "Format1", center curves must correspond to evaluations on the unique union of all time points.

References

Christina Yassouridis and Dominik Ernst and Friedrich Leisch. Generalization, Combination and Extension of Functional Clustering Algorithms: The R Package funcy. Journal of Statistical Software. 85 (9). 1--25. 2018

Examples

Run this code
# NOT RUN {
##Generate dataset
set.seed(2804)
ds <- sampleFuncy(obsNr=100, k=4, timeNrMin=5, timeNrMax=10, reg=FALSE)
data <- Data(ds)
##Get unique union of all time points
time <- sort(unique(data[,3]))
##Generate center curves
c1 <- sin(time)+rnorm(30)
c2 <- cos(time)+rnorm(30)
c3 <- time^2+rnorm(3)
centers <- cbind(c1,c2,c3)
##Calculate distance to the centers
dist2centers(data, centers)
# }

Run the code above in your browser using DataLab