[R] Help with reading code

Dana77 luckyinwind at yahoo.com
Thu Dec 4 00:24:17 CET 2008


I would like to give out the equation for calculating the maximum likelihood.
Below is the code, but I still have problems with it.  After I read the
code, I found there are two cases for "w(weights)".  If  "w" is not zero,
then the equation is given as "val <- 0.5 * (sum(log(w)) - N * (log(2 * pi)
+ 1 - log(N) + 
        log(sum(w * res^2))))". However, if "w" is zero, then I do not know
what equation it should be since it does not make any sense for "log0". Hope
someone can help me to figure this out. Thanks!




function (object, REML = FALSE, ...) 
{
    res <- object$residuals
    p <- object$rank
    N <- length(res)
    if (is.null(w <- object$weights)) {
        w <- rep.int(1, N)
    }
    else {
        excl <- w == 0  #####I can not understand the following lines after
this. 
        if (any(excl)) {
            res <- res[!excl]
            N <- length(res)
            w <- w[!excl]        }
    }
    N0 <- N
    if (REML) 
        N <- N - p
    val <- 0.5 * (sum(log(w)) - N * (log(2 * pi) + 1 - log(N) + 
        log(sum(w * res^2))))
    if (REML) 
        val <- val - sum(log(abs(diag(object$qr$qr)[1:p])))
    attr(val, "nall") <- N0
    attr(val, "nobs") <- N
    attr(val, "df") <- p + 1
    class(val) <- "logLik"
    val
}


Best,

Dana
-- 
View this message in context: http://www.nabble.com/Help-with-reading-code-tp20823979p20823979.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list