Ghosh, Gaurav
2011-Mar-13 13:44 UTC
[R] Problem implementing 'waldtest' when using 'mlogit' package
Hi all, I have been working through the examples in one of the vignettes associated with the 'mlogit' package, 'Kenneth Train's exercises using the mlogit package for R.' In spite of using the code unchanged, as well as the data used in the examples, I have been unable to run a Wald test to test two models. Specifically, I have run the following command, where mc and mi2 are fitted models: waldtest(mc,mi2) I think that the test is taken from the 'lmtest' package. I get the following error message: Error in terms.default(x) : no terms component The two fitted models are: mc <- mlogit(depvar ~ ic + oc, H, reflevel="hp") mi2 <- mlogit(depvar ~ oc + ic | income, H, reflevel="hp") I would be grateful for tips on how to proceed. Thanks in advance. Best regards, Gaurav S. Ghosh, Ph.D., E.ON Energy Research Centre, Room 01.32, RWTH Aachen, Mathieustraße 6, D-52074 Aachen, Germany [[alternative HTML version deleted]]
Achim Zeileis
2011-Mar-13 14:14 UTC
[R] Problem implementing 'waldtest' when using 'mlogit' package
On Sun, 13 Mar 2011, Ghosh, Gaurav wrote:> Hi all, > > I have been working through the examples in one of the vignettes > associated with the 'mlogit' package, 'Kenneth Train's exercises using > the mlogit package for R.' In spite of using the code unchanged, as well > as the data used in the examples, I have been unable to run a Wald test > to test two models. > > Specifically, I have run the following command, where mc and mi2 are > fitted models: waldtest(mc,mi2) > > The two fitted models are: > mc <- mlogit(depvar ~ ic + oc, H, reflevel="hp") > mi2 <- mlogit(depvar ~ oc + ic | income, H, reflevel="hp")That's still not the complete code for replicating the problem...please do provide reproducible examples as the posting guide asks you! Using R 2.12.2 and mlogit 0.2-1, I can replicate the results from the vignette using library("mlogit") data("Heating", package = "mlogit") H <- mlogit.data(Heating, shape = "wide", choice = "depvar", varying = 3:12) mc <- mlogit(depvar ~ ic + oc, H, reflevel = "hp") mi2 <- mlogit(depvar ~ oc + ic | income, H, reflevel = "hp") waldtest(mc, mi2)> I think that the test is taken from the 'lmtest' package.The generic is from "lmtest" but the method is provided by "mlogit".> I get the following error message: > Error in terms.default(x) : no terms componentThe default method should not be called, there is a terms() method for "mlogit" objects. Maybe you're using an old version of mlogit? Z> > I would be grateful for tips on how to proceed. Thanks in advance. > > Best regards, > Gaurav S. Ghosh, Ph.D., > E.ON Energy Research Centre, Room 01.32, > RWTH Aachen, > Mathieustra?e 6, > D-52074 Aachen, Germany > > > > [[alternative HTML version deleted]] > >
Mark Difford
2011-Mar-13 14:41 UTC
[R] Problem implementing 'waldtest' when using 'mlogit' package
On Mar 13, 2011; 03:44pm Gaurav Ghosh wrote:>> I have been working through the examples in one of the vignettes >> associated with the 'mlogit' >> package, 'Kenneth Train's exercises using the mlogit package for R.' In >> spite of using the code >> unchanged, as well as the data used in the examples, I have been unable >> to run a Wald test to >> test two models.It strikes me that you may not have given the full facts. I have no problem with this (using a development version of R). Note that you need to make H first.> data("Heating", package = "mlogit") > H <- mlogit.data(Heating, shape = "wide", choice = "depvar",+ varying = c(3:12))> m <- mlogit(depvar ~ ic + oc | 0, H) > summary(m)> mc <- mlogit(depvar ~ ic + oc, H, reflevel="hp") > mi2 <- mlogit(depvar ~ oc + ic | income, H, reflevel="hp") > waldtest(mc,mi2)Wald test Model 1: depvar ~ ic + oc Model 2: depvar ~ oc + ic | income Res.Df Df Chisq Pr(>Chisq) 1 894 2 890 4 4.6456 0.3256 What does print(mc) and print(mi2) report? Mark.> sessionInfo()R version 2.13.0 Under development (unstable) (2010-10-14 r53299) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] grDevices datasets stats4 splines graphics utils stats methods base other attached packages: [1] mlogit_0.2-1 maxLik_1.0-0 miscTools_0.6-10 lmtest_0.9-27 zoo_1.6-4 [6] statmod_1.4.9 Formula_1.0-0 rms_3.3-0 Hmisc_3.8-3 modeltools_0.2-17 [11] mvtnorm_0.9-96 survival_2.36-5 loaded via a namespace (and not attached): [1] cluster_1.13.3 coin_1.0-18 colorspace_1.0-1 grid_2.13.0 lattice_0.19-17 [6] Matrix_0.999375-47 mboost_2.0-10 party_0.9-99991 sandwich_2.2-6 tools_2.13.0 -- View this message in context: http://r.789695.n4.nabble.com/Problem-implementing-waldtest-when-using-mlogit-package-tp3351904p3351984.html Sent from the R help mailing list archive at Nabble.com.