全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
11062 19
2011-10-26
哪位高手用R自己编写过广义矩估计的程序吗?
如果谁能提供,在下可以奉献100个论坛币!
最简单的就行如:yit=alpha*yi,t-1+yitai+uit,就行!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2011-10-28 19:10:23

简单模型,我看过matlab code

如果你熟悉matlab,我可上传.

model:Y=alpha+beta*X+eta

moment conditions:[E(eta);E(X*eta)]=0

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-10-28 20:37:47
epoh老师,您要是方便,发上来我们学习学习!非常感谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-10-28 21:28:50

原始文件来自:

    http://www.mathworks.com/matlabcentral/fileexchange/12114-gmm

为方便在matlab & R比较,我把数据截出.

gmmestimation.m
gmmweightmatrix.m
linearmodel01.m
gmm.xls
gmm.csv

  

gmm_single_eq.rar
大小:(40.68 KB)

 马上下载


%%%%%%in matlab command window
data=xlsread('gmm.xls','a2:c1001');
X=data(:,1);
Y=data(:,2);
Z=[ones(length(X),1),data(:,3)];

number=100;
para0=[0;1];
[paraest,t_sta,V]=gmmestimation('linearmodel01',para0,Y,X,Z,number,2)

%paraest =
%    1.0144
%    1.9802
%t_sta =
%   87.3992
%  178.1722
%V =
%  1.0e-003 *
%    0.1347    0.0092
%    0.0092    0.1235
%%%%%%in R command window
library(gmm)
data=read.csv("gmm.csv")
y=data[,1]
z=data[,2]
iv=data[,3]
res=gmm(z~y,x=iv,type ="cue",vcov = "HAC")
summary(res)

Call:
gmm(g = z ~ y, x = iv, type = "cue", vcov = "HAC")
Method:  cue
Kernel:  Quadratic Spectral
Coefficients:
             Estimate    Std. Error  t value     Pr(>|t|)  
(Intercept)    1.014328    0.011195   90.605819    0.000000
y             1.980223    0.011052  179.166619    0.000000

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

#############

#####in TSP

知道zhangtao兄对TSP也很有兴趣

也一并提供simplegmm.tsp的执行结果

simplegmm.tsp

simplegmm.rar
大小:(219 Bytes)

 马上下载

本附件包括:

  • simplegmm.tsp


gmm.xls for tsp

gmm.xls
大小:(100.5 KB)

 马上下载

         PROGRAM
COMMAND  ***************************************************************
1  options  memory=4;
2  FREQ N;
3  SMPL 1 1000;
4  READ(file='GMM.XLS');
5  frml eq1 y = alpha + beta*x;
6    param alpha beta;
7  GMM (INST=(C,Z)) EQ1 ;
8
8  END;
         EXECUTION
*******************************************************************************Current sample:  1 to 1000                         GENERALIZED METHOD OF MOMENTS
                         =============================
WITH STARTING VALUES VIA:
                       NONLINEAR TWO STAGE LEAST SQUARESEQUATIONS: EQ1INSTRUMENTS: C Z
.....
.....
Number of observations = 1000  E'PZ*E = .175761E-30                         Standard
Parameter  Estimate        Error       t-statistic   P-value
ALPHA      1.01433       .010882       93.2138       [.000]
BETA       1.98022       .011003       179.967       [.000]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-10-29 21:16:51
epoh 发表于 2011-10-28 21:28
原始文件来自:    http://www.mathworks.com/matlabcentral/fileexchange/12114-gmm为方便在matlab & R比较 ...


epoh老师,您好!
    附件中的程序运行到这里提示:waiting for input
我尝试输入参数,但是总是提示错误,
epoh老师,您看看,应该如何输入参数呢?
非常感谢!
***************************************************************************
                                                                          
                               GVAR Toolbox 1.1                           
                                   July 2011                              
                                                                          
                                                                          
Alessandro Galesi, CEMFI Madrid & L.Vanessa Smith, University of Cambridge
***************************************************************************
>>> Type the interface filename (WITHOUT the .xls extension) that you would like to
    use and press enter. If you wish to use one of the demo interface files provided
    with the installation program, type gvarBriefDemo or gvarFullDemo, accordingly.
    Alternatively, type the name of your own interface file.
    Note that MatLab is case sensitive.

======================================================================================
Note:
1. After typing the interface filename, the program will start running and it will make
   a number of pauses, unless the "Running the program with pauses option" is disabled.
   (This is the case for the gvarBriefDemo, for which no pauses will be performed).
2. At each pause, you will be called upon to supply settings and/or check intermediate
   results in the MAIN worksheet of the interface file that will open automatically each
   time. Once this file has opened, always refer back to the MatLab command window for
   instructions and information.
3. Additional guidance is also available by clicking on many of the headings and field
   names within the MAIN worksheet.

-----------------------------------------------------------------------------------
  After every pause, once the required settings have been supplied and/or the inter-
  mediate results have been checked, you must save and close the interface file. In
  fact, it is recommended that you close excel completely, each time.
-----------------------------------------------------------------------------------

USING THE FULL DEMO INTERFACE FILE
If you are using the full demo interface file most of the required settings and
intermediate results are already provided. However, there are occassions where the
user is required to intervene. Once again, consult the MatLab command window for
instructions referring SPECIFICALLY to the use of the full demo interface file.
If no such instructions are given, just save and close the interface file whenever
it opens in order to proceed.
======================================================================================

wainting for input


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-10-29 21:26:44
[paraest,t_sta,V]=gmmestimation('linearmodel01',para0,Y,X,Z,number,2)
epoh老师,您好!
inearmodel01是一个函数,为什么在这里可以做为moment参数引用?

另外,我运行了三个程序后,我的感想是:
这三个GMM程序matlab和R的程序可以看到源文件,可以方便修改和学习,
但是TSP程序简洁,但是看不到源程序,不能修改,不方便。
您看我的看法正确吗?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群