poLCA.reorder {poLCA} | R Documentation |
A helper function to simplify the reordering of latent classes returned by poLCA
.
poLCA.reorder(probs, o.new)
probs |
a list of class-conditional response probabilities previously used as start values to estimate a particular latent class model using poLCA . |
o.new |
a vector of length equal to the number of latent classes in probs , giving the desired reordering of the latent classes. |
Because the latent classes outputted by poLCA
are unordered categories, the numerical order of the classes is arbitrary, and is determined solely by the initial values of the EM algorithm. If probs.start
is set to NULL
(the default) when calling poLCA
, then the function generates the starting values randomly in each run, typically rearranging the latent class labels. The poLCA.reorder
function is a convenient way to manually adjust the order of the latent classes, by changing the order of the probs.start
. Refitting the latent class model using these reordered start values will produce a model having the desired category labels.
The function returns a list of matrices containing the rearranged (by row) class-conditional response probabilities.
## ## Create sample data and arrange latent classes in order of increasing size. ## sim <- poLCA.simdata(N=5000,nclass=3,ndv=5,classdist=c(0.15,0.30,0.55)) f <- cbind(Y1,Y2,Y3,Y4,Y5)~1 lc <- poLCA(f,sim$dat,nclass=3) probs.start.new <- poLCA.reorder(lc$probs.start,order(lc$P)) lc2 <- poLCA(f,sim$dat,nclass=3,probs.start=probs.start.new) ## ## Using the "cheating" sample data set, make the larger ## non-cheater class the first ("reference") class in a ## latent class regression model. The coefficient on GPA ## now maintains a consistent interpretation. ## data(cheating) f2 <- cbind(LIEEXAM,LIEPAPER,FRAUD,COPYEXAM)~GPA lc.ch <- poLCA(f2,cheating,nclass=2,verbose=FALSE) probs.start.new <- poLCA.reorder(lc.ch$probs.start,order(lc.ch$P,decreasing=TRUE)) lc.ch <- poLCA(f2,cheating,nclass=2,probs.start=probs.start.new)