0

I have data which looks like this:

## # A tibble: 6 x 7
##   sampleno    h0    h1    h2    h3    h4 correct_hyp_no
##<dbl> <dbl> <dbl> <dbl> <dbl> <dbl><dbl>
## 1 0  7498  7147  7137  7003  7003 0
## 2 1  7349  7133  7104  7065  6960 0
## 3 2  6907  6676  6671  6575  6575 0
## 4 3  7339  7267  7133  7089  7051 0
## 5 4  5378  5316  5248  5205  5171 NA
## 6 5  7411  7253  7233  7137  7118 4

When I run

mlogit(correct_hyp_no ~ h0 + h1 + h2 + h3 + h4, my_data)

I get an error

Error in data.frame(lapply(index, function(x) x[drop = TRUE]), row.names = rownames(mydata)) : row names supplied are of the wrong length

I'm fairly new to R. I didn't explicitly name rows, but it looks like it's automatically picked up 1,2,3,4,5,6 as names. What's going wrong, please?

Mohan
  • 7,302
  • 5
  • 32
  • 55
  • Your example is not self-contained, so we cannot help. Maybe wrapping "my_data" into `as.data.frame()` might solve the problem. – Michael M Sep 29 '19 at 18:19

1 Answers1

1

My reputation is too low to comment, but like Michael M said, you have not provided a reproducible example. That said, there are a few things you can do to get going.

  1. The data would need to be transformed into a format that mlogit can understand. Your data appears to be in wide format, so you would want to transform it to long format. See ?mlogit.data.
  2. Transforming the data will take care of the outcome variable, which will be coded as a TRUE/FALSE. However, it will probably be necessary to drop the situations where no outcome was recorde, i.e. where correct_hyp_no == NA.

If setting up the data correctly does not work, please provide a reproducible MWE and more information about what it is that you are trying to do.

edsandorf
  • 757
  • 7
  • 17