kma(x, y0 = NULL, y1 = NULL, n.clust = 1, warping.method = "affine",
similarity.method = "d1.pearson", center.method = "k-means", seeds = NULL,
optim.method = "L-BFGS-B", span = 0.15, t.max = 0.1, m.max = 0.1, n.out = NULL,
tol = 0.01, fence = TRUE, iter.max = 100, show.iter = 0, nstart=2, return.all=FALSE,
check.total.similarity=FALSE)x can also be a vector of length grid.size. In this case, x will be used as abscissa grid for all functions.x. n.func: number of functions in the dataset. grid.size: maximal number of abscissa values where each function is evaluated. d: (only if the sample is multidimensional) number of function components, i.e. each function is a d-dimensional curve. Default value of y0 is NULL. The parameter y0 must be provided if the chosen similarity.method concerns original functions.x. Default value of y1 is NULL. The parameter y1 must be provided if the chosen similarity.method concerns original function first derivatives.1. Note that if n.clust=1 kma performs only alignment without clustering.warping.method='NOalignment' kma performs only k-mean clustering (without alignment). If warping.method='affine' kma performs alignment (and possibly clustering) of functions using linear affine transformation as warping functions, i.e., x.final = dilation*x + shift. If warping.method='shift' kma allows only shift, i.e., x.final = x + shift. If warping.method='dilation' kma allows only dilation, i.e., x.final = dilation*x. Default value is 'affine'.'d0.pearson', 'd1.pearson', 'd0.L2', 'd1.L2', 'd0.L2.centered', 'd1.L2.centered'. Default value is 'd1.pearson'. See kma.similarity for details.'k-means' and 'k-medoids'. Default value is 'k-means'.nstart initializations. In the case where not all the values of seeds are provided, those not provided are randomly chosen among the n.func original functions. If seeds=NULL all the centers are randomly chosen. Default value of seeds is NULL'L-BFGS-B' and 'SANN'. See optim function for details. Default method is 'L-BFGS-B'.
center.method='k-means'. Default value is 0.15. If center.method='k-medoids' value of span is ignored.t.max controls the maximal allowed shift, at each iteration, in the alignment procedure with respect to the range of curve domains. t.max must be such that 0t.max=0.1 means that shift is bounded, at each iteration, between -0.1*range(x) and +0.1*range(x)). Default value is 0.1. If warping.method='dilation' value of t.max is ignored.m.max controls the maximal allowed dilation, at each iteration, in the alignment procedure. m.max must be such that 0m.max=0.1 means that dilation is bounded, at each iteration, between 1-0.1 and 1+0.1 ). Default value is 0.1. If warping.method='shift' value of m.max is ignored.round(1.1*grid.size).tol. Default value is 0.01.fence=TRUE a control is activated at the end of each iteration. The aim of the control is to avoid shift/dilation outlighers with respect to their computed distributions. If fence=TRUE the running time can increase considerably. Default value of fence is TRUE.100.show.iter=TRUE kma shows the current iteration of the algorithm. Default value is FALSE.2. This parameter is used only if center.method is 'k-medoids'. When center.method = 'k-means' one initialization is performed.return.all=TRUE the results of all the nstart initializations are returned; the output is a list of length nstart. If return.all=FALSE only the best result is provided (the one with higher mean similarity if similarity.method is 'd0.pearson' or'd1.pearson', or the one with lower distance if similarity.method is 'd0.L2', 'd1.L2', 'd0.L2.centered' or 'd1.L2.centered'). Default value is FALSE.check.total.similarity=TRUE at each iteration the algorithm checks if there is a decrease of the total similarity and stops. In the affermative case the result obtained in the penultimate iteration is returned. Default value is FALSEwarping.method='k-means' there are two scenarios: if similarity.method='d0.pearson' or 'd0.L2' or d0.L2.centered the original function center is computed via loess procedure applied to original data; if similarity.method='d1.pearson' or 'd1.L2' or d1.L2.centered it is computed by integration of first derivatives center y1.center.orig (the integration constant is computed minimizing the sum of the weighed L2 distances between the center and the original functions). If warping.method='k-medoids' the original function center is the medoid of original functions.warping.method='k-means' the original center is computed via loess procedure applied to original function first derivatives. If warping.method='k-medoids' the original center is the medoid of original functions.center.method='k.means', the parameter n.clust.final may differ from initial number of clusters (i.e., from n.clust) if some clusters are found to be empty. In this case a warning message is issued.y0.centers.final is NULL if y0 is not given as input.y1.centers.final is NULL if the chosen similarity measure does not concern function first derivatives.x to obtain the aligned abscissas x.final.x to obtain the aligned abscissas x.final.Sangalli, L.M., Secchi, P., Vantini, S., 2014. "Analysis of AneuRisk65 data: K-mean Alignment". Electronic Journal of Statistics, Special Section on "Statistics of Time Warpings and Phase Variations", Vol. 8, No. 2, 1891-1904.
kma.compare, kma.similarity, fdakma, kma.data, kma.show.results
data(kma.data)
x <- kma.data$x # abscissas
y0 <- kma.data$y0 # evaluations of original functions
y1 <- kma.data$y1 # evaluations of original function first derivatives
## Not run:
# # Plot of original functions
# matplot(t(x),t(y0), type='l', xlab='x', ylab='orig.func')
# title ('Original functions')
#
# # Plot of original function first derivatives
# matplot(t(x),t(y1), type='l', xlab='x', ylab='orig.deriv')
# title ('Original function first derivatives')
#
#
# # Example: result of kma function with 2 clusters,
# # allowing affine transformation for the abscissas
# # and considering 'd1.pearson' as similarity.method.
# kma_example <- kma (
# x=x, y0=y0, y1=y1, n.clust = 2,
# warping.method = 'affine',
# similarity.method = 'd1.pearson',
# center.method = 'k-means',
# seeds = c(1,21)
# )
#
# kma.show.results(kma_example)
#
# names(kma_example)
#
# # Labels assigned to each function
# kma_example$labels
#
# # Total shifts and dilations applied to the original
# # abscissa to obtain the aligned abscissa
# kma_example$shift
# kma_example$dilation
# ## End(Not run)
Run the code above in your browser using DataLab