Learn R Programming

hdMTD (version 0.1.4)

as.MTD: Coerce an EM fit to an MTD model

Description

Convenience coercion to rebuild an object of class "MTD" from an EM fit (i.e., an output from MTDest() with class c("MTDest","MTD")). This simply feeds the estimated parameters back into MTDmodel. Note that most methods for "MTD" also work directly on "MTDest" objects via inheritance and explicit coercion is therefore optional.

Usage

as.MTD(x, ...)

Value

An object of class "MTD" as returned by MTDmodel.

Arguments

x

An object of class "MTDest".

...

Further arguments passed to or from other methods (ignored).

See Also

MTDest, MTDmodel

Examples

Run this code
if (FALSE) {
  set.seed(1)
  MTD <- MTDmodel(Lambda = c(1, 3), A = c(0, 1), lam0 = 0.05) # generates MTD model
  X <- perfectSample(MTD, N = 400) # generates MTD sample
  init <- list(
    p0 = c(0.4, 0.6),
    lambdas = c(0.05, 0.45, 0.5),
    pj = list(
      matrix(c(0.2, 0.8, 0.45, 0.55), byrow = TRUE, ncol = 2),
      matrix(c(0.25, 0.75, 0.3, 0.7),  byrow = TRUE, ncol = 2)
    )
  )
  fit <- MTDest(X, S = c(1, 3), init = init) # estimates parameters from sample
  m <- as.MTD(fit) # generates an MTD model from estimated parameters
  str(m, max.level = 1)
}

Run the code above in your browser using DataLab