次の非線形モデルのパラメーターを暗黙の形式で推定しようとしています。その式は y = f(x;theta) + u ではなく、u = g(x,y;theta) で与えられ、u はランダム項です。 x と y は、説明変数と被説明変数です。g から f を取得することはできません (g は y で反転できない、および/または g は u で加法的ではないため)。以下の NLS と GMM はどちらも実行されません。NLS および GMM のドキュメントでこの問題について何も見つけることができなかったので、どうすればよいのだろうか。このトピックに関するヘルプをいただければ幸いです。
より具体的には、g の次の仕様を検討しました (ただし、NLS と GMM は実行されません)。
#
# The DGP
#
set.seed(34567)
N <- 1000 # sample size
x <- rnorm(N) # explanatory variable
u <- rnorm(N) # u is the random term or the model
y <- (81 - 3*x*x)*(1+exp(u)) # y = h(x,u;theta) is the explained variable
summary(y)
#
# The NLS regression: we know that the true functional form is u = g(x,y;theta) and E[u]=0
# but we do not know that the DGP is obtained for theta_0=81 and theta_1=3
#
x2 <- x*x
NLS_reg <- function(theta_0, theta_1) {
log( y / (theta_0 - theta_1*x2) - 1 )
}
nls_out <- nls(0 ~ NLS_reg(theta_0, theta_1), start = list(theta_0 = 84.3, theta_1 = 3.25), trace = T)
summary(nls_out)
#
# The GMM regression
#
require("gmm")
iota <- rep(1,N)
data <- data.matrix(cbind(y, iota, x, x2))
GMM_reg <- function(data, theta_0, theta_1) {
y <- as.numeric(data[,1])
x2 <- as.numeric(data[,4])
return( log( y / (theta_0*iota-theta_1*x2) - 1 ) )
}
moments <- function(data, theta_0, theta_1) {
z <- data.matrix(data[, 2:4])
m <- z * as.vector(GMM_reg(data, theta_0, theta_1))
return(cbind(m))
}
GMM_out <- gmm(g=moments, x = data, t0 = c(78,2.6), type = "iterative", crit = 1e-3, wmatrix = "optimal", method = "Nelder-Mead", control = list(reltol = 1e-3, maxit = 100))
summary(GMM_out)