R/anova.llra.R

Defines functions anova.llra

Documented in anova.llra

#anova.llra <- function(object, ...) UseMethod("anova.llra")

anova.llra <- function(object,...)
  {
    objets <- list(object, ...)
    isllra <- unlist(lapply(objets, function(x) "llra" %in% class(x)))

    ## checks
    if (!all(isllra)) {
        objets <- objets[isllra]
        warning("non-LLRA-model(s) removed")
    }
    dimdata <- dim(objets[[1L]]$X)
    samedata <- unlist(lapply(objets, function(x) all(dim(x$X)==dimdata)))
    if (!all(samedata))
        stop("models were not all fitted to the same size of dataset")

    nmodels <- length(objets)
    logliks <- as.numeric(lapply(objets, function(x) x$loglik))
    npars <- as.numeric(lapply(objets, function(x) x$npar))
    nparsS <- npars[order(npars)]
    logliksS <- logliks[order(npars)]
    lrstat <-c(NA,2*abs(diff(logliksS)))
    dfs <- c(NA,abs(diff(nparsS)))
    ps <- 1-pchisq(lrstat,dfs)
    tbl <- data.frame(nparsS, logliksS, dfs, lrstat, ps)
    dimnames(tbl) <- list(1L:nmodels, c("Npar", "logLik", "df", "-2LR","Asymp.p-Value"))
    title <- "Analysis of Deviance Table\n"
    structure(tbl, heading = title, class = c("anova",
        "data.frame"))
}

Try the eRm package in your browser

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

eRm documentation built on May 29, 2024, 2:12 a.m.