logLik                 package:VLMC                 R Documentation

_L_o_g _L_i_k_e_l_i_h_o_o_d _o_f _a_n_d _b_e_t_w_e_e_n _V_L_M_C _o_b_j_e_c_t_s

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

     Compute the log-likelihood or ``entropy'' of a fitted 'vlmc'
     object.  This is a method for the generic 'logLik'.

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

     entropy(object)
     ## S3 method for class 'vlmc':
     logLik(object, ...)
     entropy2(ivlmc1, ivlmc2, alpha.len = ivlmc1[1])

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

  object: typically the result of 'vlmc(..)'.

ivlmc1,ivlmc2: two 'vlmc' (sub) trees, see 'vlmc'.

alpha.len: positive integer specifying the alphabet length.

     ...: (potentially more arguments; required by generic)

_D_e_t_a_i_l_s:

     The 'logLik.vlmc()' method computes the log likelihood for a
     fitted 'vlmc' object.  'entropy' is an alias for 'logLik' for
     reasons of back compatibility.

     'entropy2' is less clear ... ... [[[ FIXME ]]] ... ...

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

     a negative number, in some contexts typically further divided by
     'log(x$alpha.len)'.

     Note that the 'logLik' method is used by the default method of the
     'AIC' generic function (from R version 1.4.x), and hence provides
     'AIC(object)' for vlmc objects.

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

     Martin Maechler

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

     'deviance.vlmc', 'vlmc', 'draw.vlmc'.

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

     dd <- cumsum(rpois(999, 1.5)) %% 10
     (vd <- vlmc(dd))
     logLik(vd)

     ## AIC model selection:
     f1 <- c(1,0,0,0)  # as in example(vlmc)
     f2 <- rep(1:0,2)
     (dt1 <- c(f1,f1,f2,f1,f2,f2,f1))
     AIC(print(vlmc(dt1)))
     AIC(print(vlmc(dt1, cutoff = 2.6)))
     AIC(print(vlmc(dt1, cutoff = 0.4)))# these two differ ``not really''
     AIC(print(vlmc(dt1, cutoff = 0.1)))

     ## Show how to compute it from the fitted conditional probabilities :
     logLikR <- function(x) {
         dn <- dimnames(pr <- predict(x))
         sum(log(pr[cbind(2:nrow(pr), match(dn[[1]][-1], dn[[2]]))]))
     }

     all.equal(  logLikR(vd),
               c(logLik (vd)), tol=1e-10) # TRUE, they do the same

     ## Compare different ones:  [cheap example]:
     example(draw)
     for(n in ls())
       if(is.vlmc(get(n))) {
            vv <- get(n)
            cat(n,":",formatC(logLik(vv) / log(vv$alpha.len),
                              format= "f", wid=10),"\n")
       }

