I'm a newbie to R with a question about poLCA. When you run a latent class analysis in poLCA it generates a value for each respondent giving their posterior probability of 'belonging' to each latent class. These are stored as a matrix in the element 'posterior'.
I would like to create a dataframe which contains each respondent's unique ID number (which is stored as a variable in the dataframe used for poLCA) and their matched posterior probability from the 'posterior' matrix. I would then like to write this dataframe to a csv file for use in another program.
I know this is possible, but I just can't seem to get it right (blame my incompetence with R). Any help would be very warmly appreciated.
Best wishes. Robert de Vries
EDIT - EXAMPLE
#Loading the poLCA package
library(poLCA)
#The ID variable
serial <-sample(1:1000,100,replace=F)
#The variables used in the latent class model
V1 <- sample(1:2,100,replace=T)
V2 <- sample(1:2,100,replace=T)
V3 <- sample(1:2,100,replace=T)
V4 <- sample(1:2,100,replace=T)
#the data given to the lca
lcadata <- data.frame(serial,V1,V2,V3,V4)
#the lca formula
f <- cbind(V1,V2,V3,V4) ~1
#A 2 class LCA model in poLCA
lca2 <- poLCA(f,lcadata,nclass=3,maxiter=5000,nrep=10)