Re: [R] mlogit error

From: Peter Ehlers <ehlers_at_ucalgary.ca>
Date: Mon, 28 Feb 2011 14:52:39 -0800

On 2011-02-28 12:54, gmacfarlane wrote:
> I actually have exactly the same question as Maha, and I wish that Z had
> answered the question instead of providing a lesson in streamlined code
> (valuable, but not helpful).

I think that Achim answered as best one could, given that Maha neglected, as you also neglect, to provide *reproducible* code. It's considerable easier to diagnose problems when one is able to run the problematic code. I'm pretty sure that if you provide a minimal, reproducible example (see the posting guide), someone will figure out where your problem originates.

Peter Ehlers

>
> It seems as though mlogit.data repopulates the row.names field, and that
> this is where the duplication comes in.
>
> hbwtrips<-read.csv("workdata.csv",header=TRUE, sep=",",
> dec=".",row.names="ROWS")
>
> This works fine, and produces a table like the one below (but bigger). I can
> run anything I want (descriptive statistics, aov, linear regression) from
> the data.frame (so I know there are no duplicate row names in the source
> table).
>
> HHID PERID CASE ALTNUM NUMALTS CHOSEN IVTT OVTT TVTT COST DIST
> WKZONE HMZONE RSPOPDEN RSEMPDEN WKPOPDEN
> 1 2 1 1 1 5 1 13.38 2.00 15.38 70.63 7.69
> 664 726 15.52 9.96 37.26
> 2 2 1 1 2 5 0 18.38 2.00 20.38 35.32 7.69
> 664 726 15.52 9.96 37.26
> 3 2 1 1 3 5 0 20.38 2.00 22.38 20.18 7.69
> 664 726 15.52 9.96 37.26
> 4 2 1 1 4 5 0 25.90 15.20 41.10 115.64 7.69
> 664 726 15.52 9.96 37.26
> 5 2 1 1 5 5 0 40.50 2.00 42.50 0.00 7.69
> 664 726 15.52 9.96 37.26
> 6 3 1 2 1 5 0 29.92 10.00 39.92 390.81 11.62
> 738 9 35.81 53.33 32.91
> 7 3 1 2 2 5 0 34.92 10.00 44.92 195.40 11.62
> 738 9 35.81 53.33 32.91
> 8 3 1 2 3 5 0 21.92 10.00 31.92 97.97 11.62
> 738 9 35.81 53.33 32.91
> 9 3 1 2 4 5 1 22.96 14.20 37.16 185.00 11.62
> 738 9 35.81 53.33 32.91
> 10 3 1 2 5 5 0 58.95 10.00 68.95 0.00 11.62
> 738 9 35.81 53.33 32.91
> 11 5 1 3 1 4 1 8.60 6.00 14.60 37.76 4.10
> 696 667 85.35 105.93 29.45
> 12 5 1 3 2 4 0 13.60 6.00 19.60 18.88 4.10
> 696 667 85.35 105.93 29.45
> 13 5 1 3 3 4 0 15.60 6.00 21.60 10.79 4.10
> 696 667 85.35 105.93 29.45
> 14 5 1 3 4 4 0 16.87 21.40 38.27 105.00 4.10
> 696 667 85.35 105.93 29.45
> 15 6 1 4 1 4 0 30.60 8.50 39.10 417.32 14.58
> 665 8 32.31 25.61 0.00
> 16 6 1 4 2 4 0 35.70 8.50 44.20 208.66 14.58
> 665 8 32.31 25.61 0.00
> 17 6 1 4 3 4 0 22.70 8.50 31.20 105.54 14.58
> 665 8 32.31 25.61 0.00
> 18 6 1 4 4 4 1 24.27 9.00 33.27 193.49 14.58
> 665 8 32.31 25.61 0.00
> 19 8 2 5 2 4 1 23.04 3.00 26.04 29.95 6.29
> 679 704 33.04 106.52 89.24
> 20 8 2 5 3 4 0 25.04 3.00 28.04 17.12 6.29
> 679 704 33.04 106.52 89.24
> 21 8 2 5 4 4 0 25.04 23.50 48.54 100.00 6.29
> 679 704 33.04 106.52 89.24
> 22 8 2 5 5 4 0 34.35 3.00 37.35 0.00 6.29
> 679 704 33.04 106.52 89.24
> 23 8 3 6 2 5 0 11.14 3.50 14.64 14.00 2.83
> 679 665 33.04 106.52 32.31
> 24 8 3 6 3 5 0 13.14 3.50 16.64 8.00 2.83
> 679 665 33.04 106.52 32.31
> 25 8 3 6 4 5 1 3.95 16.24 20.19 100.00 2.83
> 679 665 33.04 106.52 32.31
> 26 8 3 6 5 5 0 16.05 3.50 19.55 0.00 2.83
> 679 665 33.04 106.52 32.31
> 27 8 3 6 6 5 0 0.00 0.00 60.10 0.00 2.83
> 679 665 33.04 106.52 32.31
> 28 12 2 7 1 6 1 8.80 3.00 11.80 31.65 3.44
> 667 682 29.45 22.42 6.57
> 29 12 2 7 2 6 0 13.80 3.00 16.80 15.83 3.44
> 667 682 29.45 22.42 6.57
> 30 12 2 7 3 6 0 15.80 3.00 18.80 9.04 3.44
> 667 682 29.45 22.42 6.57
>
>
> I then run
>
>> hbwmode<-mlogit.data(hbwtrips,varying=c(8:11),shape="long",
>> choice="CHOSEN", alt.var="ALTNUM", row.names="ROWS")
>
> which returns
>
> Error in `row.names<-.data.frame`(`*tmp*`, value = c("1.1", "1.2", "1.3", :
> duplicate 'row.names' are not allowed
> In addition: Warning message:
> non-unique values when setting 'row.names': 1.1, 10.1, 10.4, 100.4,
> 1000.2, 1001.1, 1001.3, 1002.2, 1002.3, 1003.4, 1004.1,
> 1004.2, 1005.1, 1005.3, 1007.2, 1008.3, 1008.4, 1009.1,
> 1009.2, 1009.3, 101.1, 1010.4, 1011.1, 1012.2, 1013.3,
> 1013.4, 1015.1, 1016.2, 1018.3, 1018.4, 1019.1, 1019.2,
> 102.1, 102.2, 102.3, 1020.3, 1020.4, 1021.1, 1022.2, 1022.3,
> 1023.4, 1024.1, 1024.2, 1025.3, 1025.4, 1026.5, 1027.1,
> 1027.2, 1028.3, 1029.1, 1029.4, 103.2, 103.3, 1030.2,
> 1030.3, 1031.1, 1031.4, 1032.2, 1032.3, 1033.1, 1033.2,
> 1034.3, 1035.1, 1035.2, 1036.1, 1036.3, 1037.2, 1037.3,
> 1038.1, 1 [... truncated]
>
> Did you ever find a real answer, Maha?
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 28 Feb 2011 - 22:57:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Feb 2011 - 23:20:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive