Is this an acceptable formulation?
If yest, given this setting, I am not sure whether the usual formula (square root of sum of squares) for calculating the sd of the parameters still apply. In particular, I am not sure about the correlation between a log-normal and a normal distribution?
Here is some code:
Code: Select all
rm(list = ls())
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "MXL_corr_ln_control",
modelDescr = "Mixed logit model, correlated, controls ",
indivID = "interview__key",
mixing = TRUE,
nCores = 6,
outputDirectory = "output/Correlated"
)
apollo_beta = c(
mu_asc = -3, sigma_asc = 0,
mu_b_subs = -3.4,
sigma_s2 = 4,
# Cholesky matrix to represent correlation
# shifts of means by socio-eco variables
mu_w_legu = 22,
sigma_ls = 0, sigma_l2 = -16.954438,
gamma_legu_female = -6,
gamma_legu_W9 = -5,
gamma_legu_W28 = 0,
gamma_legu_risk = 3,
gamma_legu_age_med = 0,
gamma_legu_age_young = -10,
gamma_legu_ha_person = 10,
mu_w_fodd = 1,
sigma_fs = 0, sigma_fl = 0.064647, sigma_f2 = +0.4,
gamma_fodd_female = 0.7,
gamma_fodd_W9 = 0 ,
gamma_fodd_W28 = 0.2,
gamma_fodd_risk = 0.03,
gamma_fodd_age_med = 0.2,
gamma_fodd_age_young = -0.1,
gamma_fodd_ha_person = -0.3,
#apollo_fixed = c()
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "sobolOwenFaureTezuka",
interNDraws = 1500,
interUnifDraws = c(),
interNormDraws = c("draws_asc", "draws_legu","draws_fodd", "draws_subs"),
intraDrawsType = "halton",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c())
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["asc_SQ"]] = mu_asc + sigma_asc * draws_asc
randcoeff[["b_subs"]] = exp(mu_b_subs + sigma_s2 * draws_subs)
randcoeff[["wta_legu"]] = mu_w_legu + sigma_ls * draws_subs + sigma_l2 * draws_legu +
gamma_legu_female*GENDER + gamma_legu_W9*W9 +
gamma_legu_W28*W28 + gamma_legu_risk*RISK_SCALE +
gamma_legu_age_med*age_med + gamma_legu_age_young* age_young +
gamma_legu_ha_person*ha_person
randcoeff[["wta_fodd"]] = mu_b_fodd + sigma_fs * draws_subs + sigma_fl * draws_legu + sigma_f2* draws_fodd +
gamma_fodd_female*GENDER + gamma_fodd_W9*W9 +
gamma_fodd_W28*W28 + gamma_fodd_risk*RISK_SCALE +
gamma_fodd_age_med*age_med + gamma_fodd_age_young* age_young +
gamma_fodd_ha_person*ha_person
return(randcoeff)
}
Code: Select all
ses <- apollo_deltaMethod(model, deltaMethod_settings = list(expression=c(
sd.subs = "sigma_s2",
sd.legu= "sqrt(sigma_ls^2 + sigma_l2^2)",
sd.fodd="sqrt(sigma_fl^2 + sigma_f2^2)",
#create the cholesky matrix
row1 <- c(model$estimate["sigma_s2"], 0, 0, 0,0)
row2 <- c(model$estimate["sigma_ls"], model$estimate["sigma_l2"], 0, 0,0)
row3 <- c(model$estimate["sigma_fs"], model$estimate["sigma_fl"], model$estimate["sigma_f2"], 0,0)
cholesky <- as.matrix(rbind(row1, row2, row3))
# compute covariance matrix
cov_matrix <- cholesky %*% t(cholesky)
# compute the correlation matrix
corr_matrix <- cov2cor(cov_matrix)
corr_matrix