Learn R Programming

kmlShape (version 0.9.5)

kmlShape: ~kmlShape ~

Description

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

Usage

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
FrechetSumOrMax
[character]: kmlShape uses Frechet's distance and Frechet path. Since both of them can be define using the 'sum
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', 'shu

Value

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

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.

Examples

Run this code
###########
### 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)

Run the code above in your browser using DataLab