'How to get rid of an error while using the mle function
I tried to run MLE in r using the mle function. It was working fine but I encountered the following error all of a sudden. Can anyone help?
Error in if (!all(lower[isfixed] <= fixed[isfixed] & fixed[isfixed] <= :
missing value where TRUE/FALSE needed
To give you more background, here is my code:
- The negative likelihood function
likelihood.func <- function(theta, kappa, sigma, rt){
n <- NROW(rt)
y <- rt[2:n,]
dt <- 1/12
mu <- rt[1:(n-1),]* exp(-kappa*dt) + theta* (1- exp(-kappa*dt))
sd <- sqrt((sigma^2)*(1 - exp(-2*kappa*dt))/(2*kappa))
pdf_yt <- dnorm(y, mu, sd, log=FALSE)
-sum(log(pdf_yt))
}
- The MLE command
theta.est <- 0.04
kappa.est <- 0.5
sigma.est <- 0.02
library(stats4)
bound.lower <- parameters.est * 0.1
bound.upper <- parameters.est * 2
est.mle<-mle(likelihood.func, start= list(theta=theta.est, kappa=kappa.est, sigma=sigma.est),
method="L-BFGS-B", lower = bound.lower, upper = bound.upper, fixed=list(rt = rt))
summary(est.mle)
Solution 1:[1]
Does it work if you remove rt as the fixed parameter?
#Here I make a function that uses the likelihood function's first three parameters
LL2 = function(theta, kappa, sigma){
likelihood.func(theta,kappa,sigma,rt)
}
#Then I use it in my mle
est.mle <- mle(minuslogl = LL2,
start = list(theta=theta.est, kappa=kappa.est, sigma=sigma.est),
method = "L-BFGS-B",
# fixed = list(rt = rt2),
lower = bound.lower,
upper = bound.upper
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Nick Jacobi |