data-edu / tidyLPA

Easily carry out Latent Profile Analysis (LPA) using open-source or commercial software
https://data-edu.github.io/tidyLPA/
Other
55 stars 15 forks source link

LPA with Long Data #179

Open benjaminwnelson opened 3 years ago

benjaminwnelson commented 3 years ago

This is a fantastic package! Is there a way to export LPA profile classes, while keeping subject ids for long data?

spacecadet333 commented 11 months ago

This helped me. It looks like the order of your data frame and the list output of profiles remain in the same order. If you add a sequential ID column, you can join after LPA is conducted:

#add sequential number column to data frame
data<- data
numr_rows= nrow(data)
data$seqID<- seq.int(numr_rows)

#run LPA
LPA<- data %>%
  select(c(X1, X2, X3)) %>%
  single_imputation() %>%
  estimate_profiles(3) 

#add sequential ID to Model classification and convert to data frame
data.with.class<- LPA$model_1_class_3$model$classification%>%as.data.frame()
data.with.class$seqID<- seq.int(nrow(data.with.class)) 

#use left_join function to join based on sequential ID
data.join<- left_join(data, data.with.class, by= "seqID")