## object 'exampleModels' contains a number of models for examples and testing
names(exampleModels)
exampleModels$WL_ibm
## some of the models below are available in object 'exampleModels';
## the examples here show how to create them from scratch
mo_WLprob <- c(0.5439, 0.4176, 0.0385) # model coefficients from Wong&Li
mo_WLsigma <- c(4.8227, 6.0082, 18.1716)
mo_WLar <- list(c(0.6792, 0.3208), c(1.6711, -0.6711), 1)
mo_WL <- new("MixARGaussian", prob = mo_WLprob, scale = mo_WLsigma, arcoef = mo_WLar)
mo_WL_A <- new("MixARGaussian" # WongLi, model A
, prob = c(0.5, 0.5)
, scale = c(5, 1)
, shift = c(0, 0)
, arcoef = list(c(0.5), c(1.1))
)
mo_WL_B <- new("MixARGaussian" # WongLi, model B
, prob = c(0.75, 0.25)
, scale = c(5, 1)
, shift = c(0, 0)
, arcoef = list(c(0.5), c(1.4))
)
mo_WL_I <- new("MixARGaussian" # WongLi, model I
, prob = c(0.4, 0.3, 0.3)
, scale = c(1, 1, 5)
, shift = c(0, 0, -5)
, arcoef = list(c(0.9, -0.6), c(-0.5), c(1.50, -0.74, 0.12))
)
mo_WL_II <- new("MixARGaussian" # WongLi, model II
, prob = c(0.4, 0.3, 0.3)
, scale = c(1, 1, 5)
, shift = c(5, 0, -5)
, arcoef = list(c(0.9, -0.6), c(-0.7, 0), c( 0, 0.80))
)
## MixAR models with arbitrary dist. of the components
## (user interface not finalized)
## Gaussian
mo_WLgen <- new("MixARgen", prob = mo_WLprob, scale = mo_WLsigma, arcoef = mo_WLar,
dist = list(dist_norm))
## t_3
mo_WLt3v <- new("MixARgen", prob = mo_WLprob, scale = mo_WLsigma, arcoef = mo_WLar,
dist = list(fdist_stdt(3, fixed = FALSE)))
## t_20, t_30, t_40 (can be used to start estimation)
mo_WLtf <- new("MixARgen", prob = mo_WLprob, scale = mo_WLsigma, arcoef = mo_WLar,
dist = list(generator =
function(par)
fn_stdt(par, fixed = FALSE), param = c(20, 30, 40)))
## data(ibmclose, package = "fma") # for `ibmclose'
## The examples below are quick but some of them are marked as 'not run'
## to avoid cumulative time of more than 5s on CRAN.
## fit a MAR(2,2,1) model
a0a <- fit_mixAR(as.numeric(fma::ibmclose), c(2, 2, 1), crit = 1e-4)
## same with 2 sets of automatically generated initial values.
# \donttest{
a0b <- fit_mixAR(as.numeric(fma::ibmclose), c(2, 2, 1), 2, crit = 1e-4)
# }
## fix the shift parameters:
a1a <- fit_mixAR(as.numeric(fma::ibmclose), c(2, 2, 1), fix = "shift", crit = 1e-4)
## ... with 3 sets of automatically generated initial values.
# \donttest{
a1b <- fit_mixAR(as.numeric(fma::ibmclose), c(2, 2, 1), 3, fix = "shift", crit = 1e-4)
# }
# \donttest{
## specify the model using a MixAR model object
a1c <- fit_mixAR(as.numeric(fma::ibmclose), a1a$model, init = a0a$model, fix = "shift",
crit = 1e-4)
## fit a model like mo_WL using as initial values 2 automatically generated sets.
a2 <- fit_mixAR(as.numeric(fma::ibmclose), mo_WL, 2, fix = "shift", permute = TRUE,
crit = 1e-4)
# }
moT_B3 <- new("MixARgen"
, prob = c(0.3, 0.3, 0.4)
, scale = c(2, 1, 0.5)
, shift = c(5, -5, 0)
, arcoef = list(c(0.5, 0.24), c(-0.9), c(1.5, -0.74, 0.12))
# t4, t4, t10
, dist = distlist("stdt", c(4,10), fixed = c(FALSE, TRUE), tr = c(1, 1, 2))
)
moT_C1 <- new("MixARgen"
, prob = c(0.3, 0.3, 0.4)
, scale = c(2, 1, 0.5)
, shift = c(5, -5, 0)
, arcoef = list(c(0.5, 0.24), c(-0.9), c(1.5, -0.74, 0.12))
# t4, t7, N(0,1)
, dist = distlist(c("stdt", "stdt", "stdnorm"), c(4,7))
)
## demonstrate reuse of existing models
exampleModels$WL_Bt_1
moT_C2 <- new("MixARgen"
, model = exampleModels$WL_Bt_1
, dist = distlist(c("stdt", "stdt", "stdnorm"), c(4,7)) # t4, t7, N(0,1)
)
moT_C3 <- new("MixARGaussian", model = exampleModels$WL_Bt_1 )
Run the code above in your browser using DataLab