You are on page 1of 1

library(poLCA)

library(ggplot2)
library(reshape2)
data=read.csv("basket3.csv",header=TRUE,sep=",")
f <- cbind(CustomerEducation,CustomerGender,SMSBankingBit)~1
lca4 <- poLCA(f,data,nclass=3)
plot(lca4)
lcModelProbs <- melt(lca4$probs)
# Replicating the poLCA 3-D plot, without the 3-D:
zp1 <- ggplot(lcModelProbs,
aes(x = L1, y = value, fill = Var2))
zp1 <- zp1 + geom_bar(stat = "identity", position = "stack")
zp1 <- zp1 + facet_wrap(~ Var1)
print(zp1)
# Suggested alternative, as a possible improvement:
zp2 <- ggplot(lcModelProbs,
aes(x = Var1, y = value, fill = Var2))
zp2 <- zp2 + geom_bar(stat = "identity", position = "stack")
zp2 <- zp2 + facet_wrap(~ L1)
zp2 <- zp2 + scale_x_discrete("Class", expand = c(0, 0))
zp2 <- zp2 + scale_y_continuous("Proportion", expand = c(0, 0))
zp2 <- zp2 + scale_fill_discrete("Factor Level")
zp2 <- zp2 + theme_bw()
print(zp2)

lca4$predcell
data=lca4$predcell
datachis=(data$observed-data$expected)^2/data$expected
pvalue=1-pchisq(datachis,1)
pvalue=round(pvalue, digits=5)
kes=data$observe>data$expected
sig=pvalue<0.05
akhir=cbind(data,datachis,pvalue,sig,kes)
sort1.hsb2 <- akhir[order(sig) , ]

You might also like