Skip to content

Commit

Permalink
final version of the summary and print.summary method
Browse files Browse the repository at this point in the history
  • Loading branch information
BERENZ committed Mar 8, 2025
1 parent 94f33f9 commit 7dcb281
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 14 deletions.
23 changes: 13 additions & 10 deletions R/prints.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ print.nonprob_summary <- function(x,
digits, as.numeric(x$ps_scores_nonprob["Median"]),
digits, as.numeric(x$ps_scores_nonprob["Max."])))

if (!is.null(x$ps_scores_prob)) {
if (!x$no_prob) {
cat(" - distribution of IPW probabilities (prob sample):\n")
cat(sprintf(
" - min: %.*f; mean: %.*f; median: %.*f; max: %.*f\n",
Expand Down Expand Up @@ -181,16 +181,19 @@ print.nonprob_summary <- function(x,
digits, as.numeric(x$ys_nons_pred[[y]]["Max."])))
}

cat(" - distribution of outcome predictions (prob sample):\n")
for (y in 1:length(x$ys_rand_pred)) {
cat(sprintf(
" - %s: min: %.*f; mean: %.*f; median: %.*f; max: %.*f\n",
names(x$ys_rand_pred)[y],
digits, as.numeric(x$ys_rand_pred[[y]]["Min."]),
digits, as.numeric(x$ys_rand_pred[[y]]["Mean"]),
digits, as.numeric(x$ys_rand_pred[[y]]["Median"]),
digits, as.numeric(x$ys_rand_pred[[y]]["Max."])))
if (!x$no_prob) {
cat(" - distribution of outcome predictions (prob sample):\n")
for (y in 1:length(x$ys_rand_pred)) {
cat(sprintf(
" - %s: min: %.*f; mean: %.*f; median: %.*f; max: %.*f\n",
names(x$ys_rand_pred)[y],
digits, as.numeric(x$ys_rand_pred[[y]]["Min."]),
digits, as.numeric(x$ys_rand_pred[[y]]["Mean"]),
digits, as.numeric(x$ys_rand_pred[[y]]["Median"]),
digits, as.numeric(x$ys_rand_pred[[y]]["Max."])))
}
}

} else {
cat(" - distribution of outcome predictions:\n")
cat(" too many variables (more than 5). Details are stored in the `ys_nons_pred` and `ys_rand_pred` elements.")
Expand Down
44 changes: 41 additions & 3 deletions R/summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,48 @@
#'
#' @return An object of \code{nonprob_summary} class containing:
#' \itemize{
#' \item \code{call}
#' \item {\code{call} call}
#' \item {\code{estimator} type of estimator}
#' \item {\code{control} list of controls}
#' \item {\code{ipw_weights} estimated IPW weights}
#' \item {\code{ipw_weights_total} estimated IPW total (sum)}
#' \item {\code{ps_scores_nonprob} estimated propensity scores for non-probability sample}
#' \item {\code{ps_scores_prob} estimated propensity scores for probability sample}
#' \item {\code{case_weights} case weights}
#' \item {\code{output} estimated means and standard errors}
#' \item {\code{SE} estimated standard errors of V1 and V2}
#' \item {\code{confidence_interval} confidence intervals}
#' \item {\code{nonprob_size} size of the non-probability sample}
#' \item {\code{prob_size} size of the probability sample}
#' \item {\code{pop_size} population size}
#' \item {\code{pop_size_fixed} whether the population size is treated as fixed}
#' \item {\code{no_prob} whether probability sample was provided}
#' \item {\code{outcome} model details}
#' \item {\code{selection} selection details}
#' \item {\code{estimator_method} estimator method}
#' \item {\code{selection_formula} selection formula}
#' \item {\code{outcome_formula} outcome formula}
#' \item {\code{vars_selection} whether variable selection algorithm was applied}
#' \item {\code{vars_outcome} variables of the outcome models}
#' \item {\code{ys_rand_pred} predicted values for the random sample (if applies)}
#' \item {\code{ys_nons_pred} predicted values for the non-probability sample}
#' \item {\code{ys_resid} residuals for the non-probability sample}
#' }
#'
#' @examples
#'
#' data(admin)
#' data(jvs)
#'
#' jvs_svy <- svydesign(ids = ~ 1, weights = ~ weight,
#' strata = ~ size + nace + region, data = jvs)
#'
#' ipw_est1 <- nonprob(selection = ~ region + private + nace + size,
#' target = ~ single_shift,
#' svydesign = jvs_svy,
#' data = admin, method_selection = "logit"
#' )
#' summary(ipw_est1)
#'
#' @method summary nonprob
#' @exportS3Method
Expand Down Expand Up @@ -46,13 +85,12 @@ summary.nonprob <- function(object, ...) {
prob_size = object$prob_size,
pop_size = object$pop_size,
pop_size_fixed = object$pop_size_fixed,
no_prob = is.null(object$svydesign),
outcome = object$outcome,
selection = object$selection,
estimator_method = object$estimator_method,
selection_formula = object$selection_formula,
outcome_formula = object$outcome_formula,
outcome = object$outcome,
selection = object$selection,
vars_selection = names(object$selection$coefficients),
vars_outcome = lapply(object$outcome, function(x) names(x$coefficients)),
ys_rand_pred = summary_ys_rand_pred,
Expand Down
43 changes: 42 additions & 1 deletion man/summary.nonprob.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7dcb281

Please sign in to comment.