Learn R Programming

kml3d (version 0.6)

affectIndiv: ~ Function: affectIndiv ~

Description

Given some longitudinal data (trajectories) and k clusters centers, affectIndiv affect each individual to the cluster whose center is the closest.

Usage

affectIndiv(traj, clustersCenter, distance = dist3d)

Arguments

traj
[array(numeric)]: longitudinal data. Each line is an individual, each column is a time measurement.
clustersCenter
[matrix]: cluster center. Each line is a cluster centers, each column is a time measurement.
distance
[character]: distance between an individual and a clusters centre.

Value

  • Object of class Partition.

Author(s)

Christophe Genolini INSERM U669 / PSIGIAM: Paris Sud Innovation Group in Adolescent Mental Health Modal'X / Universite Paris Ouest-Nanterre- La Defense Contact author : genolini@u-paris10.fr

Details

EM algorithm (like k-means) alternates between two phases : Esperance and Maximisation. During Maximisation, each individual is affected to the closest cluster. This is what affectIndiv does. The default distance dist3d is the euclidean distance but the user can define some non-classical distance. Note that affectIndiv does not work with a ClusterLongData object but with an array of trajectories. affectIndiv used with calculTrajMean simulates one k-means step (see examples).

References

Article "KmL: K-means for Longitudinal Data", in Computational Statistics, Volume 25, Issue 2 (2010), Page 317. Web site: http://christophe.genolini.free.fr/kml

Examples

Run this code
#######################
### affectIndiv

### Some trajectories
traj <- gald()["traj"]

### 4 clusters centers
center <- traj[runif(4,1,nrow(traj)),,]

### Affectation of each individual
part <- affectIndiv(traj,center)
plot(as.longData(traj),part)

### Unusual distance
distCor <- function(x,y){return(max(cor(x,y)))}
part2 <- affectIndiv(traj,center,distCor)
plot(as.longData(traj),part2)


#################
### K-means simulation (4 steps)
plot(as.longData(traj),part)
for (i in 1:4){
    center <- calculTrajMean(traj,part["clusters"])
    part <- affectIndiv(traj,center)
    plot(as.longData(traj),part)
}

Run the code above in your browser using DataLab