~kmlShape ~

Description

This function run k-means for longitudinal data using some shape respecting distance and mean.

Usage

1
2
kmlShape(myClds, nbClusters = 3, timeScale = 0.1, FrechetSumOrMax =
"max", toPlot="both", parAlgo=parKmlShape())

Arguments

myClds

[Clds]: Object that hold the trajectories, the 'senators' resulting from a simplification of the trajectories and, after the use of kmlShape, the clusters.

nbClusters

[numeric] or [vector(numeric)]: either the number of clusters, or a vector of initial (distinct) cluster centers. If a number, a random set of (distinct) trajectories is chosen as the initial centres.

timeScale

[numeric]: allow to modify the time scale, increasing or decreasing the cost of the horizontal shift. If timeScale is very big, then the Frechet mean tends to the euclidienne distance. If timeScale is very small, then it tends to the Dynamic Time Warping.

FrechetSumOrMax

[character]: kmlShape uses Frechet's distance and Frechet path. Since both of them can be define using the 'sum' function or the 'max' function, this option let the user to chose one or the other.

toPlot

[character]: use 'traj' for graphical display during computation, or 'none' for a faster but quiet run.

parAlgo

[ParKmlShape]: parameters used to run the algorithm. They can be change using the function parKmlShape. Option are mainly 'aggregationMethod', 'shuffle', 'sampleSize', 'methodHclust' and 'maxIter'. See ParKmlShape for details.

Details

This function run k-means for longitudinal data using a shape respecting distance (distFrechet) and a shape respecting mean (meanFrechet). See [1] for details.

Value

An object of class Clds in which the field 'clustersSenators', 'clusters' and 'trajMeans' are now filled.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
###########
### Example

### Generating artificial data
nbLignes <- 20
trajG <- matrix(0,nbLignes,10)
for(i in 1:(nbLignes/2)){
   trajG[i,] <- dnorm(1:10,runif(1,3,8),1)*rnorm(1,10,0.1)
}
for(i in (nbLignes/2+1):nbLignes){
   trajG[i,] <- dnorm(1:10,runif(1,3,8),1)*rnorm(1,5,0.1)
}

myClds <- cldsWide(data.frame(1:20,trajG))
plot(myClds)

### kmlshape
par(ask=FALSE)
kmlShape(myClds,2)
par(ask=TRUE)
plot(myClds)



###########
### Example 2

### Generating artificial data
nbLignes <- 12
trajH <- matrix(0,nbLignes,10)

 for(i in 1:(nbLignes/3)){
   trajH[i,] <- pnorm(1:10,runif(1,3,8),1)*rnorm(1,10,1)
}
for(i in (nbLignes/3+1):(2*nbLignes/3)){
   trajH[i,] <- dnorm(1:10,runif(1,3,8),1)*rnorm(1,13,1)
}

for(i in (2*nbLignes/3+1):nbLignes){
   trajH[i,] <- pnorm(1:10,runif(1,3,8),1)*rnorm(1,5,0.1)
}

myClds2 <- cldsWide(data.frame(1:60,trajH))
plot(myClds2)

### kmlshape
par(ask=FALSE)
kmlShape(myClds2,3)
par(ask=TRUE)
plot(myClds2)