Skip to content
Prev 301848 / 398506 Next

Problems in using GMM for calculating linear regression

Hi,

I'm trying to use gmm package in order to calculate linear regression (I
need to use the gmm for other application and this is a prior test I'm
doing).

I've defined a function for linear regression with 2 variables (x[,1] holds
the y values, while x[,2:3] holds the x values):

function(tet, x)
{
 m1 <- (x[,1] - (tet[1] + tet[2] * x[,2] + tet[3] * x[,3])) * x[,2]
 m2 <- (x[,1] - (tet[1] + tet[2] * x[,2] + tet[3] * x[,3])) * x[,3]
 m3 <- (x[,1] - (tet[1] + tet[2] * x[,2] + tet[3] * x[,3])) * 1.0
 f <-cbind(m1, m2, m3)
 return(f)
}

Then I run:

gmm(g1, d, c(0,0,0)) 
* d - input data.frame

and I get:
Theta[1]  Theta[2]  Theta[3]  
0.055635  0.025520  0.047638  

However when I use:
glm(y~x1 + x2, data =d)

I get:
Coefficients:
(Intercept)           x1           x2  
    -0.2833       0.0318       0.6612  

When I tries to use the output from glm as initial values to the gmm I got
the following results:
 Theta[1]   Theta[2]   Theta[3]  
-0.283349   0.031798   0.661225

In addition when I'm trying the coefficients from the glm run in g1 I get
the minimum result (much smaller results relative to the gmm result).

BTW, d is:
   y x1         x2
1  0  1 0.29944294
2  0  2 0.12521669
3  1  3 0.97254701
4  0  4 0.79952796
5  0  5 0.77358425
6  0  6 0.09983754
7  1  7 0.46133893
8  0  8 0.59833493
9  0  9 0.80005524
10 0 10 0.02979412
11 1 11 0.70576655
12 0 12 0.67138962
13 0 13 0.33446510
14 1 14 0.72187427
15 0 15 0.28193852
16 1 16 0.11258881
17 0 17 0.22001868
18 1 18 0.54681964
19 0 19 0.03336023
20 1 20 0.47007378

Can someone explain what am I doing wrong and why I don't get the same
results?

Thanks!





--
View this message in context: http://r.789695.n4.nabble.com/Problems-in-using-GMM-for-calculating-linear-regression-tp4638557.html
Sent from the R help mailing list archive at Nabble.com.