Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for degrees of freedom to sdc_model() (#87) #98

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(print,sdc_descriptives)
S3method(print,sdc_dfs)
S3method(print,sdc_distinct_ids)
S3method(print,sdc_dominance)
S3method(print,sdc_min_max)
Expand All @@ -13,6 +14,7 @@ export(sdc_min_max)
export(sdc_model)
import(mathjaxr)
importFrom(broom,augment)
importFrom(broom,glance)
importFrom(broom,tidy)
importFrom(checkmate,assert_character)
importFrom(checkmate,assert_data_frame)
Expand Down
14 changes: 14 additions & 0 deletions R/print_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ print.sdc_dominance <- function(x, ...) {

}

#' @importFrom cli cli_alert_danger cli_alert_success
#' @export
print.sdc_dfs <- function(x, ...) {
# with problems
if (x <= getOption("sdc.n_df", 10L)) {
cli::cli_alert_danger("Not enough degrees of freedom: {x}")

# withOUT problems
} else if (getOption("sdc.info_level", 1L) > 1L) {
cli::cli_alert_success("No problem with degrees of freedom ({x}).")
}
}


#' @importFrom cli cli_text style_bold
#' @export
Expand Down Expand Up @@ -127,6 +140,7 @@ print.sdc_model <- function(x, ...) {
print(x[["settings"]])

print(x[["distinct_ids"]])
print(x[["dfs"]])
if (getOption("sdc.info_level", 1L) <= 1L) {
print_fun <- conditional_print
} else {
Expand Down
16 changes: 15 additions & 1 deletion R/sdc_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @importFrom data.table is.data.table as.data.table fsetequal rbindlist :=
#' %flike% set
#' @importFrom broom augment tidy
#' @importFrom broom augment tidy glance
#' @importFrom stats model.frame na.omit
#' @importFrom checkmate assert_data_frame assert_string
#'
Expand Down Expand Up @@ -93,6 +93,19 @@ sdc_model <- function(data, model, id_var = getOption("sdc.id_var"), fill_id_var
)
}

# check degrees of freedom ----
dfs <- structure(
broom::glance(model)[["df.residual"]],
class = c("sdc_dfs", "integer")
)
if (dfs <= getOption("sdc.n_df", 10L)) {
cli::cli_warn(paste(
cli::style_bold("DISCLOSURE PROBLEM:"),
"Not enough degrees of freedom."
))
}


model_dt <- stats::na.omit(data[, c(id_var, model_vars), with = FALSE])


Expand Down Expand Up @@ -201,6 +214,7 @@ sdc_model <- function(data, model, id_var = getOption("sdc.id_var"), fill_id_var
options = list_options(),
settings = list_arguments(id_var = id_var, fill_id_var = fill_id_var),
distinct_ids = distinct_ids,
dfs = dfs,
terms = term_list
),
class = c("sdc_model", "list")
Expand Down
Loading