Title: | Support Functions used by the LIBDR LCMM Analysis |
---|---|
Description: | This package provides support functions frequently used by Constantine et al. for their paper, "Large-scale clustering of longitudinal faecal calprotectin and C-reactive protein profiles in inflammatory bowel disease". These functions are primarily used to manipulate data and visualise findings. |
Authors: | Nathan Constantine-Cooke [aut, cre] , Catalina Vallejos [aut] |
Maintainer: | Nathan Constantine-Cooke <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.0 |
Built: | 2024-12-13 16:30:57 UTC |
Source: | https://github.com/VallejosGroup/Lothian-IBDR |
Build DT::datatable objects from matrix of fit statistics
buildDT(hlme.metrics)
buildDT(hlme.metrics)
hlme.metrics |
A data frame or matrix of model fit metrics for different number of assumed clusters (G) |
Create co-clustering matrix for FCAL and CRP models
compareClustering(G, models.fcal, models.crp, cutoff = FALSE, threshold = 0.8)
compareClustering(G, models.fcal, models.crp, cutoff = FALSE, threshold = 0.8)
G |
Number of clusters assumed by both models |
models.fcal |
List holding all |
models.crp |
List holding all |
cutoff |
Logical, should only subjects assigned posterior cluster membership probabilities above a given threshold for both models be included? |
threshold |
Numeric. The posterior probability of cluster membership
cutoff required for a subject to be included in the plot. Only used if
|
Produce descriptive analysis of categorical variables
describe_cat(vars, data)
describe_cat(vars, data)
vars |
Character vector giving the names of categorical variables |
data |
Data frame (or tibble) holding the data of interest |
Produce a heatmap of LCMM cluster assignments across multiple lcmm::hlme fit objects
lcmmHeatmap( models, cores = NULL, png = TRUE, pdf = FALSE, file.name = "heatmap", return.data = FALSE )
lcmmHeatmap( models, cores = NULL, png = TRUE, pdf = FALSE, file.name = "heatmap", return.data = FALSE )
models |
list containing objects generated by
|
cores |
Numeric. Number of CPU cores to use. Defaults to maximum available. |
png |
Logical. If |
pdf |
Logical. If |
file.name |
Character. File name (without extension) for saved heatmap
files. Defaults to |
return.data |
Logical. If |
Produce table of model fit metrics (AIC, BIC, Log-likelihood) for LCMMs
makeMetrics(Gs, models)
makeMetrics(Gs, models)
Gs |
Vector indicating which values of G should metrics be calculated for. |
models |
List containing LCMM model fits |
Forest plot of multinomial logistic regression model
mlrPlot(dat, var, class = "class_combined", prob = "probmax", minprob = 0.5)
mlrPlot(dat, var, class = "class_combined", prob = "probmax", minprob = 0.5)
dat |
Data frame holding covariate and cluster assignment data. |
var |
Character. The name of the covariate(s) of interest. If given as a character vector then a multivariate model is fitted using the specified covariates. |
class |
Character. The name of the class assignment variable. Assumed
to be |
prob |
Character. The name of the variable which gives posterior
probabilities for cluster membership. Assumed to be |
minprob |
Numeric. The minimum posterior probability for cluster membership required for a subject to be included in the analysis. Assumed to be 0.5 if not manually specified |
Percentage bar plots for categorical data
plotCat(dat, var, class = "class_combined")
plotCat(dat, var, class = "class_combined")
dat |
Data frame holding categorical and cluster assignment data. |
var |
Character. The name of the categorical variable of interest. |
class |
Character. The name of the class assignment variable. Assumed
to be |
A patchwork
object
Rank clusters by the area under their mean trajectories
rankCumulative(model, tmax = 7, var.time = "calpro_time")
rankCumulative(model, tmax = 7, var.time = "calpro_time")
model |
An |
tmax |
Numeric. Maximum observation period. Defaults to 10 |
var.time |
Character. Name of variable used for time. Either "calpro_time" or "crp_time" Also used to determine if the LCMM has been fitted for FCAL or CRP. |
A data frame with columns for the original cluster number (Original), the new rank (New), and the area calculated via the trapezoidal rule (Area).
Relabel class labels in an alluvial data frame to ensure class labels are consistent with the class labels used models assuming fewer classes
reLabel(new.G, alluvial.df)
reLabel(new.G, alluvial.df)
new.G |
The number of classes assumed by the LCMM which is now subject to class relabelling. |
alluvial.df |
Data frame containing class assignments for subjects for differing G |
Spaghetti plots of each class
spaghettiPlot( data, models, G, log = TRUE, indi = FALSE, multi = TRUE, tmax = 10, ylim = NULL, column = FALSE, pprob.cutoff = NA, sizes = FALSE, mapping = NULL, save = FALSE, knots = FALSE, knot.type = "quantiles", n.knots = 3, grbf = FALSE, l = 1, color = NULL, clusters = FALSE, var.time = "calpro_time" )
spaghettiPlot( data, models, G, log = TRUE, indi = FALSE, multi = TRUE, tmax = 10, ylim = NULL, column = FALSE, pprob.cutoff = NA, sizes = FALSE, mapping = NULL, save = FALSE, knots = FALSE, knot.type = "quantiles", n.knots = 3, grbf = FALSE, l = 1, color = NULL, clusters = FALSE, var.time = "calpro_time" )
data |
Data frame used to fit the LCMM(s). |
models |
A list containing |
G |
Numeric. How many classes does the model assume? |
log |
Logical. Should plots be on log scale? Defaults to TRUE. |
indi |
Logical. Should separate plots for each class be generated? Defaults to FALSE. |
multi |
Logical. Should sub-plots for each class be plotted alongside each other? Defaults to TRUE. |
tmax |
Numeric. Maximum observation period. Defaults to 10 |
ylim |
Character. What should the y-axis of the plots be scaled to fit? Either NULL (default), "data", "pred", or "conf". The default uses pre-determined values for FCAL and CRP |
column |
Logical. Should all sub-plots be in a single column? Defaults to FALSE (two columns) |
pprob.cutoff |
Posterior probability cut-off for subjects to be included as trajectories |
sizes |
Logical. Should class sizes be given as plot titles? |
mapping |
Numeric vector Giving the new ordering of sub-plots. One must take into account plots are generated by column - not row. If not specified then the default class numbers will be used. |
save |
Logical. Should sub-figure labels be generated? |
knots |
Logical. If TRUE, knot locations will be plotted as vertical lines. Defaults to FALSE |
knot.type |
Character. How are knots placed? Either "quantiles"
(default) or "equal" (equally spaced). Not used if |
n.knots |
Numeric integer giving the number of knots used. Defaults to
3. Not used if |
grbf |
Logical. If |
l |
Numeric. Length scale constant for the Gaussian radial basis
functions (not used if |
color |
Character. Name of variable in |
clusters |
Logical. Are clusters given via a "class" column in
|
var.time |
Character. Name of variable used for time. Either "calpro_time" or "crp_time" Also used to determine if the LCMM has been fitted for FCAL or CRP. |