R/summary.rsf.R

summary.rsf <-
function (object, type, ...)
{
    boot <- object$bootstrap
    if (missing(type)) {
        type <- if (is.null(boot))
        "mle" else "boot"
    }
    type <- match.arg(type, c("mle", "boot"))
    if (type == "boot" && is.null(boot))
        stop("cannot provide Bootstrap type summary")
    if (type != "boot")
        boot <- NULL

    k <- length(object$coefficients)
    coefs <- coef(object)
    se <- if (type == "boot")
        apply(boot, 1, sd) else object$std.error
    tstat <- coefs/se
#    pval <- 2 * pt(abs(tstat), object$df.residual, lower.tail = FALSE)
    ## z test because no overdspersion
    pval <- 2 * pnorm(-abs(tstat))
    coefs <- cbind(coefs, se, tstat, pval)
#    colnames(coefs) <- c("Estimate", "Std. Error", "t value", "Pr(>|t|)")
    colnames(coefs) <- c("Estimate", "Std. Error", "z value", "Pr(>|z|)")
    coefs <- coefs[seq_len(k), , drop = FALSE]
    rownames(coefs) <- names(coef(object))

    if (identical(object$m, 0)) {
        omega <- sum(object$y)/length(object$y)
        alpha <- mean(fitted(object, "avail"))
        fit <- fitted(object, "all")
        p <- (omega * fit) / (omega * fit + (1-omega)*alpha)
        hl <- try(hoslem.test(object$y, p))
        if (inherits(hl, "try-error")) {
            warning("Hosmer and Lemeshow test cannot be calculated")
            hl <- NULL
        }
    } else hl <- NULL

    out <- list(call = object$call, coefficients=coefs, loglik = object$loglik,
        converged = object$converged, m = object$m, fitted.values = object$fitted.values,
        control = object$control, link = object$link, terms = object$terms,
        bootstrap=boot, type=type, B=ncol(object$bootstrap)-1, np=object$np, bic=BIC(object),
        hoslem.test=hl)
#    out$hoslem.test <- NULL
    class(out) <- "summary.rsf"
    return(out)
}

Try the ResourceSelection package in your browser

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

ResourceSelection documentation built on July 9, 2023, 5:58 p.m.