[R] Calling str() on mlogit object gives warnings

Jennifer Lyon jennifer.s.lyon at gmail.com
Wed Nov 2 01:35:07 CET 2011


Hi:

When I call str() on an mlogit object, I seem to get warnings. This
code is from an example provided in the mlogit documentation:

library(mlogit)
data("Train", package="mlogit")
tr<-mlogit.data(Train, shape="wide", choice="choice", varying=4:11,
sep="", alt.levels=c(1,2), id="id")
ml.train<-mlogit(choice~price+time+change+comfort| -1, tr)

str(ml.train)
List of 12
 $ coefficients : atomic [1:4] -0.00148 -0.02868 -0.32634 -0.94573
  ..- attr(*, "fixed")= Named logi [1:4] FALSE FALSE FALSE FALSE
  .. ..- attr(*, "names")= chr [1:4] "price" "time" "change" "comfort"
 $ logLik       :Class 'logLik' : -1724 (df=4)
 $ gradient     : Named num [1:4] -3.94e-09 -1.40e-11 6.15e-13 -6.11e-13
  ..- attr(*, "names")= chr [1:4] "price" "time" "change" "comfort"
 $ gradi        : num [1:2929, 1:4] -136 -281 -309 -139 448 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:2929] "1.1" "2.1" "3.1" "4.1" ...
  .. ..$ : chr [1:4] "price" "time" "change" "comfort"
 $ hessian      : num [1:4, 1:4] -2.75e+08 2.48e+06 5.10e+04 9.95e+04
2.48e+06 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:4] "price" "time" "change" "comfort"
  .. ..$ : chr [1:4] "price" "time" "change" "comfort"
 $ est.stat     :List of 5
  ..$ elaps.time:Class 'proc_time'  Named num [1:5] 0.12 0 0.12 0 0
  .. .. ..- attr(*, "names")= chr [1:5] "user.self" "sys.self"
"elapsed" "user.child" ...
  ..$ nb.iter   : num 5
  ..$ eps       : num [1, 1] 0.00014
  ..$ method    : chr "nr"
  ..$ code      : num 2
  ..- attr(*, "class")= chr "est.stat"
 $ fitted.values: num [1:2929, 1:2] 0.915 0.649 0.807 0.174 0.56 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:2] "X1" "X2"
 $ residuals    : num [1:2929, 1:2] 0.0851 0.3512 0.1932 -0.1737 -0.5602 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:2929] "1.1" "2.1" "3.1" "4.1" ...
  .. ..$ : chr [1:2] "X1" "X2"
 $ model        :Classes ‘mlogit.data’ and 'data.frame':	5858 obs. of
5 variables:
  ..$ choice : logi [1:5858] TRUE FALSE TRUE FALSE TRUE FALSE ...
  ..$ price  : int [1:5858] 2400 4000 2400 3200 2400 4000 4000 3200
2400 3200 ...
  ..$ time   : int [1:5858] 150 150 150 130 115 115 130 150 150 150 ...
  ..$ change : int [1:5858] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ comfort: int [1:5858] 1 1 1 1 1 0 1 0 1 0 ...
  ..- attr(*, "terms")=Classes 'terms', 'formula' length 3 choice ~
price + time + change + comfort + -1
  .. .. ..- attr(*, "variables")= language list(choice, price, time,
change, comfort)
  .. .. ..- attr(*, "factors")= int [1:5, 1:4] 0 1 0 0 0 0 0 1 0 0 ...
  .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. ..$ : chr [1:5] "choice" "price" "time" "change" ...
  .. .. .. .. ..$ : chr [1:4] "price" "time" "change" "comfort"
  .. .. ..- attr(*, "term.labels")= chr [1:4] "price" "time" "change" "comfort"
  .. .. ..- attr(*, "order")= int [1:4] 1 1 1 1
  .. .. ..- attr(*, "intercept")= int 0
  .. .. ..- attr(*, "response")= int 1
  .. .. ..- attr(*, ".Environment")=<environment: 0x187ef68>
  .. .. ..- attr(*, "predvars")= language list(choice, price, time,
change, comfort)
  .. .. ..- attr(*, "dataClasses")= Named chr [1:5] "logical"
"numeric" "numeric" "numeric" ...
  .. .. .. ..- attr(*, "names")= chr [1:5] "choice" "price" "time" "change" ...
  ..- attr(*, "index")='data.frame':	5858 obs. of  3 variables:
  .. ..$ chid: Factor w/ 2929 levels "1","2","3","4",..: 1 1 2 2 3 3 4 4 5 5 ...
  .. ..$ alt : Factor w/ 2 levels "1","2": 1 2 1 2 1 2 1 2 1 2 ...
  .. ..$ id  : Factor w/ 235 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ freq         : 'table' int [1:2(1d)] 1474 1455
  ..- attr(*, "dimnames")=List of 1
  .. ..$ : chr [1:2] "1" "2"
 $ formula      :Classes 'mFormula', 'Formula', 'formula' length 3
choice ~ price + time + change + comfort | -1
  .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
  .. ..- attr(*, "lhs")=List of 1
  .. .. ..$ : symbol choice
  .. ..- attr(*, "rhs")=List of 2
  .. .. ..$ : language price + time + change + comfort
  .. .. ..$ : language -1
 $ call         : language mlogit(formula = choice ~ price + time +
change + comfort | -1,      data = tr, method = "nr", print.level = 0)
 - attr(*, "class")= chr "mlogit"
Warning messages:
1: In if (is.na(le)) " __no length(.)__ " else if (give.length) { :
  the condition has length > 1 and only the first element will be used
2: In if (le > 0) P0("[1:", paste(le), "]") else "(0)" :
  the condition has length > 1 and only the first element will be used


I am surprised that I'm getting warnings. Am I doing something wrong
here, or is the mlogit object misformed in some way, or is there a
problem with str()?

I don't think the str() is specific to mlogit, since if I do
utils:::str.default(ml.train)

I get the same warnings.

Thanks.

Jen

 sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C                 LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] mlogit_0.2-1     maxLik_1.0-2     miscTools_0.6-10 lmtest_0.9-29
[5] zoo_1.7-5        statmod_1.4.13   Formula_1.0-1

loaded via a namespace (and not attached):
[1] grid_2.14.0    lattice_0.20-0 sandwich_2.2-8 tools_2.14.0



More information about the R-help mailing list