TmixDist                package:tdist                R Documentation

_D_i_s_t_r_i_b_u_t_i_o_n _o_f _a _l_i_n_e_a_r _c_o_m_b_i_n_a_t_i_o_n _o_f _i_n_d_e_p_e_n_d_e_n_t _S_t_u_d_e_n_t'_s
_t-_v_a_r_i_a_b_l_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Characteristic function, density, distribution function, quantile
     function and random generation for the linear combination of
     independent Student's t random variables (with small degrees of
     freedom, df <= 100) and/or standard Normal Z random variables.

_U_s_a_g_e:

     ctdist(x, dff, lambda, pts =14)
     dtdist(x, dff, lambda, pts =14, log.d = FALSE)
     ptdist(q, dff, lambda, pts =14, lower.tail = TRUE, log.p = FALSE)
     qtdist(p, dff, lambda, pts =14, lower.tail = TRUE, log.p = FALSE)
     rtdist(n, dff, lambda)

_A_r_g_u_m_e_n_t_s:

     x,q: vector of quantiles. If 'x = numeric(0)', 'q = numeric(0)'
          then 'x', 'q' is generated automatically.

       p: vector of probabilities. If 'p = numeric(0)' then 'p' is
          generated automatically.

       n: number of observations. If 'length(n) > 1', the length is
          taken to be the number required.

     dff: vector of degrees of freedom of independent Student's t
          random variables, use 'Inf' as df's for the standard Normal
          random variables.

  lambda: vector of coefficients of the linear combination.

     pts: number of pts for Gaussian Quadrature. 
           By default 'pts = 14'. For many practical purposes, fast and
          reasonably precise results are for choice of pts as small as
          3.

   log.d: logical; if TRUE, 'dtdist' gives the logarithm of density.

   log.p: logical; if TRUE, probabilities p are given as log(p).

lower.tail: logical; if TRUE (default), probabilities are P[X <= x],
          otherwise, P[X > x].

_V_a_l_u_e:

     'ctdist' gives the characteristic function, 'dtdist' gives the
     density, 'ptdist' gives the distribution function, 'qtdist' gives
     the quantile function, and 'rdist' generates random deviates.

_A_u_t_h_o_r(_s):

     Alexander Savin savin@savba.sk and Viktor Witkovsky
     witkovsky@savba.sk, <URL: http://aiolos.um.savba.sk/~viktor/>.

_R_e_f_e_r_e_n_c_e_s:

     Witkovsky, V. (2001), On the exact computation of the density and
     of the quantiles of linear combinations of t and F random
     variables. _Journal of Statistical Planning and Inference_, 94,
     1-13.

     Witkovsky, V. (2004), Matlab algorithm TDIST: The distribution of
     a linear combination of Student's T random variables. _COMPSTAT
     2004, 16th Symposium of IASC PRAGUE, August 23-27_,
     Physica-Verlag/Springer 2004, 1995-2002.

_S_e_e _A_l_s_o:

     'tdist'

_E_x_a_m_p_l_e_s:

     # Plot the characteristic function of the random variable T = t_1 + t_2 + t_3,
     # where t_1, t_2, and t_3 are random variables with Student's t distribution
     # with 1, 2, and 3 degrees of freedom. The random variables are assumed to be
     # stochastically independent.

     tt = c(seq(0,.1,,100), seq(.1,7,,200))
     chf = ctdist(tt, c(1, 2, 3), c(1, 1, 1))
     plot(tt, chf, type = 'l')

     ###
     # Plot the pdf of the random variable T = ( Z + t_1 + t_10 )/3,
     # where Z is a random variable with standard normal distribution
     # and t_1 and t_10 are random variables with Student's t distribution
     # with 1 and 10 degrees of freedom. The random variables are assumed
     # to be stochastically independent.

     dff = c(Inf, 1, 10)
     lambda = c(1, 1, 1) / 3
     x = seq(-4,4,,100)
     pdf = dtdist(x, dff, lambda, 6)
     plot(x, pdf, type = 'l')

     ###
     # Plot the cdf of the random variable T = t_1 + 2*t_2 + 3*t_3 + 4*t_4 + Z,
     # where Z is a random variable with standard normal distribution
     # and t_1, t_2, t_3 and t_4 are random variables with Student's t distribution
     # with 1, 2, 3 and 4 degrees of freedom. The random variables are assumed
     # to be stochastically independent.

     dff = c(1, 2, 3, 4, Inf)
     lambda = c(1, 2, 3, 4, 1)
     x = seq(-36,36,,200)
     cdf = ptdist(x, dff, lambda)
     plot(x, cdf, type = 'l')

     ###
     # Calculate the quantiles (for given probabilities 0.9, 0.95, 0.99)
     # of the random variable  T = ( t_1 + Z )/2, where Z is a random variable
     # with standard normal distribution and t_1 is a random variable
     # with Student's t distribution with 1 degree of freedom. The random variables
     # are assumed to be stochastically independent.

     prob = c(0.9, 0.95, 0.99)
     quantiles = qtdist(prob, c(1, Inf), 1/2, 3)
     cbind(prob, quantiles)

     ###
     # Generate 1000 realization of the random variable  T = ( t_3 + t_5 + Z )/3,
     # where Z is a random variable with standard normal distribution and t_3 and t_5
     # are a random variable with Student's t distribution with 3 and 5 degrees
     # of freedom. The random variables are assumed to be stochastically independent.

     r = rtdist(1000, c(3, 5, Inf), 1/3)

     # Plot the binned kernel density estimate of the probability density of the
     # generated data by 'bdke' procedure and compare with true density (red line).

     library(KernSmooth)
     est <- bkde(r, bandwidth=0.25)
     plot(est, ylim = c(-0, .6), type="l")
     lines(est$x,dtdist(est$x, c(3, 5, Inf), 1/3), col = 'red')

