Learn R Programming

akmedoids (version 0.1.5)

statPrint: Descriptive (Change) statistics and plots

Description

This function perform two tasks: (i) it generate the descriptive and change statistics of groups, particularly suited for the outputs form the akmedoids.clust function, and (ii) generates the plots of the groups (performances).

Usage

statPrint(
  clustr,
  traj,
  id_field = TRUE,
  reference = 1,
  N.quant = 4,
  type = "lines",
  y.scaling = "fixed"
)

Arguments

clustr

[vector (charater)] A vector of cluster membership (labels). For instance, the result extracted from the akmedoids.clust function.

traj

[matrix (numeric)]: corresponding longitudinal data used to generate clustr (with rows corresponding to each label of clustr). For example, the first label of clustr is the group label of the first row of traj matrix, and so on.

id_field

[numeric or character] Whether the first column of the traj is a unique (id) field. Default: FALSE. If TRUE the function recognises the second column as the first time step.

reference

[numeric] Specifying the reference line from which the direction of each group is measured. Options are: 1: slope of mean trajectory, 2: slope of medoid trajectory, 3: slope of a horizontal line (i.e. slope = 0). Default: 1.

N.quant

[numeric] Number of equal intervals (quantiles) to create between the reference line (R) and the medoids (M) of the most-diverging groups of both sides of (R). Default is 4 - meaning quartile subdivisions on each side of (R). In this scenario, the function returns the quartile in which the medoid of each group falls. This result can be used to further categorise the groups into 'classes'. For example, groups that fall within the 1st quartile may be classified as 'Stable' groups (Adepeju et al. 2019).

type

[character] plot type. Available options are: "lines" and "stacked".

y.scaling

[character] works only if type="lines". y.scaling set the vertical scales of the cluster panels. Options are: "fixed": uses uniform scale for all panels, "free": uses variable scales for panels.

Value

A plot showing group membership or sizes (proportion) and statistics.

Details

Generates the descriptive and change statistics of the trajectory groupings. Given a vector of group membership (labels) and the corresponding data matrix (or data.frame) indexed in the same order, this function generates all the descriptive and change statistics of all the groups. The function can generate a line and an area stacked plot drawing from the functionalities of the ggplot2 library. For a more customised visualisation, we recommend that users deploy ggplot2 directly (Wickham H. (2016)).

References

1. Adepeju, M. et al. (2019). Anchored k-medoids: A novel adaptation of k-means further refined to measure inequality in the exposure to crime across micro places (Submitted).

Wickham H. (2016). Elegant graphics for Data Analysis. Spring-Verlag New York (2016)

Examples

Run this code
# NOT RUN {
print(traj)
traj <- dataImputation(traj, id_field = TRUE, method = 1, replace_with = 1,
fill_zeros = FALSE)
print(traj)
traj <- props(traj, id_field = TRUE)
clustr <- akmedoids.clust(traj, id_field = TRUE, method = "linear", k = 5)
clustr <- as.vector(clustr$memberships)
print(statPrint(clustr, traj, id_field=TRUE, type="lines", y.scaling="fixed"))
print(statPrint(clustr, traj, id_field=TRUE, reference = 1, N.quant = 8, type="stacked"))
# }

Run the code above in your browser using DataLab