Forum: help
Monitor Forum | Start New ThreadRE: maxLik: Return code 100: Initial value out of range. [ Reply ] By: Nancy Chou on 2019-05-16 15:19 | [forum:46735] |
Hi Arne, I actually solve the problem. It turned out my main variable contains missing data. Once I removed the missing data, I was able to run. Thank you for responding to my e-mail Joanne |
RE: maxLik: Return code 100: Initial value out of range. [ Reply ] By: Arne Henningsen on 2019-05-16 14:36 | [forum:46733] |
If I run your code, I get an error message: R> S <- sum(cases) # total number of cases Error: object 'cases' not found Please provide a minimal reproducible example. I guess that you get the error message "Initial value out of range", because the log-likelihood value at the initial parameters is infinite, NA, or NaN. You can check this by: R> c(as.numeric(glmfit$coefficients), .1) Please also check your "constraints". |
maxLik: Return code 100: Initial value out of range. [ Reply ] By: Nancy Chou on 2019-05-15 16:37 | [forum:46725] |
To whom it May Concern, I'm trying to fit a Poisson excess relative risk models using a paper I came across (https://www.researchgate.net/publication/329865390_Poisson_excess_relative_risk_models_new_implementations_and_software) In there, the author used the maxLik function to fit the Poisson excess relative risk model. When I ran the program using my own data, I came across the error term that the initial value out of range. I'm puzzled by the error message and not sure how to problem solve. Below is my code. S <- sum(cases) # total number of cases bcvr <- cbind(rep(1, length(cases)), age) # covariance matrix M <- ncol(bcvr) # number of covariates at the background risk term Sk <- as.numeric(cases%*%bcvr) # inner product of cases with covariates doses <- cbind(dose) # RR term covariate Nd <- ncol(doses) # number of RR term covariates #log-likelihood llk <- function(b) sum(log(dpois(cases, py*exp(bcvr%*%b[1:M])*(1 + doses%*%b[(M + 1):(M + Nd)])))) # gradient of the log-likelihood with respect the model parameters grd <- function(t){ pyEi <- as.numeric(py*exp(bcvr%*%t[1:M])) ERRi <- as.numeric(1 + doses%*%t[(M + 1):(M + Nd)]) c( Sk - ((ERRi*pyEi)%*%bcvr), (cases/ERRi)%*%doses - (pyEi)%*%doses ) } # definition of constrains for ERR parameters: beta1 + beta2 > -1/max(D) and beta1 > -1/max(D) A <- matrix(c(rep(0, M), 1), ncol=M + 1) B <- 1/max(dose) constraints <- list(ineqA = A, ineqB = B) # model fitting fitERR <- maxLik(logLik = llk, grad = grd, start = c(as.numeric(glmfit$coefficients), .1), constraints = constraints) Thanks Nancy |