Learn R Programming

kml3d (version 2.3)

calculTrajMean3d: ~ Function: calculTrajMean3d ~

Description

Given some joint longitudinal data and a cluster affectation, calculTrajMean3d computes the mean joint-trajectories of each cluster.

Usage

calculTrajMean3d(traj, clust,centerMethod=function(x){mean(x,na.rm=TRUE)})

Arguments

traj
[array(numeric)]: joint longitudinal data. Each line is an individual, each column is a time measurement, the third dimension is for variables.
clust
[vector(numeric)]: affectation of each individual.
centerMethod
[joint-trajectory <- function(array(numeric))]: function used to compute the clusters' centers.

Value

  • An array of dimension (k,t,v) with k number of groups, t number of time mesurement and v number of variables.

Details

Given a vector of affectation to a cluster, the function calculTrajMean3d compute the "central" trajectory of each clusters. The "center" can be define using the argument centerMethod. affectIndiv3d used with calculTrajMean3d simulates one k-means step.

Examples

Run this code
#######################
### calculTrajMean3d

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

### A partition
part <- floor(runif(150,1,5))
plot(clusterLongData3d(traj),partition(part))

### Clusters center
(center <- calculTrajMean3d(traj,part))


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

Run the code above in your browser using DataLab