[R] Error in `[[<-.data.frame`(`*tmp*`, alt.name, value = integer(0)) with mlogit

Rui Barradas ruipbarradas at sapo.pt
Fri Jul 28 14:33:08 CEST 2017


Hello,

There's a typo in your call to mlogit.data, it should be 
alt.var="nbChev", not alt.var="noChev".
Then the error is different. You should check the call arguments to see 
if they make sense.

Hope this helps,

Rui Barradas

Em 28-07-2017 13:14, sandoz at free.fr escreveu:
> I   re post my question with the csv problem fixed.
>
> Can someone explain the error below?
> sandoz
>
>> library(mlogit)
>> horse1.data<-read.csv("cte2.csv", header=TRUE, sep=";")
>> h1.dat<-mlogit.data(data=horse1.data,choice="win",chid.var="raceid",alt.var="noChev",shape="long")
> #mul1.model<-mlogit(win~cteD+cteTh|0|0,data=h1.dat)
> #summary(mul1.model)
>
> Error in `[[<-.data.frame`(`*tmp*`, alt.name, value = integer(0)) :
>    le tableau de remplacement a 0 lignes, le tableau remplacé en a 26
>
>> head(horse1.data,27)
>    raceid nbChev  cteD cteTh win
> 1       1      9  29.6  23.8  no
> 2       1      9   5.3   6.7  no
> 3       1      9  10.9  11.5  no
> 4       1      9   8.2   6.7 yes
> 5       1      9  17.8  18.2  no
> 6       1      9  26.0  30.0  no
> 7       1      9   4.4   5.7  no
> 8       1      9   4.9   6.0  no
> 9       1      9   4.5   6.9  no
> 10      2     17  32.1  48.3  no
> 11      2     17   8.8  24.5  no
> 12      2     17  36.7  18.3  no
> 13      2     17   6.7  11.8 yes
> 14      2     17  10.3  12.8  no
> 15      2     17  61.6  68.5  no
> 16      2     17   2.5   6.7  no
> 17      2     17  27.7  30.9  no
> 18      2     17   8.4  10.5  no
> 19      2     17  56.5  40.7  no
> 20      2     17  95.5  11.9  no
> 21      2     17  12.7   6.4  no
> 22      2     17  19.6  14.2  no
> 23      2     17 269.6  67.2  no
> 24      2     17 300.0  75.6  no
> 25      2     17 300.0 114.3  no
> 26      2     17  36.3  16.9  no
>
>> str(horse1.data)
> 'data.frame':	26 obs. of  5 variables:
>   $ raceid: int  1 1 1 1 1 1 1 1 1 2 ...
>   $ nbChev: int  9 9 9 9 9 9 9 9 9 17 ...
>   $ cteD  : num  29.6 5.3 10.9 8.2 17.8 26 4.4 4.9 4.5 32.1 ...
>   $ cteTh : num  23.8 6.7 11.5 6.7 18.2 30 5.7 6 6.9 48.3 ...
>   $ win   : Factor w/ 2 levels "no","yes": 1 1 1 2 1 1 1 1 1 1 ...
>
> below the cte2.csv url
> https://www.dropbox.com/s/wv7nq8tk9k87le5/cte2.csv?dl=0
>
>
> ----- Mail original -----
> De: "Rui Barradas" <ruipbarradas at sapo.pt>
> À: "peter dalgaard" <pdalgd at gmail.com>, "Jeff Newmiller" <jdnewmil at dcn.davis.ca.us>
> Cc: r-help at r-project.org
> Envoyé: Jeudi 27 Juillet 2017 22:39:58
> Objet: Re: [R] Error in `[[<-.data.frame`(`*tmp*`, alt.name, value = integer(0))  with mlogit
>
> Hello,
>
> Inline.
>
> Em 27-07-2017 20:36, peter dalgaard escreveu:
>>
>>> On 27 Jul 2017, at 18:03 , Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:
>>>
>>> Looks like you need to pay attention to how you read in your data.  In general, you should always execute one statement at a time until you know your script is working.  All the errors after the first one are unhelpful to you or us.
>>>
>>> If you actually pay attention to what is in your horse.data data frame after you have read it in, the columns did not get separated out. The "csv" in in read.csv stands for "comma", and your file appears to use semicolons. Read the help for read.csv using
>>>
>>> ?read.csv
>>>
>>> and use the sep=";" argument. You should always use the str() function to look at your data and make sure it looks reasonable before you start trying to give it to other functions to analyze.
>>
>> Or use read.csv2 which exists for that reason. (It may be "c" for comma, but in locales that use comma as the decimal point it is replaced by the semicolon, as you'll find out if you save an Excel file as CSV in, say, France. This is due to some idiotic decisions from early 1990s, but there you are...)
>
> Idiotic? In Portugal that is also true and it "allows" us to use the
> comma as a decimals marker, as you've said. I would use it, with or
> without someone else's decision.
>
> Rui Barradas
>
>>
>> -pd
>>
>>
>>> --
>>> Sent from my phone. Please excuse my brevity.
>>>
>>> On July 27, 2017 8:01:12 AM PDT, sandoz at free.fr wrote:
>>>> Hi,
>>>> Please  help about the error I am getting after the h1.dat<- line :
>>>> this line worked with much more independant variables and bigger data.
>>>> This time I want to work with just 2 variables cteD & cteTh.
>>>> What is wrong ?
>>>>
>>>>> setwd("C:/Rstudio/Trot")
>>>>> library(mlogit)
>>>>> horse1.data<-read.csv("cte2.csv")
>>>>>
>>>> h1.dat<-mlogit.data(data=horse1.data,choice="win",chid.var="raceid",alt.var="nbChev",shape="long")
>>>>
>>>> Error in `[[<-.data.frame`(`*tmp*`, alt.name, value = integer(0)) :
>>>> le tableau de remplacement a 0 lignes, le tableau remplacé en a 26
>>>>
>>>>
>>>>> mul1.model<-mlogit(win~cteD+cteTh|0|0,data=h1.dat)
>>>> Error in mlogit(win ~ cteD + cteTh | 0 | 0, data = h1.dat) :
>>>> object 'h1.dat' not found
>>>>
>>>>
>>>>> head(horse.data,27)
>>>>    raceid.nbChev.cteD.cteTh.win
>>>> 1              1;9;29.6;23.8;no
>>>> 2                1;9;5.3;6.7;no
>>>> 3              1;9;10.9;11.5;no
>>>> 4               1;9;8.2;6.7;yes
>>>> 5              1;9;17.8;18.2;no
>>>> 6                  1;9;26;30;no
>>>> 7                1;9;4.4;5.7;no
>>>> 8                  1;9;4.9;6;no
>>>> 9                1;9;4.5;6.9;no
>>>> 10            2;17;32.1;48.3;no
>>>> 11             2;17;8.8;24.5;no
>>>> 12            2;17;36.7;18.3;no
>>>> 13            2;17;6.7;11.8;yes
>>>> 14            2;17;10.3;12.8;no
>>>> 15            2;17;61.6;68.5;no
>>>> 16              2;17;2.5;6.7;no
>>>> 17            2;17;27.7;30.9;no
>>>> 18             2;17;8.4;10.5;no
>>>> 19            2;17;56.5;40.7;no
>>>> 20            2;17;95.5;11.9;no
>>>> 21             2;17;12.7;6.4;no
>>>> 22            2;17;19.6;14.2;no
>>>> 23           2;17;269.6;67.2;no
>>>> 24             2;17;300;75.6;no
>>>> 25            2;17;300;114.3;no
>>>> 26            2;17;36.3;16.9;no
>>>>
>>>> ______________________________________________
>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>> 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.
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>>
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



More information about the R-help mailing list