Learn R Programming

kml3d (version 2.3)

affectIndiv3d: ~ Function: affectIndiv3d ~

Description

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

Usage

affectIndiv3d(traj, clustersCenter, distance = dist3d)

Arguments

traj
[array(numeric)]: longitudinal data. Each line is an individual, each column is a time measurement, each plan of the third dimension is for one variable.
clustersCenter
[array(numeric)]: cluster center. Each line is a cluster centers, each column is a time measurement, each plan of the third dimension is for one variable. .
distance
[numeric <- function(joint-trajectory,joint-trajectory)]: distance between an individual and a clusters centre.

Value

Details

Given an array of clusters center clustersCenter (each plan of the first dimension is a cluster center, that is clusterCenter[2,,] is the second cluster center), the function affectIndiv3d affect each individual of the array traj to the closest clusters, according to distance. affectIndiv3d used with calculTrajMean3d simulates one k-means 3D step.

Examples

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

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

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

### Affectation of each individual
part <- affectIndiv3d(traj,center)


#################
### K-means simulation (4 steps)
plot(clusterLongData3d(traj),partition(part))
for (i in 1:4){
    center <- calculTrajMean3d(traj,part)
    part <- affectIndiv3d(traj,center)
    plot(clusterLongData3d(traj),partition(part))
}

Run the code above in your browser using DataLab