-
Dear all, I am looking at custers regarding weight loss trajectories. With latrend I got very nice plots of different clusters but when I try to look at which patient is assigned to which custer I noticed that on the different timepoints patients can be assigned to a different cluster compared to another timepoint (and looking at the same patient). I used the lcMethodGCKM. This is my code: GCKMmethod <- lcMethodGCKM(formula = weight_loss~ (follow_up_numeric| ID)) cluster_new <- trajectoryAssignments(bestGCKMmodel_best) I would have thought that patients would stay in one cluster? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, The You cannot assign this vector to your The correct way is to first construct a data frame of the subject cluster assignments, and then to merge that with your original dataset. This ensures the assignments are repeated per subject as required. Try: subjectClusterTable = data.frame(ID = ids(bestGCKMmodel_best), cluster_new= trajectoryAssignments(bestGCKMmodel_best))
head(subjectClusterTable )
posthocAnalysisData = merge(data, subjectClusterTable, by = 'ID')
head(posthocAnalysisData) This should give you what you are looking for :) |
Beta Was this translation helpful? Give feedback.
Hi,
The
trajectoryAssignments
function returns a vector with a single cluster assignment per patient. Subjects are not modeled to change cluster over time.You cannot assign this vector to your
data
data frame directly because the data contains repeated measurements per subject. To confirm this, you'll see thatlength(cluster_new)
is way smaller thannrow(data)
. Unfortunately R does not warn about this mismatching assignment, and happily repeats the vector to match the number of rows, hence the different values over time.The correct way is to first construct a data frame of the subject cluster assignments, and then to merge that with your original dataset. This ensures the assignments ar…