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

ampute() now preserves the data structure #593

Merged
merged 2 commits into from
Oct 6, 2023
Merged
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
7 changes: 4 additions & 3 deletions R/ampute.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ ampute <- function(data, prop = 0.5, patterns = NULL, freq = NULL,
if (is.null(data)) {
stop("Argument data is missing, with no default", call. = FALSE)
}
data.in <- data # preserve an original set to inject the NA's in later
data <- check.dataform(data)
if (anyNA(data)) {
stop("Data cannot contain NAs", call. = FALSE)
Expand All @@ -218,7 +219,7 @@ ampute <- function(data, prop = 0.5, patterns = NULL, freq = NULL,
data <- data.frame(data)
if (any(vapply(data, Negate(is.numeric), logical(1))) && mech != "MCAR") {
data <- as.data.frame(sapply(data, as.numeric))
warning("Data is made numeric because the calculation of weights requires numeric data",
warning("Data is made numeric internally, because the calculation of weights requires numeric data",
call. = FALSE
)
}
Expand Down Expand Up @@ -454,7 +455,7 @@ ampute <- function(data, prop = 0.5, patterns = NULL, freq = NULL,
names(patterns.new) <- names(data)
names(weights) <- names(data)
call <- match.call()
missing.data <- data.frame(missing.data)
data.in[is.na(data.frame(missing.data))] <- NA
result <- list(
call = call,
prop = prop,
Expand All @@ -466,7 +467,7 @@ ampute <- function(data, prop = 0.5, patterns = NULL, freq = NULL,
std = std,
type = type,
odds = odds,
amp = missing.data,
amp = data.in,
cand = P - 1,
scores = scores,
data = as.data.frame(data)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ampute.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ test_that("function works around unusual arguments", {
# when data is categorical and mech != mcar, warning is expected
expect_warning(
ampute(data = nasty.data),
"Data is made numeric because the calculation of weights requires numeric data"
"Data is made numeric internally, because the calculation of weights requires numeric data"
)
# when data is categorical and mech = mcar, function can continue
expect_warning(ampute(data = nasty.data, mech = "MCAR"), NA)
Expand Down