zhuwang46 / mpath

1 stars 3 forks source link

NegBin family zipath - never uses init.theta #10

Open Alihanan opened 3 months ago

Alihanan commented 3 months ago

Based on my observation ,the following parts of the zipath_fit(...) function:

if(family=="negbin" && theta.fixed) {
    #if(is.null(init.theta)){
    #    init.theta <- fit0$theta
    #}
    Xtmp <- X
    Ztmp <- Z
    X <- as.matrix(X[,1])
    Z <- as.matrix(Z[,1])
    kx <- 1
    kz <- 1 
### find the solution of estimates for the intercept-only model with fixed init.theta; what about offset? 
    fit0.nb <- optim(fn = ziNegBin2, gr = gradfun,
                     par = c(fit0$coef$count, fit0$coef$zero), #if(dist == "negbin") log(start$theta) else NULL),
                     method = "Nelder-Mead", hessian = FALSE, control = list(fnscale=-1))
    fit0$coefficients <- list(count=fit0.nb$par[1], zero=fit0.nb$par[2])
    fit0$theta <- init.theta
    X <- Xtmp
    Z <- Ztmp
    kx <- NCOL(X)
    kz <- NCOL(Z)
}

....

start <- list(count = model_count$coefficients, zero = model_zero$coefficients)
vcov <- vector("list", length=nlambda)
if(family == "negbin"){
    #if(!theta.fixed)
    #    start$theta <- fit0$theta
    #else start$theta <- init.theta
}
if(is.null(start$theta)) start$theta <- 1

always set the theta coefficient to 1 if theta.fixed=TRUE and overwrites the start (zero and count) values to be that of zeroinfl run with init.theta.

Is this the intended behavior or the functionality is yet to be implemented? I do apologize if it was described elsewhere

zhuwang46 commented 3 months ago

The initial point theta is important for stable estimation. Although there are potentially different strategies, this is the intended implementation.

On Jun 2, 2024, at 2:59 PM, Alihanan @.***> wrote:

Based on my observation ,the following parts of the zipath_fit(...) function:

if(family=="negbin" && theta.fixed) {

if(is.null(init.theta)){

#    init.theta <- fit0$theta
#}
Xtmp <- X
Ztmp <- Z
X <- as.matrix(X[,1])
Z <- as.matrix(Z[,1])
kx <- 1
kz <- 1 

find the solution of estimates for the intercept-only model with fixed init.theta; what about offset?

fit0.nb <- optim(fn = ziNegBin2, gr = gradfun,
                 par = c(fit0$coef$count, fit0$coef$zero), #if(dist == "negbin") log(start$theta) else NULL),
                 method = "Nelder-Mead", hessian = FALSE, control = list(fnscale=-1))
fit0$coefficients <- list(count=fit0.nb$par[1], zero=fit0.nb$par[2])
fit0$theta <- init.theta
X <- Xtmp
Z <- Ztmp
kx <- NCOL(X)
kz <- NCOL(Z)

} ....

start <- list(count = model_count$coefficients, zero = model_zero$coefficients) vcov <- vector("list", length=nlambda) if(family == "negbin"){

if(!theta.fixed)

#    start$theta <- fit0$theta
#else start$theta <- init.theta

} if(is.null(start$theta)) start$theta <- 1 always set the theta coefficient to 1 if theta.fixed=TRUE and overwrites the start (zero and count) values to be that of zeroinfl run with init.theta.

Is this the intended behavior or the functionality is yet to be implemented? I do apologize if it was described elsewhere

— Reply to this email directly, view it on GitHub https://github.com/zhuwang46/mpath/issues/10, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALGS6SFLS7A6YKAVIWZJMQLZFN2QJAVCNFSM6AAAAABIVKKNO2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGMZDSOBTHAZDQNA. You are receiving this because you are subscribed to this thread.