nmm: Maximum likelihood estimation of nonlinear multivariate...

Description Usage Arguments Value Examples

View source: R/004functions.R

Description

nmm, nmm_sigma and summary are the main functions used for the estimation of NMM.

Usage

 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
37
38
39
40
41
42
43
44
45
46
nmm(
  data,
  eq_type = c("joint", "cont", "disc"),
  eq_d = NULL,
  eq_c = NULL,
  par_c = NULL,
  par_d = NULL,
  start_v = NULL,
  check_hess = TRUE,
  corrl = TRUE,
  weight_paths = TRUE,
  weight_paths_cont = FALSE,
  data_weight = NULL,
  estimate = TRUE,
  fixed_term = FALSE,
  best_method = FALSE,
  DEoptim_run = FALSE,
  hessian = "joint_hess",
  print_out = FALSE,
  diff_hessian = FALSE,
  bayesian_random = FALSE,
  DEoptim_run_main = FALSE,
  deconst = 2,
  numerical_deriv = FALSE,
  best_method4start = FALSE,
  eqsys = "sur",
  miterlim = 10000,
  opt_method = "BFGS",
  try_last_DEoptim = TRUE,
  transform = NULL,
  MNtypef = "logit",
  nmm_object = NULL
)

## S3 method for class 'nmm'
summary(object, type = "normal", new_coef = NULL, ...)

nmm_sigma(
  object,
  methodopt = "BFGS",
  try_1good = TRUE,
  try_DEoptim = FALSE,
  try_diff_method = FALSE,
  trace = FALSE,
  estimate = FALSE
)

Arguments

data

data.frame used in the optimization.

eq_type

Possible options "joint", "cont", "disc".

eq_d

Discrete equations.

eq_c

Continuous equations.

par_c

Parameters from continuous equations.

par_d

Parameters from discrete equations.

start_v

Starting values for optimization. If NULL, starting values are found by get_start function.

check_hess

If TRUE, check the Hessian.

corrl

If TRUE, correlation between blocks (continuous and discrete).

weight_paths

If TRUE, weight according to the number of choices made by individual i will be added to the whole system.

weight_paths_cont

If TRUE, if only to continuous part should be weighted.

data_weight

Data weight matrix.

estimate

If TRUE, estimation is performed.

fixed_term

If TRUE, includes fixed term to continuous equation block.

best_method

If TRUE, all optimizers are checked.

DEoptim_run

If TRUE, runs DEoptim in generation of starting values.

hessian

String, name of the Hessian function.

print_out

If TRUE, prints out log-likelihood for each equation.

diff_hessian

If TRUE, for changing hessian and gradient with weights.

bayesian_random

If TRUE, than par[1] is changed to par[,1] to be used for optimization of random parameters in Bayesian estimation.

DEoptim_run_main

If TRUE, run DEoptim in the main optimization.

deconst

absolute value of lower and upper bound in DEoptim optimization.

numerical_deriv

If TRUE, uses numerical derivative instead of the analytical.

best_method4start

If TRUE, all optimizers are checked for starting values.

eqsys

"sur" or "sem".

miterlim

Number many iterations passed to maxLik function

opt_method

optimization method for maxLik.

try_last_DEoptim

If TRUE, in case of error in maxLik should DEoptim be run.

transform

if TRUE, quantile transformation is applied to discrete equations.

MNtypef

estimate "logit", or "dogit"

nmm_object

nmm object created by nmm function.

object

nmm object, for summary and nmm_sigma

type

Type of standard errors c("robust", "clustered", "normal"), for summary

new_coef

New coefficients that will be tested, for summary

...

additional arguments affecting the summary produced, for summary

methodopt

optimizer from maxLik package, for nmm_sigma

try_1good

If TRUE, stops then first good values are found, for nmm_sigma

try_DEoptim

If TRUE, uses DEoptim for optimization, then maxLik optimizers produce errors, for nmm_sigma

try_diff_method

If TRUE, stops then first good values with Hessian check are found, for nmm_sigma

trace

If TRUE, trace of DEoptim is printed, for nmm_sigma

Value

nmm

returns nmm object with estimated parameters, functions, and data.

nmm_sigma

returns estimated parameters, functions, data.

summary

returns summary of nmm object.

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# estimation of System of Nonlinear Equations based on example from 'systemfit'
library(systemfit)
data( ppine , package="systemfit")
hg.formula <- hg ~ exp( h0 + h1*log(tht) + h2*tht^2 + h3*elev)
dg.formula <- dg ~ exp( d0 + d1*log(dbh) + d2*hg + d3*cr)
labels <- list( "height.growth", "diameter.growth" )
model <- list( hg.formula, dg.formula )
start.values <- c(h0=-0.5, h1=0.5, h2=-0.001, h3=0.0001,
                  d0=-0.5, d1=0.009, d2=0.25, d3=0.005)
model.sur <- nlsystemfit( "SUR", model, start.values, data=ppine, eqnlabels=labels )
eq_c <- as.character(c(hg.formula, dg.formula))
parl <- c(paste0("h", 0:3),paste0("d", 0:3))
res <- nmm(ppine, eq_c=eq_c, par_c=parl, start_v = start.values,
eq_type = "cont", best_method = FALSE, numerical_deriv=TRUE)
summary(res)
res_sigma_cont <- nmm_sigma(res,estimate=TRUE) # Estimation of the Variance-Covariance matrix
summary(res_sigma_cont)

#example discrete choice
library(mlogit)
data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")
## a pure "conditional" model
mres <- summary(mlogit(mode ~ price + catch, data = Fish))
data <- prepare_data(Fish %>% data.frame %>% dplyr::select(-idx),
choice="alt", dummy="mode", PeID="chid", mode_spec_var = c("price", "catch"),
 type="long")
eq_d <- c("a1 + p1 * price_1 + p2 * catch_2", "a2 + p1 * price_2 + p2 * catch_2",
             "a3 + p1 * price_3 + p2 * catch_3", "a4 + p1 * price_4 + p2 * catch_4")
par_d <- c(paste0("a", 1:4), paste0("p", 1:2))
res <- nmm(data, eq_d=eq_d, par_d = par_d,  eq_type="disc", fixed_term=FALSE,
best_method=FALSE)
summary(res)

# joint estimation mockup example
data(dataM)
dataMp <- dataM %>% data.frame %>% prepare_data(. , choice="DR_Course", 
PeID = "Student")
eq_c <- c("PlcmtScore ~ exp(a0 + a1 * PSATM + a2 * Rank + a3 * Size)",
"ACTM ~ exp(c0 + c1 * GPAadj)")
par_c <- c(paste0("a", 0:3), paste0("c", 0:1))
eq_d <- c("ASC1" ,
"ASC2 + b1_2 * SATM + b2_2 * PlcmtScore",
"ASC3 + b1_3 * SATM + b2_3 * PlcmtScore")
par_d <- c(paste0("ASC", 1:3), paste0("b", rep(1:2, rep(2,2)), "_", 2:3))

nmm_joint_res <- nmm(dataMp, eq_type = "joint", eq_d = eq_d, 
par_d = par_d,  eq_c = eq_c, par_c = par_c, 
start_v = c(a0=3.394, a1=0.001, a2=-0.001, a3=0, c0=3.583, c1=-0.008, 
ASC2=-1.452, ASC3=3.047, b1_2=0.145, b1_3=0.102, b2_2=-0.133, b2_3=-0.168))
summary(nmm_joint_res)

nmm documentation built on Jan. 7, 2021, 5:10 p.m.

Related to nmm in nmm...