R error: error in `row.names <-. Data.frame` (`* tmp *`, value = value)

I just create a dataset to test the mlogit function, which means a multidimensional logistic regression model

The data is simple:

head(dat)
   y x1 x2 x3
 1 4  1 18  4
 2 5  1 20  5
 3 2  1 25  3
 4 3  0 26  6
 5 4  0 26  8
 6 3  1 27  4

Then when i type

fit <- mlogit(y ~ x1 + x2 + x3, data=dat)

The following message will appear:

Error in `row.names<-.data.frame`(`*tmp*`, value = value) : 
  invalid 'row.names' length

Does anyone know why and how to solve it?

+4
source share
1 answer

On the right says:

The data argument may be the usual "data.frame". In this case, some additional arguments should be provided and "Mlogit.data.

. , , , .

, "" "" :

 # a data.frame in wide format with two missing prices
 Fishing2 <- Fishing
 Fishing2[1, "price.pier"] <- Fishing2[3, "price.beach"] <- NA
 mlogit(mode~price+catch|income, Fishing2, shape="wide", choice="mode", varying = 2:9)

 # a data.frame in long format with three missing lines
 data("TravelMode", package = "AER")
 Tr2 <- TravelMode[-c(2, 7, 9),]
 mlogit(choice~wait+gcost|income+size, Tr2, shape = "long",
        chid.var = "individual", alt.var="mode", choice = "choice")

, stackoverflow! .

  • , . , mlogit, mlogit .
  • . head, , . library(mlogit) .
  • . , . , , some supplementary arguments should be provided . , mlogit, ?mlogit help(mlogit).
+6

Source: https://habr.com/ru/post/1539178/


All Articles