tests/testthat/test-fit_mixAR.R

## Do not edit this file manually.
## It has been automatically generated from *.org sources.

test_that("fit_mixAR works", {

prob   <- exampleModels$WL_ibm@prob
scale  <- exampleModels$WL_ibm@scale
arcoef <- exampleModels$WL_ibm@arcoef@a

fi0 <- fit_mixAR(fma::ibmclose, exampleModels$WL_ibm, fix = "shift")

fit_mixAR(fma::ibmclose, exampleModels$WL_ibm, fix = "shift", init = 2)

tmp_mo <- fit_mixAR(fma::ibmclose, exampleModels$WL_ibm, fix = "shift",
                    init = list(exampleModels$WL_ibm, 5))

## the coefficients used for the fitting function below were obtained by first calling it with:
##
## mo_WLtf <- new("MixARgen", prob = prob, scale = scale, arcoef = arcoef, 
##                dist = list(generator = function(par) fn_stdt(par, fixed = FALSE), 
##                param = c(20, 30, 40)))

fitmo_WLtf_prob <- c(0.578579797, 0.414862603, 0.006557599)
fitmo_WLtf_scale <- c(5.505965, 5.911653, 6.988254)
fitmo_WLtf_arcoef <- list(c(0.6991521, 0.3019527), c(1.6793752, -0.6819934), 0.9254728)
fitmo_WLtf_dist_param <- c(6.243, 27.96, 8381944)

mo_WLtf <- new("MixARgen",
               prob   = fitmo_WLtf_prob,
	       scale  = fitmo_WLtf_scale,
	       arcoef = fitmo_WLtf_arcoef, 
               dist = list(generator = function(par) fn_stdt(par, fixed = FALSE), 
               param = fitmo_WLtf_dist_param))

fitmo_WLtf <- fit_mixAR(fma::ibmclose, mo_WLtf, fix = "shift", minniter = 2, maxniter = 2)

## 2021-08-09:
##     Fit a model with Gaussian components and AR order 0 for one of them.
##     Before the fix today was giving the error below.
##
## simulate from a mar model
## mar <- new("MixARGaussian",prob = c(0.2,0.3,0.5), scale = c(1,4,2), arcoef = list(0.5,0.8,0))
## simdata <- mixAR_sim(mar, n = 100, init=c(1,2))
## mar110 <- fit_mixAR(simdata, c(1,1,0), fix="shift")
## Error in svd(a) : a dimension is zero
mar110 <- fit_mixAR(diff(fma::ibmclose), c(1,1,0), fix="shift")




if(covr::in_covr()){

mo_WLt30_111 <- new("MixARgen", prob = prob, scale = scale, 
                     arcoef = list(0.1, 0.5, 0.8), dist = list(fdist_stdt(30)))

fi30wn_111 <- fit_mixAR(diff(fma::ibmclose), mo_WLt30_111, fix = "white.noise", method = "BBoptim")

## Estimating.  Successful convergence.
## 0.kiki!  4.8227 6.0082 18.1716 
## 
## Estimating.  Successful convergence.
## 0.kiki!  5.128563 6.731221 17.89796 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.957974 6.549832 16.6071 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.941826 6.561235 23.35963 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.913312 6.576608 20.02167 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.875446 6.525766 19.55314 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.856034 6.514799 18.14091 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.839119 6.506982 17.21471 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.830101 6.510181 16.45221 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.824754 6.515123 15.8488 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.825015 6.523113 15.34611 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.830815 6.533221 14.87532 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.847118 6.549382 13.82671 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.864779 6.561899 12.12255 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.88103 6.571996 9.46088 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.8919 6.58133 5.991644 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.894542 6.59043 2.401979 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.889353 6.593083 1.075581 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.885277 6.598826 0.4455969 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.881645 6.60199 0.1199707 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.878514 6.606292 0.06918824 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.876538 6.611424 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.874768 6.613902 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.873536 6.615316 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.872717 6.616194 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.872181 6.616756 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871831 6.61712 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871603 6.617356 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871455 6.61751 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871358 6.61761 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871295 6.617675 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871255 6.617717 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871228 6.617745 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871211 6.617763 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871199 6.617775 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871192 6.617782 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871187 6.617787 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871184 6.61779 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871182 6.617792 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.871181 6.617794 0.01 
## 
## Estimating.  Successful convergence.
## 0.kiki!  4.87118 6.617795 0.01 
## 
## > fi30wn_111
## $model
## An object of class "MixARgen"
## Number of components: 3 
##        prob        shift      scale    order ar_1      
## Comp_1 0.597337441   1.108563 4.871179   1   -0.3556190
## Comp_2 0.395945242  -1.089003 6.617795   1    0.5977633
## Comp_3 0.006717317 -34.388887 0.010000   1   -3.6111095
## 
## Distributions of the error components:
## [[1]]
## [[1]]$pdf
## function(x) dstd(x, nu = nu)
## <bytecode: 0x563283950480>
## <environment: 0x56327fb4c1c8>
## 
## [[1]]$cdf
## function(x) pstd(x, nu = nu)
## <bytecode: 0x56327b80de00>
## <environment: 0x56327fb4c1c8>
## 
## [[1]]$rand
## function(n) rstd(n, nu = nu)
## <bytecode: 0x56327b57fa90>
## <environment: 0x56327fb4c1c8>
## 
## [[1]]$logpdf
## function(x) log(dstd(x, nu = nu))
## <bytecode: 0x56327bc0b740>
## <environment: 0x56327fb4c1c8>
## 
## [[1]]$Fscore
## function(x) - x*(1+nu)/(x^2+nu-2)
## <bytecode: 0x563283893208>
## <environment: 0x56327fb4c1c8>
## 
## [[1]]$xFscore
## function(x) - x^2*(1+nu)/(x^2+nu-2)
## <bytecode: 0x56327d317530>
## <environment: 0x56327fb4c1c8>
## 
## [[1]]$Parscore
## function(x) param_score_stdt(x,nu)
## <bytecode: 0x56328073c630>
## <environment: 0x56327fb4c1c8>
## 
## [[1]]$get_param
## function() nu
## <bytecode: 0x563284a04048>
## <environment: 0x56327fb4c1c8>
## 
## [[1]]$set_param
## function(x) nu <<- x
## <bytecode: 0x5632815a4f00>
## <environment: 0x56327fb4c1c8>
## 
## [[1]]$any_param
## function() param_flag
## <bytecode: 0x56327b9a5be8>
## <environment: 0x56327fb4c1c8>
## 
## 
## 
## 
## $vallogf
## [1] -1197.189
## 
## $niter
## [1] 41
## 
## $all_vallogf
##  [1] -1235.496 -1218.986 -1214.760 -1212.355 -1211.436 -1211.183 -1211.042
##  [8] -1210.952 -1210.891 -1210.845 -1210.808 -1210.767 -1210.690 -1210.531
## [15] -1210.192 -1209.398 -1207.603 -1206.158 -1204.337 -1201.990 -1201.106
## [22] -1197.189 -1197.189 -1197.189 -1197.189 -1197.189 -1197.189 -1197.189
## [29] -1197.189 -1197.189 -1197.189 -1197.189 -1197.189 -1197.189 -1197.189
## [36] -1197.189 -1197.189 -1197.189 -1197.189 -1197.189 -1197.189 -1197.189
## 
## $all_relchange
##  [1]           NA 3.467352e-03 1.979876e-03 7.577684e-04 2.092369e-04
##  [6] 1.163678e-04 7.362687e-05 5.070516e-05 3.764112e-05 3.102896e-05
## [11] 3.366300e-05 6.366066e-05 1.311418e-04 2.805416e-04 6.556662e-04
## [16] 1.484762e-03 1.196600e-03 1.509737e-03 1.948441e-03 7.355017e-04
## [21] 3.261223e-03 1.225911e-07 2.561823e-08 1.083388e-08 4.587185e-09
## [26] 1.942430e-09 8.225095e-10 3.482880e-10 1.474859e-10 6.245846e-11
## [31] 2.645343e-11 1.120584e-11 4.759471e-12 2.011475e-12 8.504753e-13
## [36] 3.600940e-13 1.525082e-13 6.476375e-14 2.753884e-14 1.177523e-14
## [41] 5.127921e-15
} # end if in_covr()

})

Try the mixAR package in your browser

Any scripts or data that you put into this service are public.

mixAR documentation built on May 3, 2022, 5:08 p.m.