Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double' but not sure how to fix it

I get this error when i run the following code but i am unsure how to resolve the issue:

starting_param_val <- list(beta = beta, alpha = alpha, gamma = gamma, eta = eta, sigma = 1)
estimates <- mle2(minuslogl = mLL,
start = lapply(starting_param_val, log),
method = "Nelder-Mead",
data = data.frame(c(flu$Cases, N = 66000000)))

summary(estimates)

prof <- profile(estimates)
plot(prof, main = NA)

starting_param_val <- list(beta = beta, alpha = alpha, gamma = gamma, eta = eta, sigma = 1)
estimates <- mle2(minuslogl = mLL,
start = lapply(starting_param_val, log),
method = "Nelder-Mead",
data = data.frame(c(flu$Cases, N = 66000000)))

summary(estimates)
Maximum likelihood estimation

Call:
mle2(minuslogl = mLL, start = lapply(starting_param_val, log),
method = "Nelder-Mead", data = data.frame(c(flu$Cases, N = 6.6e+07)))

Coefficients:
Estimate Std. Error z value Pr(z)
beta -1.6945e+01 0.0000e+00 -Inf < 2.2e-16 ***
alpha -6.2522e+00 0.0000e+00 -Inf < 2.2e-16 ***
gamma -4.2086e+00 1.0290e-18 -4.0900e+18 < 2.2e-16 ***
eta -4.2191e+00 9.7807e-19 -4.3136e+18 < 2.2e-16 ***
sigma 6.9381e+00 1.2678e-01 5.4726e+01 < 2.2e-16 ***

Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1

-2 log L: 486.8175

profile(estimates)
Profiling has found a better solution,so original fit had not converged:

(new deviance=486.7, old deviance=486.8, diff=-0.07309)

Returning better fit ...

Call:
mle2(minuslogl = function (beta, alpha, gamma, eta, sigma, Day,
Cases, N = 6.6e+07)
{
beta <- exp(beta)
alpha <- exp(alpha)
gamma <- exp(gamma)
eta <- exp(eta)
sigma <- exp(sigma)
I0 <- 1
observations <- flu$Cases[-1]
predictions <- sir_values_1
predictions <- predictions[, 4][-1]
-sum(dnorm(x = observations, mean = predictions, sd = sigma,
log = TRUE))
}, start = list(beta = -16.9454244088328, alpha = -6.25223260081642,
gamma = -4.20860043522018, eta = -4.21905179798287, sigma = 6.93812275330027),
method = "Nelder-Mead", fixed = list(beta = c(beta = -16.9454244088328)),
data = list(c.flu.Cases..N...6.6e.07. = c(0, 48, 43, 67,
46, 54, 83, 140, 202, 264, 330, 152, 407, 676, 643, 714,
1035, 665, 967, 1427, 1452, 2129, 2890, 2556, 2502, 2665,
3250, 4567, 4522, 4672, 6.6e+07)), skip.hessian = TRUE, lower = -Inf,
upper = Inf, control = list())

Coefficients:
beta.beta alpha gamma eta sigma
-16.945424 -6.396627 -3.815565 -3.496303 6.973033

Log-likelihood: -243.37

prof <- profile(estimates)
Profiling has found a better solution,so original fit had not converged:

(new deviance=486.7, old deviance=486.8, diff=-0.07309)

Returning better fit ...

plot(prof, main = NA)
Error in as.double(y) :
cannot coerce type 'S4' to vector of type 'double'

The message indicates that the data to be plotted is not directly accessible in the prof object. Use

str(prof)

to see where it is embedded within the S4 object.

Im trying to plot the likelihood profiles:

str(prof)
Formal class 'mle2' [package "bbmle"] with 12 slots
..@ call : language mle2(minuslogl = function (beta, alpha, gamma, eta, sigma, Day, Cases, N = 6.6e+07) { ...
..@ call.orig: language mle2(minuslogl = function (beta, alpha, gamma, eta, sigma, Day, Cases, N = 6.6e+07) { ...
..@ coef : Named num [1:4] -6.4 -3.82 -3.5 6.97
.. ..- attr(, "names")= chr [1:4] "alpha" "gamma" "eta" "sigma"
..@ fullcoef : Named num [1:5] -16.95 -6.4 -3.82 -3.5 6.97
.. ..- attr(
, "names")= chr [1:5] "beta.beta" "alpha" "gamma" "eta" ...
..@ vcov : logi [1:4, 1:4] NA NA NA NA NA NA ...
.. ..- attr(*, "dimnames")=List of 2
.. .. .. : chr [1:4] "alpha" "gamma" "eta" "sigma" .. .. .. : chr [1:4] "alpha" "gamma" "eta" "sigma"
..@ min : num 243
..@ details :List of 7
.. .. par : Named num [1:4] -6.4 -3.82 -3.5 6.97 .. .. ..- attr(*, "names")= chr [1:4] "alpha" "gamma" "eta" "sigma" .. .. value : num 243
.. .. counts : Named int [1:2] 53 NA .. .. ..- attr(*, "names")= chr [1:2] "function" "gradient" .. .. convergence: int 0
.. .. message : NULL .. .. hessian : logi [1:4, 1:4] NA NA NA NA NA NA ...
.. .. maxgrad : num 0.0101 ..@ minuslogl:function (beta, alpha, gamma, eta, sigma, Day, Cases, N = 6.6e+07) .. ..- attr(*, "srcref")= 'srcref' int [1:8] 1 8 13 1 8 1 1 13 .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x7fab61fc0ab8> ..@ method : chr "Nelder-Mead" ..@ data :List of 1 .. .. c.flu.Cases..N...6.6e.07.: num [1:31] 0 48 43 67 46 54 83 140 202 264 ...
..@ formula : chr ""
..@ optimizer: chr "optim"

Please see the code toward the end of this post reproducing the log likelihood plot Figure 1.3 in Hosmer, David W., Stanley Lemeshow, and Rodney X. Sturdivant. Applied logistic regression . Hoboken, New Jersey: Wiley, 2013, the standard text

Thanks, just had a ready and the issue is with the line:
confint(estimates)

as it comes up with this error:

Profiling...

Profiling has found a better solution,so original fit had not converged:

(new deviance=486.7, old deviance=486.8, diff=-0.07309)

Returning better fit ...

returning better fit

Any idea how to converge it?

The resolution depends on the data, which is missing from the OP

This is the data im using

Cases
0
48
43
67
46
54
83
140
202
264
330
152
407
676
643
714
1035
665
967
1427
1452
2129
2890
2556
2502
2665
3250
4567
4522
4672

Please see the FAQ. The data provided is insufficient to reproduce the result.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.