Giter Club home page Giter Club logo

longmixr's Introduction

longmixr

R-CMD-check

The goal of longmixr is to provide consensus clustering for longitudinal clustering performed with flexmix. It uses the approach from ConsensusClusterPlus but replaces the clustering of the longitudinal data with a flexmix model.

Installation

You can install longmixr from github with:

remotes::install_github("cellmapslab/longmixr")

If you want to render the vignette, use:

remotes::install_github("cellmapslab/longmixr", build_vignettes = TRUE, dependencies = TRUE)

Please note that for the vignette a lot more dependencies are installed.

Basic usage

You need a dataset with a column that identifies the subject, a column that denotes the time point of the measurement and variables that you want to model.

set.seed(5)
test_data <- data.frame(
  patient_id = rep(1:10, each = 4),
  visit = rep(1:4, 10),
  var_1 = c(rnorm(20, -1), rnorm(20, 3)) + rep(seq(from = 0, to = 1.5, length.out = 4), 10),
  var_2 = c(rnorm(20, 0.5, 1.5), rnorm(20, -2, 0.3)) + rep(seq(from = 1.5, to = 0, length.out = 4), 10)
)

In the following approach, the variables var_1 and var_2 each are modeled as dependent on a smooth function of time, taking the multiple measurements for each subject into account. The assumption is that var_1 and var_2 represent a multivariate outcome. The modeling is specified in the flexmix drivers and the flexmix_formula:

model_list <- list(flexmix::FLXMRmgcv(as.formula("var_1 ~ .")),
                   flexmix::FLXMRmgcv(as.formula("var_2 ~ .")))
clustering <- longitudinal_consensus_cluster(
  data = test_data,
  id_column = "patient_id",
  max_k = 2,
  reps = 3,
  model_list = model_list,
  flexmix_formula = as.formula("~s(visit, k = 4) | patient_id"))

The results of the clustering can be assessed via several plots. For every specified number of clusters, the consensus matrix and the resulting hierarchical clustering on this matrix is shown. Additionally, the consensus CDF and the delta Area plots give a measure which number of cluster is optimal. The tracking plot gives an overview how the observations are distributed across the different clusters for different numbers of specified clusters. The item (subject) consensus plot shows the average consensus of each subject with all other subjects that belong to one cluster. The cluster consensus plot depicts the average consensus between all members of each cluster.

The above mentioned plots are generated when calling the plot function:

plot(clustering)

Detailed explanation

For a detailed explanation how you can use longmixr to analyze your longitudinal data, check out the Example clustering analysis vignette.

Cross-sectional clustering

Additionally, this package provides a wrapper function around the ConsensusClusterPlus function to work with mixed continuous and categorical data (by using the Gower distance):

dc <- mtcars
# scale continuous variables
dc <- sapply(mtcars[, 1:7], scale)
# code factor variables
dc <- cbind(as.data.frame(dc),
            vs = as.factor(mtcars$vs),
            am = as.factor(mtcars$am),
            gear = as.factor(mtcars$gear),
            carb = as.factor(mtcars$carb))
cc <- crosssectional_consensus_cluster(
  data = dc,
  reps = 10,
  seed = 1
)

Copyright

The package is based on the code of ConsensusClusterPlus (version 1.52.0). For this code the copyright holders are Matt Wilkerson and Peter Waltman. For all subsequent changes the copyright holder is the Max Planck Institute of Psychiatry. The code is licensed under GPL v2.

longmixr's People

Contributors

jhagenberg avatar

Watchers

Gábor Csárdi avatar CRAN robot avatar  avatar

longmixr's Issues

Fitting terminated with step failure - check results carefully

Hello,

I'm trying to cluster the 445 individuals of the PsyCourse cohort according to their phenotype (all covariates where measured at 4 different visits). I don't have a single missing values. in my dataframe.

I tried to group the covariates by two different methods. First, I used the hetcor function from the polycor packages to check if there were groups of variables that were highly correlated together. I used those groups to make a clustering (reps = 300, max_k = 4). This worked perfectly.

Then, I tried to redo the clustering with semantic groups (separate depressive symptoms, mania symptoms, ...). When I tried to redo the clustering with the same options I get the error in the title for some permutations. Do you have any idea of what cause this?

> response_names <- c("group_1_1_resid", "group_2_1_resid", "group_3_1_resid",
+                     "group_4_1_resid", "group_5_1_resid")
> 
> list_models <- lapply(response_names, function(x) {
+   flexmix::FLXMRmgcv(as.formula(paste0(x, " ~ .")))
+ })
> set.seed(2378)
> cluster_model <- longitudinal_consensus_cluster(data = cluster_data_resid,
+                                                 id_column = "ID", max_k = 4,
+                                                 reps = 300, p_item = 0.8,
+                                                 model_list = list_models,
+                                                 flexmix_formula = as.formula("~s(visit, k = 4) | ID"),
+                                                 final_linkage = "ward.D2")
2 : *
3 : *
4 : *
2 : *
3 : *
4 : *Fitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefullyFitting terminated with step failure - check results carefully
2 : *
3 : *
4 : *
2 : *

Best Regard,

Pierre

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.