Suppose I have 2 data.frame
objects:
df1 <- data.frame(x = 1:100)
df1$y <- 20 + 0.3 * df1$x + rnorm(100)
df2 <- data.frame(x = 1:200000)
df2$y <- 20 + 0.3 * df2$x + rnorm(200000)
I want to do MLE. With df1
everything is ok:
LL1 <- function(a, b, mu, sigma) {
R = dnorm(df1$y - a- b * df1$x, mu, sigma)
-sum(log(R))
}
library(stats4)
mle1 <- mle(LL1, start = list(a = 20, b = 0.3, sigma=0.5),
fixed = list(mu = 0))
> mle1
Call:
mle(minuslogl = LL1, start = list(a = 20, b = 0.3, sigma = 0.5),
fixed = list(mu = 0))
Coefficients:
a b mu sigma
23.89704180 0.07408898 0.00000000 3.91681382
But if I would do the same task with df2
I would receive an error:
LL2 <- function(a, b, mu, sigma) {
R = dnorm(df2$y - a- b * df2$x, mu, sigma)
-sum(log(R))
}
mle2 <- mle(LL2, start = list(a = 20, b = 0.3, sigma=0.5),
fixed = list(mu = 0))
Error in optim(start, f, method = method, hessian = TRUE, ...) :
initial value in 'vmmin' is not finite
How can I overcome it?