R/summary_a90logit.R

Defines functions summary.a90logit

Documented in summary.a90logit

#' @title Object summaries of logistic regression model for capture-recaputre
#' data and its display
#'
#' @description \code{summary} is a generic function for summarizing results
#' produced from logistic regression model with maximum likelihood
#' estimation.
#' Using the estimates of fitted object \code{obj}, the size of
#' unknown population \code{N} and its \code{100*(1-alpha)} confidence
#' interval are calculated.
#'  
#' @param object a fitted model object,
#' @param alpha a confidence level required (\code{alpha=0.05} by
#' default), 
#' @param k an integer, the penalty per parameter to be used; the
#' \code{k=2} is used for classical AIC (Akaike's information
#' criteria), 
#' @param ... other arguments
#'
#' @return An object of class \code{summary.a90logit} with components
#' including
#' \item{tab}{Formatted object to be printed including coefficients,
#' standard errors, etc.  Significance star is also printed with stars,}
#' \item{aic}{Akaike Information Criteria,}
#' \item{N}{Estimate of unknown population size,}
#' \item{VarN}{Variance of \code{N},}
#' \item{ciu}{Upper bound of confidence interval,}
#' \item{cil}{Lower bound of confidence interval.}
#'
#' @seealso \code{\link{AIC}}, \code{\link{extractAIC}}, \code{\link{printCoefmat}}
#' @name summary.a90logit
#' @aliases print.summary.a90logit
#'
#' @note \code{print.summary.a90logit} is a generic function that displays
#' all summaries of object generated from \code{summary.a90logit}.
#' 
#' @author Chel Hee Lee <gnustats@@gmail.com>
#' @method summary a90logit
#' @S3method summary a90logit
summary.a90logit <- function(object, alpha=0.05, k=2, ...){

  obj <- object

  cfs <- obj$cfs
  vcv <- obj$vcv
  se <- sqrt(diag(vcv))
  phi <- obj$phi
  Xa <- obj$Xa
  tmat <- obj$tmat
  XX <- obj$XX
  llik <- obj$llik
  npars <- length(obj$cfs)

  z <- cfs/se
  pval <- 2*pnorm(-abs(z))
  tab <- cbind(cfs, se, z, pval)
  colnames(tab) <- c("Estimate", "SE", "z-score", "Pr(>|z|)")
  obj$tab <- tab

  obj$aic <- aic <- -2*llik + k*npars
 
  obj$N <- N <- sum(1/phi)
  k.theta <- apply(exp(as.matrix(t(apply(Xa, 1, function(x)
  apply(tmat, 1, function(t) t %*% x) )))), 1, sum)
  psi1 <- apply(Xa, 1, function(x) exp(x[1])*(1+exp(x[2])))
  psi2 <- apply(Xa, 1, function(x) exp(x[2])*(1+exp(x[1])))
  psi <- c(psi1, psi2)/k.theta^2
  V2 <- t(psi) %*% XX %*% vcv %*% t(XX) %*% psi
  V3 <- sum((1-phi)/(phi^2))
  obj$VarN <- VarN <- V2+V3
  obj$ciu <- N + qnorm(1-alpha/2)*sqrt(VarN)
  obj$cil <- N + qnorm(alpha/2)*sqrt(VarN)
  obj$alpha <- alpha
  
  class(obj) <- c("summary.a90logit")
  return(obj)
}
NULL

Try the ipeglim package in your browser

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

ipeglim documentation built on May 2, 2019, 4:31 p.m.