Skip to content

fixed plot_acf() factor issue #159 #160

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: auditor
Title: Model Audit - Verification, Validation, and Error Analysis
Version: 1.3.4
Version: 1.3.5
Authors@R: c(
person("Alicja", "Gosiewska", email = "alicjagosiewska@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-6563-5742")),
Expand All @@ -10,7 +10,8 @@ Authors@R: c(
comment = c(ORCID = "0000-0001-6661-5364")),
person("Tomasz", "Mikołajczyk", role = c("aut")),
person("Michal", "Burdukiewicz", role = c("ctb")),
person("Szymon", "Maksymiuk", role = c("ctb"))
person("Szymon", "Maksymiuk", role = c("ctb")),
person("Michal", "Kaminski", role = c("ctb"))
)
Description: Provides an easy to use unified interface for creating validation plots for any model.
The 'auditor' helps to avoid repetitive work consisting of writing code needed to create residual plots.
Expand Down
10 changes: 7 additions & 3 deletions R/plot_acf.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ plot_acf <- function(object, ..., variable = NULL, alpha = 0.95) {
# data frame for ggplot object
df <- make_dataframe(object, ..., variable = variable, type = "res")

result_df <- data.frame(acf = numeric(), label = character(), lag = numeric(), ymin = numeric())
for (label in unique(df$`_label_`)) {

result_df <- data.frame(acf = numeric(), label = factor(), lag = numeric(), ymin = numeric())

label_levels <- levels(df$`_label_`)

for (label in label_levels) {
orderedResiduals <- df[which(df$`_label_` == label), "_residuals_"]
acf <- acf(orderedResiduals, plot = FALSE)
result_df <- rbind(result_df, data.frame(acf = acf$acf[-1], label = label, lag = acf$lag[-1], ymin = 0))
result_df <- rbind(result_df, data.frame(acf = acf$acf[-1], label = factor(label, levels = label_levels), lag = acf$lag[-1], ymin = 0))
}

df <- result_df
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/objects_for_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ model_class_glm2 <- glm(factor(y) ~ x3, family=binomial, data=artifficial_classi
exp_class_glm2 <- explain(model_class_glm2, data = artifficial_classif, y = artifficial_classif$y, verbose = FALSE)
exp_lm <- explain(model_lm, label = "lm", data = artifficial_regr, y = artifficial_regr$y, verbose = FALSE)
exp_glm <- explain(model_glm, label = "glm", data = artifficial_classif_2, y = artifficial_classif_2$y, verbose = FALSE)
exp_glm2 <- explain(model_glm, label = "glm2", data = artifficial_classif_2, y = artifficial_classif_2$y, verbose = FALSE)
exp_rf <- explain(model_rf, label="rf", data =artifficial_classif_2, y = artifficial_classif_2$y, verbose = FALSE)
exp_class_glm <- explain(model_class_glm, label="class glm", data = artifficial_classif, y = artifficial_classif$y, verbose = FALSE)

mr_rf <- model_residual(exp_rf)
mr_glm <- model_residual(exp_glm)
mr_glm2 <- model_residual(exp_glm2)

cd_lm <- model_cooksdistance(exp_lm)
cd_rf <- model_cooksdistance(exp_rf)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_plotsR.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test_that("plot_acf", {
expect_is(plot_acf(mr_rf, variable = "_y_"), "gg")
expect_is(plot_acf(mr_rf, variable = "_y_hat_"), "gg")
expect_is(plot_acf(mr_rf), "gg")
expect_error(plot_acf(mr_rf, mr_glm, mr_glm2), NA)
})

test_that("plot_autocorrelation", {
Expand Down