> ## Avoid printing to unwarranted accuracy
> od <- options(digits = 5)
> x <- 0:10
> y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)
>
> ## Easy one-dimensional MLE:
> nLL <- function(lambda) -sum(stats::dpois(y, lambda, log=TRUE))
> fit0 <- mle(nLL, start = list(lambda = 5), nobs = NROW(y))
错误: 没有"mle"这个函数
> # For 1D, this is preferable:
> fit1 <- mle(nLL, start = list(lambda = 5), nobs = NROW(y),
+ method = "Brent", lower = 1, upper = 20)
错误: 没有"mle"这个函数
> stopifnot(nobs(fit0) == length(y))
错误于nobs(fit0) : 找不到对象'fit0'
>
> ## This needs a constrained parameter space: most methods will accept NA
> ll <- function(ymax = 15, xhalf = 6) {
+ if(ymax > 0 && xhalf > 0)
+ -sum(stats::dpois(y, lambda = ymax/(1+x/xhalf), log = TRUE))
+ else NA
+ }
> (fit <- mle(ll, nobs = length(y)))
错误: 没有"mle"这个函数
> mle(ll, fixed = list(xhalf = 6))
错误: 没有"mle"这个函数
> ## alternative using bounds on optimization
> ll2 <- function(ymax = 15, xhalf = 6)
+ -sum(stats::dpois(y, lambda=ymax/(1+x/xhalf), log = TRUE))
> mle(ll2, method = "L-BFGS-B", lower = rep(0, 2))
错误: 没有"mle"这个函数
>
> AIC(fit)
错误于AIC(fit) : 找不到对象'fit'
> BIC(fit)
错误于BIC(fit) : 找不到对象'fit'
>
> summary(fit)
错误于summary(fit) : 找不到对象'fit'
> logLik(fit)
错误于logLik(fit) : 找不到对象'fit'
> vcov(fit)
错误于vcov(fit) : 找不到对象'fit'
> plot(profile(fit), absVal = FALSE)
错误于profile(fit) : 找不到对象'fit'
> confint(fit)
错误于confint(fit) : 找不到对象'fit'
>
> ## Use bounded optimization
> ## The lower bounds are really > 0,
> ## but we use >=0 to stress-test profiling
> (fit2 <- mle(ll, method = "L-BFGS-B", lower = c(0, 0)))
错误: 没有"mle"这个函数
> plot(profile(fit2), absVal=FALSE)
错误于profile(fit2) : 找不到对象'fit2'
>
> ## a better parametrization:
> ll3 <- function(lymax = log(15), lxhalf = log(6))
+ -sum(stats::dpois(y, lambda=exp(lymax)/(1+x/exp(lxhalf)), log=TRUE))
> (fit3 <- mle(ll3))
错误: 没有"mle"这个函数
> plot(profile(fit3), absVal = FALSE)
错误于profile(fit3) : 找不到对象'fit3'
> exp(confint(fit3))
错误于confint(fit3) : 找不到对象'fit3'
>
> options(od)
>
epoh老师,您好·!
这个MLE函数在R的什么地方?如何安装?


雷达卡



京公网安备 11010802022788号







