affectIndiv3d: ~ Function: affectIndiv3d ~

View source: R/kml3d.r

affectIndiv3dR Documentation

~ 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.

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.

Value

Object of classPartition.

Examples

#######################
### 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 (3 steps)
plot(clusterLongData3d(traj),parTraj=parTRAJ(col=part+1))
for (i in 1:3){
    center <- calculTrajMean3d(traj,part)
    part <- affectIndiv3d(traj,center)
    plot(clusterLongData3d(traj),parTraj=parTRAJ(col=part+1))
}

kml3d documentation built on Feb. 16, 2023, 9:44 p.m.