R/methods.R

Defines functions print.sampling_plan summary.mle_fit print.mle_fit

Documented in print.mle_fit print.sampling_plan summary.mle_fit

#' Print Method for MLE Fit Objects
#'
#' @param x Object of class \code{mle_fit}.
#' @param ... Unused additional parameters.
#'
#' @return No return value, called for side effects.
#' @export
print.mle_fit <- function(x, ...) {
  cat("--- Maximum Likelihood Estimation Results ---\n")
  cat("Method: ", x$method, "\n")
  cat("Log-Likelihood: ", round(x$loglik, 4), "\n")
  cat("AIC: ", round(x$aic, 4), " | BIC: ", round(x$bic, 4), "\n\n")
  cat("Coefficients:\n")
  print(round(x$coefficients, 4))
  invisible(x)
}

#' Summary Method for MLE Fit Objects
#'
#' @param object Object of class \code{mle_fit}.
#' @param ... Unused additional parameters.
#'
#' @return A matrix summary of parameter estimates, standard errors, z-values, and p-values.
#' @export
summary.mle_fit <- function(object, ...) {
  coef_mat <- cbind(
    Estimate = object$coefficients,
    `Std. Error` = object$se,
    `z value` = object$z_values,
    `Pr(>|z|)` = object$p_values
  )
  cat("--- MLE Summary ---\n")
  cat("Optimization Method: ", object$method, "\n")
  print(round(coef_mat, 5))
  invisible(coef_mat)
}

#' Print Method for Bayesian Fit Objects
#'
#' @param x Object of class \code{bayes_fit}.
#' @param ... Unused parameters.
#'
#' @return No return value, called for side effects.
#' @export
print.bayes_fit <- function(x, ...) {
  cat("--- Bayesian Estimation Results ---\n")
  cat("Method: ", x$method, "\n")
  cat("Posterior Means:\n")
  print(round(x$post_means, 4))
  invisible(x)
}

#' Summary Method for Bayesian Fit Objects
#'
#' @param object Object of class \code{bayes_fit}.
#' @param ... Unused parameters.
#'
#' @return Summary table with posterior estimates and credible intervals.
#' @export
summary.bayes_fit <- function(object, ...) {
  if (!is.null(object$ci_lower)) {
    tab <- cbind(
      `Post Mean` = object$post_means,
      `2.5%` = object$ci_lower,
      `97.5%` = object$ci_upper
    )
  } else {
    tab <- cbind(`Post Mean` = object$post_means, `SE` = object$se)
  }
  cat("--- Bayesian Estimation Summary ---\n")
  cat("Method: ", object$method, "\n")
  print(round(tab, 5))
  invisible(tab)
}

#' Print Method for Sampling Plan Objects
#'
#' @param x Object of class \code{sampling_plan}.
#' @param ... Unused parameters.
#'
#' @return No return value, called for side effects.
#' @export
print.sampling_plan <- function(x, ...) {
  cat("--- Reliability Acceptance Sampling Plan ---\n")
  cat("Distribution: ", x$distribution, "\n")
  cat("Critical Value (c): ", round(x$critical_value, 4), "\n")
  if (!is.null(x$oc_AQL)) {
    cat("OC at AQL: ", round(x$oc_AQL, 4), " | OC at RQL: ", round(x$oc_RQL, 4), "\n")
  }
  invisible(x)
}

Try the CompRiskRel package in your browser

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

CompRiskRel documentation built on Aug. 5, 2026, 9:08 a.m.