title: Multinomial logit models and nested logit models
body: <p>I am using the mlogit package in program R. I have converted my data from its original wide format to long format. Here is a sample of the converted data.frame which I refer to as 'long_perp'. All of the independent variables are individual specific. I have 4258 unique observations in the data-set.</p>
  
  <pre><code>         date_id  act2 grp.bin pdist   ship   sea avgknots   shore day location chid  alt
  4.dive 40707_004  TRUE       2 2.250 second light 14.06809 2.30805  12    Lower    4 dive
  4.fly  40707_004 FALSE       2 2.250 second light 14.06809 2.30805  12    Lower    4  fly
  4.none 40707_004 FALSE       2 2.250 second light 14.06809 2.30805  12    Lower    4 none
  5.dive 40707_006 FALSE       2 0.000 second light 15.12650 2.53312  12    Lower    5 dive
  5.fly  40707_006  TRUE       2 0.000 second light 15.12650 2.53312  12    Lower    5  fly
  5.none 40707_006 FALSE       2 0.000 second light 15.12650 2.53312  12    Lower    5 none
  6.dive 40707_007 FALSE       1 1.995 second light 14.02101 2.01680  12    Lower    6 dive
  6.fly  40707_007  TRUE       1 1.995 second light 14.02101 2.01680  12    Lower    6  fly
  6.none 40707_007 FALSE       1 1.995 second light 14.02101 2.01680  12    Lower    6 none
  </code></pre>
  
  <p>'act2' is the dependent variable and consists of choices a bird floating on the water could make when approached by a ship; fly, dive, or none. I am interested in how these probabilities relate to the remaining independent variables in the data.frame, i.e. perpendicular distance to the ship path (pdist) sea conditions (sea), speed (avgknots), distance to shore (shore) etc. The independent variables are made of dichotomous, factor and continuous variables.</p>
  
  <p>I ran two multinomial logit models, one including all the choice options and another including only a subset. I then compared these models with the hmftest() function to test for the IIA assumption. The results were confusing the say the least. I will include the codes for the two models and the test output (in case I am miss-specifying the models in the code).</p>
  
  <pre><code># model including all choice options (fly, dive, none)
  mod.1 &lt;- mlogit(act2 ~ 1 | pdist + as.factor(grp.bin)  +
      as.factor(sea) + avgknots + shore + as.factor(location),long_perp , 
      reflevel = 'none')  
  
  # model including only a subset of choice options (fly, dive)
  mod.alt &lt;- mlogit(act2 ~ 1 | pdist + as.factor(grp.bin)  +
      as.factor(sea) + avgknots + shore + as.factor(location),long_perp , 
      reflevel = 'none', alt.subset = c("fly","dive"))
  
  # IIA test
  hmftest(mod.1, mod.alt)
  # output
              Hausman-McFadden test
  
  data:  long_perp
  chisq = -968.7303, df = 7, p-value = 1
  alternative hypothesis: IIA is rejected
  </code></pre>
  
  <p>As you can see the chisquare statistic is negative! I assume I am either 1. doing something wrong, or 2. IIA is violated. This result holds true for choice subset (fly, dive), but the IIA assumption is upheld with choice subset (none, dive)? This confuses me.</p>
  
  <p>Next I tried to formulate a nested model as a way to relax the IIA assumption. I nested the choices as nest1 = none, nest2 = fly, dive. This makes sense to me as this seems like a logical break, the bird decides to react or not then decides which reaction to make. </p>
  
  <p>I am unclear on how to run the nested logit models (even after reading the two vignettes for mlogit, <a href="http://cran.r-project.org/web/packages/mlogit/vignettes/mlogit.pdf" rel="noreferrer">Croissant vignette</a> and <a href="http://cran.r-project.org/web/packages/mlogit/vignettes/Exercises.pdf" rel="noreferrer">Train vignette</a>).</p>
  
  <p>When I run my analysis following the example in the Croissant vignette I get the following error.</p>
  
  <pre><code>nested.1 &lt;- mlogit(act2 ~  0 | pdist + as.factor(grp.bin) + as.factor(ship) +
      as.factor(sea) + avgknots + shore + as.factor(location),
      long_perp , reflevel="none",nests = list(noact = "none", 
      react = c("dive","fly")), unscaled = TRUE)
  
  # Error in solve.default(crossprod(attr(x, "gradi")[, !fixed])) : 
    Lapack routine dgesv: system is exactly singular: U[19,19] = 0
  </code></pre>
  
  <p>I have read a bit about this error message and it may occur because of complete separation. I have looked at some tables of the data and do not believe this is happening as I have 4,000+ observations and only one factor variable with more than 2 levels (it has 3).</p>
  
  <p>Help on these specific problems is greatly appreciated but I am also open to alternate analyses that I can use to answer my question. I am mainly interested in the probability of flying as a function of perpendicular distance to the ships path. </p>
  
  <p>Thanks, Tim</p>