[R] Creation of mlogit models from text file

R. Michael Weylandt michael.weylandt at gmail.com
Mon Oct 17 22:57:40 CEST 2011


I'm not at all familiar with mlogit or Biogene so I can't really give
a definitive answer, but it seems that this would be a very dangerous
thing to try.

Looking at the mlogit manual, I see that, like most model objects in
R, mlogit has a variety of elements including many of those you
specifically seem to be avoiding: data, likelihood functions, etc. You
could perhaps make a trivial mlogit object and directly modify the
elements you mention, but then you'd want to check each of the
functions you run on your object to make sure they don't access the
unmodified list elements. A fair compromise is probably to run mlogit
on a small sample of your data (I suppose you are using this Biogene
program for speed reasons?) to create a "best-approximation object"
and then modify directly; that will at least reduce the chance of
something too bad happening.

I suppose this could be automated to save you a little trouble (just
create your own class whose methods consist of getting the mlogit
methods, deparsing them and making sure they don't look at an
unmodified element, and then passing to the mlogit method) but the
smarter path is probably to extract the code from those functions you
want to use for prediction and tweak them to use the object you read
in directly.

Someone may have already implemented a work around though if this is a
common problem.

Best of luck,

Michael

On Mon, Oct 17, 2011 at 12:01 PM, Bhargava Sana
<Bhargava.Sana at rsginc.com> wrote:
> Michael,
>
> Thanks for the quick response. I currently have a few models that have been estimated using Biogeme. I have attached a sample output file from the estimation.
>
> I am more concerned about creating a model object from scratch rather than the reading part. Let us just say if we have a list of variables, coefficients, and std errors, how can an R model object be created (so that it can be used for prediction on an R data frame)? I read in the mlogit documentation that a model is created using an estimation dataset and formula. I was wondering if there have been previous attempts to setup a model object without estimating it in R just based on some character variables.
>
> Bhargava
>
> -----Original Message-----
> From: R. Michael Weylandt [mailto:michael.weylandt at gmail.com]
> Sent: Monday, October 17, 2011 11:44 AM
> To: Bhargava Sana
> Cc: r-help at r-project.org
> Subject: Re: [R] Creation of mlogit models from text file
>
> You're going to have to say more about your text file if you want
> meaningful help: specifically, what is in the file: data, output from
> other software, etc?
>
> There are probably two questions to deal with here: reading in
> whatever is in the text file and mapping it to the correct R object
> and setting up the mlogit model. For the reading part, try
> read.table() or readLines depending on the formatting. For the mlogit,
> look at the mlogit package available on CRAN.
>
> Michael
>
> On Mon, Oct 17, 2011 at 10:52 AM, Bhargava Sana
> <Bhargava.Sana at rsginc.com> wrote:
>> Hello all,
>>
>> Has anyone tried to create an R mlogit model object from a text file? If yes, what would be the best way to do it? I already have models that have been estimated using other software and would like to use R to help me make predictions for new data.
>>
>> Thank you!
>>
>> Bhargava Sana
>>
>>
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>



More information about the R-help mailing list