ekenah / TranStat

An R package for the analysis of infectious disease transmission data
GNU Lesser General Public License v3.0
8 stars 3 forks source link

Warning message with weibull option in transreg command, providing negative variance of estimates #5

Closed yushuf closed 6 years ago

yushuf commented 7 years ago

Command:
unobs_tr <- transreg( Surv(start, stop, infset) ~ infx + susx + ext(external), sus = "susceptible", data = dat, subset = (trace == 1), dist = "weibull", xdist = "weibull" )

confint(unobs_tr) 2.5% 97.5% log(shape) -0.6486682 -0.4060933 (Intercept) 0.5340550 1.6490126 infx -0.3250205 0.5155029 susx -0.6907586 0.3430065 (xIntercept) NaN NaN log(xshape) NaN NaN

Warning message: In sqrt(diag(treg$var)[parm]) : NaNs produced

round(unobs_tr$var, 2) log(shape) (Intercept) infx susx (xIntercept) log(xshape) log(shape) 0.00 0.01 0.00 0.00 -0.20 0.01 (Intercept) 0.01 0.08 -0.03 -0.03 -3.82 0.04 infx 0.00 -0.03 0.05 0.00 0.23 0.00 susx 0.00 -0.03 0.00 0.07 -0.15 0.00 (xIntercept)
-0.20 -3.82 0.23 -0.15 -5711.21 139.03 log(xshape) 0.01 0.04 0.00 0.00 139.03 -3.01

covariance matrix of coefficients providing negative variance of xintercept and log(xshape). It seems to me something wrong? This is happening frequently with Weibull option. xdata, pdata, coef were sent by email. Github does not attach .csv

coef.txt pdata.txt xdata.txt

ekenah commented 6 years ago

I have recreated the error and will investigate.

ekenah commented 6 years ago

This seems to be a case where "optim" did not find a true minimum in the negative log likelihood. If you try different initial values, it converges to a higher log likelihood with a positive definite Hessian. I tried many different starting values, and the convergence failure seems to happen most often when one of the starting values is far from zero.

I have revised the code so that all initial coefficients are zero by default. You should run some simulations to see if this has reduced the probability of getting negative variances. If so, I will close this issue.