比较几种方法是有效的,但并非旨在选择一种符合我们的愿望/信念的方法。
我对您的问题的回答是:两种分布可能有重叠,而它们的均值却不同,这似乎是您的情况(但我们需要查看您的数据和上下文才能提供更精确的答案)。
我将使用几种比较正常均值的方法来说明这一点。
t
70N(10,1)N(12,1)t10
rm(list=ls())
# Simulated data
dat1 = rnorm(70,10,1)
dat2 = rnorm(70,12,1)
set.seed(77)
# Smoothed densities
plot(density(dat1),ylim=c(0,0.5),xlim=c(6,16))
points(density(dat2),type="l",col="red")
# Normality tests
shapiro.test(dat1)
shapiro.test(dat2)
# t test
t.test(dat1,dat2)
σ
μ
有关轮廓可能性和可能性的定义,请参见1和2。
μnx¯Rp(μ)=exp[−n(x¯−μ)2]
对于模拟数据,可以在R中按如下方式计算它们
# Profile likelihood of mu
Rp1 = function(mu){
n = length(dat1)
md = mean(dat1)
return( exp(-n*(md-mu)^2) )
}
Rp2 = function(mu){
n = length(dat2)
md = mean(dat2)
return( exp(-n*(md-mu)^2) )
}
vec=seq(9.5,12.5,0.001)
rvec1 = lapply(vec,Rp1)
rvec2 = lapply(vec,Rp2)
# Plot of the profile likelihood of mu1 and mu2
plot(vec,rvec1,type="l")
points(vec,rvec2,type="l",col="red")
μ1μ2
3.后验μ
(μ,σ)
π(μ,σ)∝1σ2
μ
# Posterior of mu
library(mcmc)
lp1 = function(par){
n=length(dat1)
if(par[2]>0) return(sum(log(dnorm((dat1-par[1])/par[2])))- (n+2)*log(par[2]))
else return(-Inf)
}
lp2 = function(par){
n=length(dat2)
if(par[2]>0) return(sum(log(dnorm((dat2-par[1])/par[2])))- (n+2)*log(par[2]))
else return(-Inf)
}
NMH = 35000
mup1 = metrop(lp1, scale = 0.25, initial = c(10,1), nbatch = NMH)$batch[,1][seq(5000,NMH,25)]
mup2 = metrop(lp2, scale = 0.25, initial = c(12,1), nbatch = NMH)$batch[,1][seq(5000,NMH,25)]
# Smoothed posterior densities
plot(density(mup1),ylim=c(0,4),xlim=c(9,13))
points(density(mup2),type="l",col="red")
同样,手段的可信度间隔在任何合理的水平上都不重叠。
总之,您可以看到尽管分布重叠,但所有这些方法如何表明均值的显着差异(这是主要关注点)。
⋆
P(X<Y)0.8823825
# Optimal bandwidth
h = function(x){
n = length(x)
return((4*sqrt(var(x))^5/(3*n))^(1/5))
}
# Kernel estimators of the density and the distribution
kg = function(x,data){
hb = h(data)
k = r = length(x)
for(i in 1:k) r[i] = mean(dnorm((x[i]-data)/hb))/hb
return(r )
}
KG = function(x,data){
hb = h(data)
k = r = length(x)
for(i in 1:k) r[i] = mean(pnorm((x[i]-data)/hb))
return(r )
}
# Baklizi and Eidous (2006) estimator
nonpest = function(dat1B,dat2B){
return( as.numeric(integrate(function(x) KG(x,dat1B)*kg(x,dat2B),-Inf,Inf)$value))
}
nonpest(dat1,dat2)
我希望这有帮助。