Skip to contents

These functions and objects are mostly internal and should not be needed for routine use. Generate noise distribution, currently standard normal and standardised t-distributions. These functions can be used as templates for new distributions.

Usage

fdist_stdnorm()

fdist_stdt(df, fixed = TRUE)

fn_stdt(df, fixed = TRUE)

b_show(x)

distlist(type, param, ncomp = NULL, fixed = FALSE, tr = NULL, ...)

ed_nparam

ed_parse(s)

ed_skeleton(df, fixed = FALSE, n = length(df), tr = NULL)

ed_src

ed_stdnorm

ed_stdt

ed_stdt0

ed_stdt1

ft_stdt

Arguments

df

degrees of freedom

fixed

if TRUE, the parameters are fixed, otherwise they are variable, see Details.

x

a fitted object.

type

list of distributions.

param

parameters.

ncomp

number of components.

tr

transformation.

...

not used.

s

named vector.

n

number of different degrees of freedom.

Details

If argument fixed is TRUE, estimation functions assume that the parameter(s) are fixed, otherwise they estimate it. The support is incomplete, see below.

fdist_stdnorm is for the standard normal distribution. For example dist_norm is generated by it.

fdist_stdt is for the t-distribution with df degrees of freedom.

fn_stdt is also for the t-distribution but the degrees of freedom, df, may be a vector. The value is a list of distributions. Although the list can be obtained by repeated calls of fdist_stdt

The support is incomplete. In particular, if parameter fixed is TRUE, changes to the parameter(s) should probably not be allowed (this can be achieved by simply dropping the corresponding function from the list). However, a thorough rethinking is necessary, as I introduced it on the fly while developing estimation functions and forbidding changes may necessitate changes in the code. Changes are useful for estimation for convenience but also to avoid recreating the whole distributions again and again.

However, there is a major drawback, which in the final version needs to be addressed satisfactorily. Since parameters are held in local environments, changes to the parameters are reflected in copies of the objects. For example, an estimation function (or the user) may call another function with a model containing an object generated by the above functions and assign the result to a new object. However if the parameters of the noise distribution are changed in the process this will be reflected in the original model.

Note that the above effect is valid only if an object generated by the above functions is reused. Objects created by different calls have different environments, so the problem does not arise for them.

Examples

stdt3 <- fdist_stdt(3)
stdt3v <- fdist_stdt(3, fixed = FALSE)
fn_stdt(c(20, 30, 40), fixed = FALSE)
#> [[1]]
#> [[1]]$pdf
#> function (x) 
#> dstd(x, nu = nu[k])
#> <bytecode: 0x7faeb711e4a8>
#> <environment: 0x7faec1f7cd68>
#> 
#> [[1]]$cdf
#> function (x) 
#> pstd(x, nu = nu[k])
#> <bytecode: 0x7faeb71220e0>
#> <environment: 0x7faec1f7cd68>
#> 
#> [[1]]$rand
#> function (n) 
#> rstd(n, nu = nu[k])
#> <bytecode: 0x7faeb7121e08>
#> <environment: 0x7faec1f7cd68>
#> 
#> [[1]]$logpdf
#> function (x) 
#> log(dstd(x, nu = nu[k]))
#> <bytecode: 0x7faeb7121b30>
#> <environment: 0x7faec1f7cd68>
#> 
#> [[1]]$Fscore
#> function (x) 
#> -x * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71217e8>
#> <environment: 0x7faec1f7cd68>
#> 
#> [[1]]$xFscore
#> function (x) 
#> -x^2 * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71210b0>
#> <environment: 0x7faec1f7cd68>
#> 
#> [[1]]$Parscore
#> function (x) 
#> param_score_stdt(x, nu[k])
#> <bytecode: 0x7faeb71208d0>
#> <environment: 0x7faec1f7cd68>
#> 
#> [[1]]$get_param
#> function () 
#> nu[k]
#> <bytecode: 0x7faeb7120630>
#> <environment: 0x7faec1f7cd68>
#> 
#> [[1]]$set_param
#> function (x) 
#> nu[k] <<- x
#> <bytecode: 0x7faeb71204e0>
#> <environment: 0x7faec1f7cd68>
#> 
#> [[1]]$any_param
#> function () 
#> param_flag
#> <bytecode: 0x7faeb7124070>
#> <environment: 0x7faec1f7cd68>
#> 
#> [[1]]$show
#> function () 
#> paste("Student t with", format(nu[[k]], digits = 4), "df")
#> <bytecode: 0x7faeb7123f20>
#> <environment: 0x7faec1f7cd68>
#> 
#> 
#> [[2]]
#> [[2]]$pdf
#> function (x) 
#> dstd(x, nu = nu[k])
#> <bytecode: 0x7faeb711e4a8>
#> <environment: 0x7faec1f7c748>
#> 
#> [[2]]$cdf
#> function (x) 
#> pstd(x, nu = nu[k])
#> <bytecode: 0x7faeb71220e0>
#> <environment: 0x7faec1f7c748>
#> 
#> [[2]]$rand
#> function (n) 
#> rstd(n, nu = nu[k])
#> <bytecode: 0x7faeb7121e08>
#> <environment: 0x7faec1f7c748>
#> 
#> [[2]]$logpdf
#> function (x) 
#> log(dstd(x, nu = nu[k]))
#> <bytecode: 0x7faeb7121b30>
#> <environment: 0x7faec1f7c748>
#> 
#> [[2]]$Fscore
#> function (x) 
#> -x * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71217e8>
#> <environment: 0x7faec1f7c748>
#> 
#> [[2]]$xFscore
#> function (x) 
#> -x^2 * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71210b0>
#> <environment: 0x7faec1f7c748>
#> 
#> [[2]]$Parscore
#> function (x) 
#> param_score_stdt(x, nu[k])
#> <bytecode: 0x7faeb71208d0>
#> <environment: 0x7faec1f7c748>
#> 
#> [[2]]$get_param
#> function () 
#> nu[k]
#> <bytecode: 0x7faeb7120630>
#> <environment: 0x7faec1f7c748>
#> 
#> [[2]]$set_param
#> function (x) 
#> nu[k] <<- x
#> <bytecode: 0x7faeb71204e0>
#> <environment: 0x7faec1f7c748>
#> 
#> [[2]]$any_param
#> function () 
#> param_flag
#> <bytecode: 0x7faeb7124070>
#> <environment: 0x7faec1f7c748>
#> 
#> [[2]]$show
#> function () 
#> paste("Student t with", format(nu[[k]], digits = 4), "df")
#> <bytecode: 0x7faeb7123f20>
#> <environment: 0x7faec1f7c748>
#> 
#> 
#> [[3]]
#> [[3]]$pdf
#> function (x) 
#> dstd(x, nu = nu[k])
#> <bytecode: 0x7faeb711e4a8>
#> <environment: 0x7faec1f82038>
#> 
#> [[3]]$cdf
#> function (x) 
#> pstd(x, nu = nu[k])
#> <bytecode: 0x7faeb71220e0>
#> <environment: 0x7faec1f82038>
#> 
#> [[3]]$rand
#> function (n) 
#> rstd(n, nu = nu[k])
#> <bytecode: 0x7faeb7121e08>
#> <environment: 0x7faec1f82038>
#> 
#> [[3]]$logpdf
#> function (x) 
#> log(dstd(x, nu = nu[k]))
#> <bytecode: 0x7faeb7121b30>
#> <environment: 0x7faec1f82038>
#> 
#> [[3]]$Fscore
#> function (x) 
#> -x * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71217e8>
#> <environment: 0x7faec1f82038>
#> 
#> [[3]]$xFscore
#> function (x) 
#> -x^2 * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71210b0>
#> <environment: 0x7faec1f82038>
#> 
#> [[3]]$Parscore
#> function (x) 
#> param_score_stdt(x, nu[k])
#> <bytecode: 0x7faeb71208d0>
#> <environment: 0x7faec1f82038>
#> 
#> [[3]]$get_param
#> function () 
#> nu[k]
#> <bytecode: 0x7faeb7120630>
#> <environment: 0x7faec1f82038>
#> 
#> [[3]]$set_param
#> function (x) 
#> nu[k] <<- x
#> <bytecode: 0x7faeb71204e0>
#> <environment: 0x7faec1f82038>
#> 
#> [[3]]$any_param
#> function () 
#> param_flag
#> <bytecode: 0x7faeb7124070>
#> <environment: 0x7faec1f82038>
#> 
#> [[3]]$show
#> function () 
#> paste("Student t with", format(nu[[k]], digits = 4), "df")
#> <bytecode: 0x7faeb7123f20>
#> <environment: 0x7faec1f82038>
#> 
#> 

mo_tf <- new("MixARgen", prob = exampleModels$WL_ibm@prob,
             scale = exampleModels$WL_ibm@scale, arcoef = exampleModels$WL_ibm@arcoef@a,
             dist = list(generator = function(par)
                 fn_stdt(par, fixed = FALSE), param = c(20, 30, 40)))
mo_tf
#> An object of class "MixARgen"
#> Number of components: 3 
#>        prob   shift scale   order ar_1   ar_2   
#> Comp_1 0.5439   0    4.8227   2   0.6792  0.3208
#> Comp_2 0.4176   0    6.0082   2   1.6711 -0.6711
#> Comp_3 0.0385   0   18.1716   1   1.0000        
#> 
#> Distributions of the error components:
#> 	Component 1: Student t with 20 df
#> 	Component 2: Student t with 30 df
#> 	Component 3: Student t with 40 df
#> 
str(mo_tf)
#> Formal class 'MixARgen' [package "mixAR"] with 6 slots
#>   ..@ dist  :List of 2
#>   .. ..$ generator:function (par)  
#>   .. .. ..- attr(*, "srcref")= 'srcref' int [1:8] 7 38 8 44 38 44 7 8
#>   .. .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x7faec1af26d8> 
#>   .. ..$ param    : num [1:3] 20 30 40
#>   ..@ prob  : num [1:3] 0.5439 0.4176 0.0385
#>   ..@ order : int [1:3] 2 2 1
#>   ..@ shift : num [1:3] 0 0 0
#>   ..@ scale : num [1:3] 4.82 6.01 18.17
#>   ..@ arcoef:Formal class 'raggedCoef' [package "mixAR"] with 2 slots
#>   .. .. ..@ a:List of 3
#>   .. .. .. ..$ : num [1:2] 0.679 0.321
#>   .. .. .. ..$ : num [1:2] 1.671 -0.671
#>   .. .. .. ..$ : num 1
#>   .. .. ..@ p: int [1:3] 2 2 1

noise_dist(mo_tf, "pdf")
#> [[1]]
#> function (x) 
#> dstd(x, nu = nu[k])
#> <bytecode: 0x7faeb711e4a8>
#> <environment: 0x7faec26c45f8>
#> 
#> [[2]]
#> function (x) 
#> dstd(x, nu = nu[k])
#> <bytecode: 0x7faeb711e4a8>
#> <environment: 0x7faec26c7ee8>
#> 
#> [[3]]
#> function (x) 
#> dstd(x, nu = nu[k])
#> <bytecode: 0x7faeb711e4a8>
#> <environment: 0x7faec26c78c8>
#> 
parameters(mo_tf)
#>  [1]  2.0000  2.0000  1.0000  0.5439  0.4176  0.0385  0.0000  0.0000  0.0000
#> [10]  4.8227  6.0082 18.1716  0.6792  0.3208  1.6711 -0.6711  1.0000
parameters(mo_tf, names = TRUE)
#>  order1  order2  order3   prob1   prob2   prob3  shift1  shift2  shift3  scale1 
#>  2.0000  2.0000  1.0000  0.5439  0.4176  0.0385  0.0000  0.0000  0.0000  4.8227 
#>  scale2  scale3   ar_11   ar_12   ar_21   ar_22   ar_31 
#>  6.0082 18.1716  0.6792  0.3208  1.6711 -0.6711  1.0000 
get_edist(mo_tf)
#> [[1]]
#> [[1]]$pdf
#> function (x) 
#> dstd(x, nu = nu[k])
#> <bytecode: 0x7faeb711e4a8>
#> <environment: 0x7faec2867820>
#> 
#> [[1]]$cdf
#> function (x) 
#> pstd(x, nu = nu[k])
#> <bytecode: 0x7faeb71220e0>
#> <environment: 0x7faec2867820>
#> 
#> [[1]]$rand
#> function (n) 
#> rstd(n, nu = nu[k])
#> <bytecode: 0x7faeb7121e08>
#> <environment: 0x7faec2867820>
#> 
#> [[1]]$logpdf
#> function (x) 
#> log(dstd(x, nu = nu[k]))
#> <bytecode: 0x7faeb7121b30>
#> <environment: 0x7faec2867820>
#> 
#> [[1]]$Fscore
#> function (x) 
#> -x * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71217e8>
#> <environment: 0x7faec2867820>
#> 
#> [[1]]$xFscore
#> function (x) 
#> -x^2 * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71210b0>
#> <environment: 0x7faec2867820>
#> 
#> [[1]]$Parscore
#> function (x) 
#> param_score_stdt(x, nu[k])
#> <bytecode: 0x7faeb71208d0>
#> <environment: 0x7faec2867820>
#> 
#> [[1]]$get_param
#> function () 
#> nu[k]
#> <bytecode: 0x7faeb7120630>
#> <environment: 0x7faec2867820>
#> 
#> [[1]]$set_param
#> function (x) 
#> nu[k] <<- x
#> <bytecode: 0x7faeb71204e0>
#> <environment: 0x7faec2867820>
#> 
#> [[1]]$any_param
#> function () 
#> param_flag
#> <bytecode: 0x7faeb7124070>
#> <environment: 0x7faec2867820>
#> 
#> [[1]]$show
#> function () 
#> paste("Student t with", format(nu[[k]], digits = 4), "df")
#> <bytecode: 0x7faeb7123f20>
#> <environment: 0x7faec2867820>
#> 
#> 
#> [[2]]
#> [[2]]$pdf
#> function (x) 
#> dstd(x, nu = nu[k])
#> <bytecode: 0x7faeb711e4a8>
#> <environment: 0x7faec2867200>
#> 
#> [[2]]$cdf
#> function (x) 
#> pstd(x, nu = nu[k])
#> <bytecode: 0x7faeb71220e0>
#> <environment: 0x7faec2867200>
#> 
#> [[2]]$rand
#> function (n) 
#> rstd(n, nu = nu[k])
#> <bytecode: 0x7faeb7121e08>
#> <environment: 0x7faec2867200>
#> 
#> [[2]]$logpdf
#> function (x) 
#> log(dstd(x, nu = nu[k]))
#> <bytecode: 0x7faeb7121b30>
#> <environment: 0x7faec2867200>
#> 
#> [[2]]$Fscore
#> function (x) 
#> -x * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71217e8>
#> <environment: 0x7faec2867200>
#> 
#> [[2]]$xFscore
#> function (x) 
#> -x^2 * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71210b0>
#> <environment: 0x7faec2867200>
#> 
#> [[2]]$Parscore
#> function (x) 
#> param_score_stdt(x, nu[k])
#> <bytecode: 0x7faeb71208d0>
#> <environment: 0x7faec2867200>
#> 
#> [[2]]$get_param
#> function () 
#> nu[k]
#> <bytecode: 0x7faeb7120630>
#> <environment: 0x7faec2867200>
#> 
#> [[2]]$set_param
#> function (x) 
#> nu[k] <<- x
#> <bytecode: 0x7faeb71204e0>
#> <environment: 0x7faec2867200>
#> 
#> [[2]]$any_param
#> function () 
#> param_flag
#> <bytecode: 0x7faeb7124070>
#> <environment: 0x7faec2867200>
#> 
#> [[2]]$show
#> function () 
#> paste("Student t with", format(nu[[k]], digits = 4), "df")
#> <bytecode: 0x7faeb7123f20>
#> <environment: 0x7faec2867200>
#> 
#> 
#> [[3]]
#> [[3]]$pdf
#> function (x) 
#> dstd(x, nu = nu[k])
#> <bytecode: 0x7faeb711e4a8>
#> <environment: 0x7faec2866be0>
#> 
#> [[3]]$cdf
#> function (x) 
#> pstd(x, nu = nu[k])
#> <bytecode: 0x7faeb71220e0>
#> <environment: 0x7faec2866be0>
#> 
#> [[3]]$rand
#> function (n) 
#> rstd(n, nu = nu[k])
#> <bytecode: 0x7faeb7121e08>
#> <environment: 0x7faec2866be0>
#> 
#> [[3]]$logpdf
#> function (x) 
#> log(dstd(x, nu = nu[k]))
#> <bytecode: 0x7faeb7121b30>
#> <environment: 0x7faec2866be0>
#> 
#> [[3]]$Fscore
#> function (x) 
#> -x * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71217e8>
#> <environment: 0x7faec2866be0>
#> 
#> [[3]]$xFscore
#> function (x) 
#> -x^2 * (1 + nu[k])/(x^2 + nu[k] - 2)
#> <bytecode: 0x7faeb71210b0>
#> <environment: 0x7faec2866be0>
#> 
#> [[3]]$Parscore
#> function (x) 
#> param_score_stdt(x, nu[k])
#> <bytecode: 0x7faeb71208d0>
#> <environment: 0x7faec2866be0>
#> 
#> [[3]]$get_param
#> function () 
#> nu[k]
#> <bytecode: 0x7faeb7120630>
#> <environment: 0x7faec2866be0>
#> 
#> [[3]]$set_param
#> function (x) 
#> nu[k] <<- x
#> <bytecode: 0x7faeb71204e0>
#> <environment: 0x7faec2866be0>
#> 
#> [[3]]$any_param
#> function () 
#> param_flag
#> <bytecode: 0x7faeb7124070>
#> <environment: 0x7faec2866be0>
#> 
#> [[3]]$show
#> function () 
#> paste("Student t with", format(nu[[k]], digits = 4), "df")
#> <bytecode: 0x7faeb7123f20>
#> <environment: 0x7faec2866be0>
#> 
#> 
noise_params(mo_tf)
#> [1] 20 30 40