Closed prokashdeb01 closed 9 months ago
Hi,
the issue lies in the definition of the idprob0, idea0, and idg0 vectors. If you set them to 0, it means that none of the nvar.exp covariates are used in the model. So the corresponding parameters are in reality not used in the likelihood, that's why you get infinite standard errors.
The idprob0 vector should contain 0s and 1s. 1 in position k if the covariate number k (the k-th column of X0) appears in the classmb formula. 0 otherwise.
For idea0 : 1 in position k if the covariate number k appears in the random formula. 0 otherwise.
For idg0 :
2 in position k if the covariate number k appears in the fixed and in the mixture formula.
1 in position k if the covariate number k appears only in the fixed formula.
0 otherwise.
Viviane
Hi Dr. Viviane Philipps. Thanks a lot for pointing out the issue in my code. I'm grateful. The Log-likelihood function is working now.
Proaksh Deb
Greetings,
I'm a PhD student and trying to compute the log-likelihood estimate with 2-class model. This is because I want to combine this model with another model and find the combined maximum likelihood estimate. The following is the code I'm using for the latent class:
m.1 <- hlme(fixed = quantity~mon+I(mon^2)+price_final+e, subject = "household_code", ng=1, maxiter = 10000000, data = pbm_1.1, nproc = 14)
m.2 <- hlme(fixed = quantity~mon+I(mon^2)+price_final+e, mixture = ~mon+I(mon^2)+price_final+e, classmb =~Household_Income+Household_Size+male_under_30+male_30_to_45+female_under_30+female_30_to_45+children_yes+male_less_highschool+female_less_highschool+married+african_american+asian+other+hispanic_yes, subject = "household_code", ng=2, B=m.1, maxiter = 10000000, nwg = F, data = pbm_1.1, nproc = 14)
initial_guess_lcmm <- estimates(m.2, cholesky = T)
Log-likelihood for the hlme model
log_likelihood_lcmm <- function(params_lcmm, data_lcmm) {
Ensure params_lcmm is numeric
}
result <- maxLik(logLik = log_likelihood_lcmm, start = initial_guess_lcmm, method = "BFGS", control = list(tol = 1e-6), data = pbm_1.1)
summary(result)
The maxLik fucntion is providing a similar log likelihood value (result[["maximum"]]: -3516.639 and m.2[["loglik"]]: -3117.81). The maxLik function Return code 0: Successful convergence. However, the standard error for all parameters are Inf. It's likely that my written log_likelihood_lcmm function has some issues which I'm not able to figure out. Is it possible to let me know what is the best way to write the log_likelihood_lcmm function in this case? I'm grateful for your help and thanks a lot in advance!