Learn R Programming

kml (version 2.4.6.1)

calculTrajMean: ~ Functions: calculTrajMean & calculTrajMeanC ~

Description

Given some longitudinal data and a cluster affectation, calculTrajMean and calculTrajMeanC compute the mean trajectories of each cluster.

Usage

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

Value

A matrix with k line and t column containing k clusters centers. Each line is a center, each column is a time measurement.

Arguments

traj

[matrix(numeric)]: longitudinal data. Each line is an individual, each column is a time measurement.

clust

[vector(numeric)]: affectation of each individual.

centerMethod

[trajectory <- function(matrix(numeric))]: function that compute the mean trajectory of a group of trajectories.

Details

Given a vector of affectation to a cluster, the function calculTrajMean compute the "central" trajectory of each clusters. The "center" can be define using the argument centerMethod. calculTrajMeanC does the same but assume that the center definition is the classic "mean". calculTrajMeanC is writen in C (and is therefor much faster).

affectIndiv used with calculTrajMean simulates one k-means step.

Examples

Run this code
#######################
### calculMean

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

### A cluster affectation
clust <- initializePartition(3,200,"randomAll")

### Computation of the cluster's centers
system.time(centers <- calculTrajMean(traj,clust))
system.time(centers <- calculTrajMeanC(traj,clust))

Run the code above in your browser using DataLab