我想测试我使用 R 中的 stats4::mle 拟合的两个非嵌套模型中的哪一个使用 Vuong 和 Clarke 测试提供了更好的拟合。
- Vuong(计量经济学,1989 年):https ://www.jstor.org/stable/1912557?seq=1#metadata_info_tab_contents
- 克拉克(政治分析,2007 年):http ://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.102.4099&rep=rep1&type=pdf
这是我正在拟合的数据的一小部分,两个不同的模型(函数“w”不同)和相应的 mle():
library(stats4)
### Data
z1 <- c(0.1111111, 0.1037037, 0.1222222, 0.1111111, 0.1074074, 0.1666667, 0.1333333, 0.2000000, 0.1333333, 0.1074074,
0.1037037, 0.1111111, 0.1333333, 0.2000000, 0.1222222, 0.1111111, 0.1666667, 0.1333333, 0.1111111, 0.1333333,
0.1111111, 0.1666667, 0.1074074, 0.1333333, 0.1222222, 0.2000000, 0.1037037)
z2 <- c(0.08888889, 0.06666667, 0.07777778, 0.00000000, 0.03333333, 0.09259259, 0.09629630, 0.08888889, 0.06666667,
0.03333333, 0.06666667, 0.08888889, 0.06666667, 0.08888889, 0.07777778, 0.00000000, 0.09259259, 0.09629630,
0.00000000, 0.09629630, 0.08888889, 0.09259259, 0.03333333, 0.06666667, 0.07777778, 0.08888889, 0.06666667)
p <- c(0.5, 0.9, 0.5, 0.9, 0.9, 0.1, 0.1, 0.1, 0.5, 0.9, 0.9, 0.5, 0.5, 0.1, 0.5, 0.9, 0.1, 0.1, 0.9, 0.1, 0.5, 0.1, 0.9, 0.5, 0.5, 0.1, 0.9)
zce <- c(0.11055556, 0.10277778, 0.11000000, 0.10833333, 0.10185185, 0.11666667, 0.13240741, 0.14166667, 0.13166667,
0.07222222, 0.08796296, 0.09944444, 0.09500000,0.10833333, 0.09444444, 0.05277778, 0.10925926, 0.11759259,
0.05833333, 0.10277778, 0.09277778, 0.10925926, 0.06111111, 0.08833333, 0.09222222, 0.12500000, 0.09166667)
### Functions:
u <- function(x,n)
{
ifelse(n!=1,util <- x^(1-n)/(1-n), util <- log(x))
return(util)
}
u.inv <- function(x,n)
{
ifelse(n !=1, inv.util <- ((1-n)*(x))^(1/(1-n)), inv.util <- exp(x))
return(inv.util)
}
v = function(x,n){return(1/(u(maxz,n)-u(minz,n))*(u(x,n)-u(minz,n)))}
v.inv = function(x,n){return(u.inv(x*(u(maxz,n)-u(minz,n))+u(minz,n),n))}
maxz = 135
minz = 0
### model 1
w <- function(p,a,b){return(exp(-b*(-log(p))^(1-a)))}
### Loglikelihood 1
LL1 <- function(n,a,b,s)
{
V = (v(z1,n)-v(z2,n))*w(p,a,b) + v(z2,n)
res = zce - v.inv(V,n)
ll = dnorm(res, 0, s,log=T)
ll.fin1 <<- ll ### record ll per datapoint given optimal parameters
return(-sum(ll))
}
### mle 1
fit.model1 <- mle(LL1,
start = list(n = 0.1,a=0.1,b=0.1,s=0.1),
method = "L-BFGS-B",
lower = list(n=-Inf,a = -Inf, b = 0.0001, s=0.0001),
upper = list(n=0.9999,a = 0.9999, b = Inf, s=Inf),
control = list(maxit = 500, ndeps = rep(0.000001,4)),
nobs=length(z1))
######################
### model 2
w <- function(p,a,b){return((b*p^a)/(b*p^a+(1-p)^a))}
### Loglikelihood 2
LL2 <- function(n,a,b,s)
{
V = (v(z1,n)-v(z2,n))*w(p,a,b) + v(z2,n)
res = zce - v.inv(V,n)
ll = dnorm(res, 0, s,log=T)
ll.fin2 <<- ll ### record ll per datapoint given optimal parameters
return(-sum(ll))
}
### mle 2
fit.model2 <- mle(LL2,
start = list(n = 0.1,a=0.1,b=0.1,s=0.1),
method = "L-BFGS-B",
lower = list(n=-Inf,a = 0.0001, b = 0.0001, s=0.0001),
upper = list(n=0.9999,a = Inf, b = Inf, s=Inf),
control = list(maxit = 500, ndeps = rep(0.000001,4)),
nobs=length(z1))