1

I use gmm package to estimate a simple model:

library(gmm)
n<-100
a <- rnorm(n, mean = 4, sd = 2)
b <- 2*a + rnorm(n, mean = 0, sd = 1)
z<- as.matrix(cbind(a, b))

g <- function(tet, data)
 {
  m1 <- (data[,2]-(tet*data[,1]))*data[,1]
  return(m1)
 }

gmm(g, z, 1.5)

I get the following error:

Error in colMeans(gt) : 'x' must be an array of at least two dimensions

Any idea what I am doing wrong?

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
Soheil
  • 954
  • 7
  • 20
  • 1
    Not reproducible: "object 'n' not found", "object 'x' not found" –  May 07 '15 at 02:37
  • 2
    What is `n`? What is `x` (in the definition of `b`)? Please try to make the example [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick May 07 '15 at 02:37
  • 2
    From `?gmm`: "g A function of the form g(θ,x) and which returns a n \times q matrix". Your function `g` returns a vector. –  May 07 '15 at 02:44
  • You need to write a function `g` which returns a _n_ x _q_ matrix. –  May 07 '15 at 06:57

0 Answers0