Greetings I'm a relatively new R user and I'm trying to build a latent class model. I've used the 'R Site Search' and it appears there's not much dialogue on these packages On mmlcr, I've gotten it working, but not sure if I'm using it correctly. On flexmix, I can only seem to get results for one class. I'm attaching my code below - if anyone is familiar with either of these packages, I'd really appreciate some assistance or direction. I'm also attaching a small sample dataset. Many thanks for your help! Scott Geller library(mmlcr) model2 = mmlcr(outer = ~ first_brand_HOLIDAY + perc_zone1 + perc_Group_nights + perc_num_asian + DaysBetweenStays + CROStays + DaysSinceLastStay + wghtmean_median_age_pop100 + perc_num_white + perc_num_hispanic + perc_CROStays + numMonthsActive + WEBStays + property_loyalty + perc_NoZone + ltgold1 + ltgold3 + rho + p_hat_PCR| gst_id, components = list(list(formula = nts ~ PCR_Dummy_class, class = "poislong")),data=Dataset, n.groups = 5, max.iter = 5000) libray(flexmix) m1<-flexmix(nts ~ first_brand_HOLIDAY+ perc_zone1+ perc_Group_nights+ perc_num_asian+ DaysBetweenStays+ CROStays+ DaysSinceLastStay+ wghtmean_median_age_pop100+ perc_num_white+ perc_num_hispanic+ perc_CROStays+ numMonthsActive+ WEBStays+ property_loyalty+ perc_NoZone+ rho+ PCR_Dummy_class+ ltgold1+ ltgold3+ p_hat_PCR, data = data, k = 2, model = FLXglm(family = "poisson")) rm1<-refit(m1) summary(rm1) Scott Geller Advanced Analytics, Decision Sciences Department, InterContinental Hotels Group 770-604-5149
R Package: mmlcr and/or flexmix
2 messages · Geller, Scott (IHG), Friedrich Leisch
On Tue, 12 Apr 2005 00:44:17 -0400, Geller, Scott (IHG) (GS() wrote:
> Greetings
> I'm a relatively new R user and I'm trying to build a latent class model.
> I've used the 'R Site Search' and it appears there's not much dialogue on
> these packages
[...]
> libray(flexmix)
> m1<-flexmix(nts ~ first_brand_HOLIDAY+ perc_zone1+ perc_Group_nights+
> perc_num_asian+ DaysBetweenStays+ CROStays+ DaysSinceLastStay+
> wghtmean_median_age_pop100+ perc_num_white+ perc_num_hispanic+
> perc_CROStays+ numMonthsActive+ WEBStays+ property_loyalty+ perc_NoZone+
> rho+ PCR_Dummy_class+ ltgold1+ ltgold3+ p_hat_PCR, data = data, k = 2, model
> = FLXglm(family = "poisson"))
> rm1<-refit(m1)
> summary(rm1)
[ Scott sent me in private a subset of the data ]
For me this seems to work fine:
R> set.seed(123)
R> m1<-flexmix(nts ~ first_brand_HOLIDAY+ perc_zone1+ perc_Group_nights+
+ perc_num_asian+ DaysBetweenStays+ CROStays+ DaysSinceLastStay+
+ wghtmean_median_age_pop100+ perc_num_white+ perc_num_hispanic+
+ perc_CROStays+ numMonthsActive+ WEBStays+ property_loyalty+ perc_NoZone+
+ rho+ PCR_Dummy_class+ ltgold1+ ltgold3+ p_hat_PCR, data = data, k = 2, model
+ = FLXglm(family = "poisson"))
R> m1
Call:
flexmix(formula = nts ~ first_brand_HOLIDAY + perc_zone1 + perc_Group_nights +
perc_num_asian + DaysBetweenStays + CROStays + DaysSinceLastStay +
wghtmean_median_age_pop100 + perc_num_white + perc_num_hispanic +
perc_CROStays + numMonthsActive + WEBStays + property_loyalty +
perc_NoZone + rho + PCR_Dummy_class + ltgold1 + ltgold3 +
p_hat_PCR, data = data, k = 2, model = FLXglm(family = "poisson"))
Cluster sizes:
1 2
93 906
convergence after 49 iterations
R> rm1<-refit(m1)
R>
R> summary(rm1)
Call:
refit(m1)
Component 1 :
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.0108e+00 6.4399e-01 1.5696 0.1164971
first_brand_HOLIDAY -9.3504e-01 4.6151e-01 -2.0261 0.0427594
perc_zone1 1.3936e-01 7.4383e-01 0.1874 0.8513845
...
-------------
Component 2 :
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.00799714 0.39133294 2.5758 0.01000
first_brand_HOLIDAY -0.07928984 0.15935997 -0.4976 0.61880
perc_zone1 0.01208886 0.42596711 0.0284 0.97736
...
So I cannot reproduce the problem. Is maybo one cluster in your
solution empty? The EM algorithm can end up in a local optimum with
one cluster empty ... either run flexmix() several times by hand or
use stepFlexmix() to do so automatically.
HTH,
-------------------------------------------------------------------
Friedrich Leisch
Institut f?r Statistik Tel: (+43 1) 58801 10715
Technische Universit?t Wien Fax: (+43 1) 58801 10798
Wiedner Hauptstra?e 8-10/1071
A-1040 Wien, Austria http://www.ci.tuwien.ac.at/~leisch