1

少なくとも 1 つの変数がクラスから独立して推定されるモデルを作成する際に問題があるため、すべてのクラスで 1 つの同じ係数を使用します。どうすればこれを行うことができますか?R パッケージ gmnl を使用しています。

install.packages("gmnl")
library(gmnl)
library(mlogit)
#browseURL("https://cran.r-project.org/web/packages/poLCA/index.html")
## Examples using the Fishing data set from the AER package

data("Electricity", package = "mlogit")
Electr <- mlogit.data(Electricity, id.var = "id", choice = "choice",
                      varying = 3:26, shape = "wide", sep = "")
Elec.lc <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0 | 0 | 0 | 1,
                data = Electr,
                subset = 1:3000,
                model = 'lc',
                panel = TRUE,
                Q = 2)
summary(Elec.lc)

クラスから独立して変数 pf、cl、loc、wk、tod、または seas の 1 つをどのようにモデル化しますか? ありがとうございました!

4

1 に答える 1

1

Mauricio Sarrias のおかげで、問題を解決する次の回避策を提示できます。

###################################
library("gmnl")
library("mlogit")

# Data
data("Electricity", package = "mlogit")
Electr <- mlogit.data(Electricity, id.var = "id", choice = "choice",
                    varying = 3:26, shape = "wide", sep = "")
# ASCs
Electr$asc2 <- as.numeric(Electr$alt == 2)
Electr$asc3 <- as.numeric(Electr$alt == 3)
Electr$asc4 <- as.numeric(Electr$alt == 4)

# We estimate a MNL for the initial values of LC-MNL
init_mnl <- gmnl(choice ~ asc2 + asc3 + asc4 + pf + cl| 0,
                  data = Electr)
summary(init_mnl)


# Work on initial values for LC-MNL
init <- coef(init_mnl)
Q <- 2 # Number of Classes

init.shift <- seq(-0.02, 0.02, length.out = Q)
lc.mean <- c()
for(i in 1:Q){
  lc.mean  <- c(lc.mean,  init + init.shift[i])
}
lc.names <- c()
lc.nalpha <- c()
for (i in 1:Q){
  lc.names <- c(lc.names, paste('class', i, names(init), sep = '.'))
}
names(lc.mean) <- lc.names

# Now we fix pf coefficient  = 0 in the second class
lc.mean[c("class.2.pf")] <- 0
start_lc <- c(lc.mean, # Var coefficients
                 0)     #Constant for second class


# Estimate LC with price coefficient held fixed at 0 in class 2
lc <- gmnl(choice ~ asc2 + asc3 + asc4 + pf + cl| 0 | 0 | 0 |1,
                  data = Electr,
                  model = "lc",
                  iterlim = 500,
                  start = start_lc,
                  fixed = c(rep(FALSE, 8), TRUE, rep(FALSE, 2)), # note that class.2.pf is fixed at 0
                  print.level = 3,
                  print.init = TRUE,
                  Q = 2)
summary(lc)
########################
于 2016-06-28T10:26:02.453 に答える