estimation_theta: Structural estimation for life-cycle model over...

Description Usage Arguments References Examples

View source: R/estimation_theta.R

Description

User front-end function for indirect inference on microsimulated data. Estimation is performed using simulated method of moments and is a particular case of extremum estimator. Theoretical framework can be found on \insertCitegourieroux1993simulation;textualmindist.

Weight matrix W is either assumed to be identity (approach = "one_stage") or estimated with the optimal weight matrix as proposed by \insertCitehansen1982large;textualmindist. In the former case, known as feasible GMM, (approach = "two_stage")

Usage

1
2
3
4
5
6
7
estimation_theta(
  theta_0,
  prediction_function = {     function(theta) theta },
  objective_function = loss_function,
  approach = c("two_step", "one_step"),
  ...
)

Arguments

theta_0

Initial values for θ parameter. This can be a named vector

prediction_function

Function to transform theta into sample conditions. See examples.

objective_function

How to transform output from prediction_function into an objective function. Included for flexibility but not recommanded to change that default option

approach

Estimation approach. Either one_step or two_step (default)

...

Additional arguments that should be used by model_function

References

\insertAllCited

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## Not run: 

n <- 10000L
ncol <- 3
x <- replicate(ncol, rnorm(n))
y <- 2*x[,2] + runif(n)

df <- data.frame(y = y, x1 = x[,1], x2 = x[,2],
                 x3 = x[,3])

moment_function <- function(theta, ...){
  return(
    data.table::data.table(
      'epsilon' = as.numeric(df$x1*(df$y - cbind(1L, df$x1) %*% theta))
    )
  )
}
objective_function <- function(theta, weights = 1L, return_moment = FALSE, ...){
  if (return_moment) return(moment_function(theta, ...))
  if (weights == 1L) return(
  t(moment_function(theta, ...)$epsilon) %*%
     moment_function(theta, ...)$epsilon
  )
  return(
    t(moment_function(theta, ...)$epsilon) %*%
      weights %*%
      moment_function(theta, ...)$epsilon
    )
}

msm1 <- estimation_theta(theta_0 = c(0, 0),
                         model_function = objective_function,
                         approach = "one_step")


## End(Not run)

linogaliana/mindist documentation built on July 11, 2021, 4:22 a.m.