r - 泊松分布上的 MLE bootstrap

标签 r machine-learning statistics poisson statistics-bootstrap

我有以下泊松分布:

Data
3 5 3 1 2 1 2 1 0 2 4 3 1 4 1 2 2 0 4 2 2 4 0 2 1 0 5 2 0 1 
2 1 3 0 2 1 1 2 2 0 3 2 1 1 2 2 5 0 4 3 1 2 3 0 0 0 2 1 2 2 
3 2 4 4 2 1 4 3 2 0 3 1 2 1 3 2 6 0 3 5 1 3 0 1 2 0 1 0 0 1 
1 0 3 1 2 3 3 3 2 1 1 2 3 0 0 1 5 1 1 3 1 2 2 1 0 3 1 0 1 1

我使用以下代码来查找 MLE θ̂

lik<-function(lam) prod(dpois(data,lambda=lam)) #likelihood function
nlik<- function(lam) -lik(lam) #negative-likelihood function
optim(par=1, nlik) 

我想要做的是创建一个引导置信区间来测试 0.05 水平上 θ = 1 的零假设,并使用我上面使用的数值优化找到 p 值。 我认为这会是类似的事情

n<-length(data)
nboot<-1000
boot.xbar <- rep(NA, nboot)
for (i in 1:nboot) {
data.star <- data[sample(1:n,replace=TRUE)]
boot.xbar[i]<-mean(data.star)
}
quantile(boot.xbar,c(0.025,0.975))

但我不认为这利用了优化,而且我不确定如何获得 p 值。

最佳答案

几点:

(1) 为了数值稳定性,您可能需要考虑负对数似然而不是负似然。

(2) 根据 Zheyuan 的建议,您需要使用 optimize 代替 optim 来在一维参数空间中实现 nll 最小化。

lik<-function(lam) sum(log(dpois(data,lambda=lam))) #log likelihood function
nlik<- function(lam) -lik(lam) #negative-log-likelihood function
optimize(nlik, c(0.1, 2), tol = 0.0001)

# $minimum
# [1] 1.816661    
# $objective
# [1] 201.1172

n<-length(data)
nboot<-1000
boot.xbar <- rep(NA, nboot)
for (i in 1:nboot) {
  data.star <- data[sample(1:n,replace=TRUE)]
  boot.xbar[i]<-mean(data.star)
}
quantile(boot.xbar,c(0.025,0.975))
#  2.5%    97.5% 
# 1.575000 2.066667 

(3) 您可以使用 bbmle 包中的 mle2 来计算 MLE 并立即构建置信区间。

library(bbmle)
res <- mle2(minuslogl = nlik, start = list(lam = 0.1))
res   
# Coefficients:
#     lam 
# 1.816708     
# Log-likelihood: -201.12 

confint(profile(res)) # confint w.r.t. the likelihood profile
# 2.5 %   97.5 % 
# 1.586083 2.068626 

confint(res, method="uniroot") # based on root-finding to find the exact point where the profile crosses the critical level     
#    2.5 %   97.5 % 
# 1.586062 2.068606 

关于r - 泊松分布上的 MLE bootstrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41093656/

相关文章:

R基础图形圆形直方图

machine-learning - 什么是强化学习中的最优性?

java - 使用 Scikit Learn 支持 vector 机在 Android 应用程序中进行预测

machine-learning - 找到分离 2 个已知数据组的最佳特征集

machine-learning - 如何识别(多峰)连续变量中的模式

algorithm - 一通通用统计。整数的数值稳定性

r - 在 R 中进行主成分分析时,如何判断是否首先标准化数据矩阵更好?

通过过滤、分组然后根据语句条件重命名因子级别

r - 如何为多个数据框条目分配唯一标识符

r - H2O:退出时保留-ice_root?