1

我尝试使用以下代码求解 GMM 估计器的 2*1 矩阵:

x<-rnorm(50, mean = 3, sd = 2)
y<-rnorm(50, mean = 4, sd = 1)
z_1<-as.matrix(x)
z_2<-as.matrix(y)
e<-function(RGAAA,x,y)
          {m1<-exp(-x/RGAAA[1])-1
          m2<-exp(-y/RGAAA[2])-1
          f<-cbind(m1,m2)  
          return(f)}


summary(gmm(e,cbind(z_1,z_2),c(1,1),method="BFGS",control=1e-12)) 

但是,它们会产生错误消息:

Error in P$g(P$t0, x) : argument "y" is missing, with no default

谁能帮我找出问题所在?非常感谢!

4

1 回答 1

0

Gmm 函数只能有一个变量矩阵和一个参数向量。你去:

set.seed(123)#to replicate the results
x<-rnorm(50, mean = 3, sd = 2)
y<-rnorm(50, mean = 4, sd = 1)
z_1<-as.matrix(x)
z_2<-as.matrix(y)
z <- cbind(z_1,z_2) #make one matrix from both vectors
e<-function(RGAAA,x) #one input for the parameters and one input for the variables
          {m1<-exp(-x[,1]/RGAAA[1])-1
          m2<-exp(-x[,2]/RGAAA[2])-1
          f<-cbind(m1,m2)  
          return(f)}
summary(gmm(e,z,c(1,1),method="BFGS",control=1e-12))

使用我的伪随机数种子,您将获得以下输出:

Call:
gmm(g = e, x = z, t0 = c(1, 1), method = "BFGS", control = 1e-12)


Method:  twoStep 

Kernel:  Quadratic Spectral

Coefficients:
          Estimate     Std. Error   t value      Pr(>|t|)   
Theta[1]   4.5256e+02   3.8809e+01   1.1661e+01   2.0121e-31
Theta[2]   4.9367e+02   1.5265e+01   3.2341e+01  1.8683e-229

J-Test: degrees of freedom is 0 
                J-test               P-value            
Test E(g)=0:    0.00577448313404338  *******            

#############
Information related to the numerical optimization
Convergence code =  0 
Function eval. =  25 
Gradian eval. =  24 
于 2017-05-02T22:18:00.457 回答