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'