2016-06-16 4 views
0

J'ai le problème de fomuler un modèle, où au moins une variable doit être estimée indépendamment des classes, donc un seul et même coefficient pour toutes les classes. Comment pourrait-on faire cela? Je travaille avec le paquet R gmnl.Modélisation de variables génériques dans un modèle de classes latentes avec 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) 

Comment modéliser vous l'une des variables Pf, cl, loc, wk, TOD, ou les mers indépendamment de la classe? Je vous remercie!

Répondre

0

Merci à Mauricio Sarrias Je peux présenter ce travail autour, ce qui devrait résoudre le problème:

################################### 
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) 
########################