R: ~ Functions: affectIndiv & affectIndivC ~

affectIndiv {kml} | R Documentation

## ~ Functions: affectIndiv & affectIndivC ~

### Description

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

### Usage

    affectIndiv(traj, clustersCenter, distance = function(x,y){dist(rbind(x, y))})
    affectIndivC(traj, clustersCenter)

### Arguments

`traj` | `[matrix(numeric)]`: longitudinal data. Each line is an individual, each column is a time measurement.
`clustersCenter` | `[matrix(numeric)]`: clusters centre. Each line is a cluster center, each column is a time measurement.
`distance` | `[numeric <- function(trajectory,trajectory)]`: use to estimate the distance between an individual and a clusters center.

### Details

Given a matrix of clusters center `clustersCenter` (each line is a cluster center), the function `affectIndiv` affect each individual of the matrix `traj` to the closest clusters (according to `distance`). `affectIndivC` does the same but assume that the distance is the Euclidean distance. `affectIndivC` is writen in C (and is therefor much faster).

`affectIndiv` used with `calculTrajMean` simulates one k-means step.

### Value

Object of class`Partition`.

### Examples

    #######################
    ### affectIndiv

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

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

    ### Affectation of each individual
    system.time(part <- affectIndiv(traj,center))
    system.time(part <- affectIndivC(traj,center))

[Package kml version 2.4.1 Index]