Page 1 of 1

Negative Std Dev, NAs when hessianRoutine="maxLik"

Posted: 04 Feb 2021, 03:59
by anhntl
Dear Professors,
I am estimating in Apollo package and find it very flexible and strong package. I enjoy estimating DCE with it.
However, I am encountering some problem when estimating MIXL and I would like to ask for your advice if possible:

1. I got negative standard deviation and negative t ratio: Is it something wrong or error with my estimation, and how to solve it? Or can I keep the result and change the sign of std dev.
(I read the manual file already but I am still not clear about it and what makes this problem)

2. If I am using estimate_settings=list(hessianRoutine="maxLik"), I got much of NAs. But if using numDeriv, then the covariance can be calculated without NA. I would like to ask the differences between the two, and which case is more suitable for my model.

3. Since I used mlogit and gmnl package before, I found that there are different results to Apollo when I am estimating same MIXL models with same halton draws. (For MNL model, they get similar results). I found from result screen that number of iterations is different, but why it makes so different value of parameters and why they make different iterations?

This is my code. Starting value is taking from MNL estimation.

Thank you very much.


################ MIXL #################

apollo_initialise()
apollo_control = list(
modelName ="SimpleMIXL",
modelDescr ="SimpleHH",
indivID ="id",
mixing=TRUE,panelData=TRUE,
nCores=3
)
database<- read.csv("D:\\Research\\Theses\\Second Chapter\\Working\\Data\\Final\\apollo_household.csv", header=T)
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c( mu.b.width=1, sigma.b.width=0.1,# sigma.hsk.h=0.1,

mu.b.access=1,mu.b.tax=1,
sigma.b.access=0.1,sigma.b.tax=0.1
)

### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c()

### Read in starting values for at least some parameters from existing model output file
apollo_beta=apollo_readBeta(apollo_beta,apollo_fixed,"MNL_Test",overwriteFixed = FALSE)

# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #

### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 50,
interUnifDraws = c(),
interNormDraws = c("draws.width","draws.access","draws.tax"),
intraDrawsType = "halton",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)

### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["b.width"]] = mu.b.width + sigma.b.width * draws.width

randcoeff[["b.access"]] = mu.b.access + sigma.b.access * draws.access
randcoeff[["b.tax"]] = mu.b.tax + sigma.b.tax * draws.tax
return(randcoeff)
}

# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()


# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #

apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){

### Function initialisation: do not change the following three commands
### Attach inputs and detach after function exit
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))

### Create list of probabilities P
P = list()

### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[['alt.1']] = b.access* access.1+b.width*width.1
V[['alt.2']] = b.access* access.2+b.width*width.2+
b.tax* tax.2
V[['alt.3']] = b.width*width.3+
b.access* access.3+b.tax* tax.3

### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt.1=1, alt.2=2,alt.2=3),
avail = list(alt.1=1, alt.2=1,alt.2=1),
choiceVar = choice,
V = V
)

### Compute probabilities using MNL model
P[['model']] = apollo_mnl(mnl_settings, functionality)

### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, functionality)

### Average across inter-individual draws
P = apollo_avgInterDraws(P, apollo_inputs, functionality)

### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}

# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #

model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs)#,estimate_settings=list(hessianRoutine="maxLik"))

apollo_modelOutput(model)
apollo_saveOutput(model)



My mlogit code:
hh<- read.csv("D:\\Research\\Theses\\Second Chapter\\Working\\Data\\Final\\apollo_household.csv", header=T)
hh$chid <- 1:nrow(hh)
m.hh <- dfidx(hh, idx = list(c("chid", "id")),
choice = "choice", varying = 171:185, sep = ".")
mxl.hh<- mlogit(formula = choice ~ tax + width + access | 0, data = m.hh,
rpar = c(tax = "n", width = "n", access = "n"),
R = 50, panel = TRUE, print.level = 3)

summary(mxl.hh)

My gmnl code:
simple=gmnl(choice~tax+access+width|0,
data=mpool.hh, model="mixl", R=50, panel=TRUE, #correlation = TRUE,
ranp=c(access="n",
width="n", tax="n"), print.init = 1)

Re: Negative Std Dev, NAs when hessianRoutine="maxLik"

Posted: 04 Feb 2021, 10:01
by stephanehess
Hi

1. Negative estimates for the standard deviation are not a problem. Please have a look at the frequently asked questions section of the manual or website (http://www.apollochoicemodelling.com/faq.html) to understand why this happens and why it is not a problem. Here is the answer:
Q: Why is my estimate of the standard deviation negative?
This happens if a random coefficient is coded as randCoeff[["beta"]]=mu+sigma*draws where draws is a random variate that is symmetrical around zero.
Q: So should I constrain the standard deviation to be positive?
There is no reason for doing so. The results will be the same if the random variate draws is symmetrical around zero. Imposing constraints will also make estimation harder. And of course, if a user wants to allow for correlation between individual coefficients, then the parameters multiplying the draws need to be able to be positive or negative.
2. We tend to find numDeriv more reliable as a routine in R, but if you update to later versions of Apollo, it will use the most appropriate routine itself.

3. It is difficult to answer this question without knowing how big the differences were you received. Differences can arise for example due to different starting values. Some software also drops the first few draws with Halton, which may again lead to differences in results. 50 draws is of course also a low number in that context.

Best wishes

Stephane