Skip to content

Commit

Permalink
Add dishwash dataset (13)
Browse files Browse the repository at this point in the history
  • Loading branch information
ABohynDOE committed Jun 24, 2024
1 parent 178eb14 commit d5c84c9
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
25 changes: 25 additions & 0 deletions R/dishwash.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#' Comparing dish washing detergents
#'
#' An experiment was carried out to compare dish washing detergents. Standard
#' plates were soiled with standard dirt, and an operator then washed the plates
#' in a detergent solution one at a time. The response variable was the number
#' of plates washed before the foam disappeared. Three basins were set up, with
#' an operator for each, and the three Operators took care to wash at the same
#' rate. A different detergent was used in each basin. Thus the experimental
#' unit was a single washing-up session in one basin, and the units were grouped
#' in blocks of three (being the washing-up sessions carried out
#' simultaneously). Since there were nine detergents to compare in blocks of
#' size three, a balanced incomplete block design was used.
#'
#' @format A data frame with 36 rows and 3 columns:
#' \describe{
#' \item{block}{Washing up session. Factor with levels '1' to '12'}
#' \item{detergent}{Detergent brand. Factor with levels '1' to '9'}
#' \item{plates}{Number of plates washed until the foam disappeared}
#' }
#'
#' @example inst/examples/dishwash.R
#'
#' @source {John, P.W.M. (1961) \emph{An application of a balanced incomplete
#' block design}, Technometrics, 3, 51-54.}
"dishwash"
28 changes: 28 additions & 0 deletions data-raw/dishwash.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# DISHWASH - data raw
library(tidyverse)

dishwash <- readr::read_delim(
file = here::here("data-raw", "data-files", "dishwash.dat"),
col_types = c("i", rep("c", 9)),
col_names = c("block", paste0("detergent_", 1:9)),
delim = "\t"
) %>%
pivot_longer(
cols = starts_with("detergent"),
names_to = "detergent",
names_prefix = "detergent_",
values_to = "plates"
) %>%
mutate(
plates = str_remove_all(plates, "") %>% as.numeric(),
block = as_factor(block),
detergent = as_factor(detergent),
) %>%
filter(!is.na(plates)) %>%
labelled::set_variable_labels(
block = "Washing session",
detergent = "Detergent brand",
plates = "Number of plates washed"
)

usethis::use_data(dishwash, overwrite = TRUE)
Binary file added data/dishwash.rda
Binary file not shown.
24 changes: 24 additions & 0 deletions inst/examples/dishwash.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
library(dplyr)
library(tidyr)
library(gt)
library(hsds)

# Generate all possible cases of detergent and block, then add the recorded
# values from the experiment
all_cases <- dishwash %>%
expand(block, detergent) %>%
left_join(dishwash, by = join_by(block, detergent))

# Display as a visually appealling table, showing the incomplete blocked design
# structure
all_cases %>%
labelled::set_variable_labels(plates = NULL) %>%
pivot_wider(
names_from = "detergent",
values_from = "plates"
) %>%
gt() %>%
sub_missing() %>%
cols_label(block ~ "Block") %>%
tab_spanner("Detergent", columns = -block) %>%
cols_width(everything() ~ px(40))
60 changes: 60 additions & 0 deletions man/dishwash.Rd

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

0 comments on commit d5c84c9

Please sign in to comment.