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

diff functions #404

Merged
merged 14 commits into from Mar 4, 2019
Merged

diff functions #404

merged 14 commits into from Mar 4, 2019

Conversation

graemeblair
Copy link
Member

  • added five functions
    • compare_design_code which does diff of code
    • compare_design_estimates which runs draw_estimates(design) and then does a diff of the output
    • compare_design_estimands which runs draw_estimands(design) and then does a diff of the output
    • compare_design_data which runs draw_data(design) and then does a diff of the output
    • compare_design_summaries which runs summary(design) and then does a diff of the output

and an omnibus function that runs them all one by one with section headers in between - compare_designs

set.seed(seed)
design1 <- draw_data(design1)
set.seed(seed)
design2 <- draw_data(design2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One cute thing would be if the ending .Random.seed was the same after two draws - if not, then you know the designs had different access patterns to the RNG.

@coveralls
Copy link

coveralls commented Feb 28, 2019

Coverage Status

Coverage decreased (-0.7%) to 94.66% when pulling 9383828 on diff_design_code into 5a6ae9e on master.

#' @rdname compare_functions
#' @importFrom diffobj diffChr
#' @export
compare_design_summaries <- function(design1, design2, format = "ansi256", mode = "sidebyside", pager = "off", context = -1L) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this family of functions, parameterize by the comparison function:

compare_design_generic <- function(FUN, design1, design2, format = "ansi256", ...){
  seed <- .Random.seed
  x <- FUN(design1)
  set.seed(seed)
  y <- FUN(design2)
 
  #etc
}
compare_design_summaries <- stackoverflow::partial(compare_design_generic, FUN=function(x) capture.output(summary(x)))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also parameterize DIFF_FUN.

}

get_design_code <- function(design){
sapply(design, function(x) clean_call(attributes(x)$call))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attr(x, "call")

print.design_comparison <- function(x, ...) {
cat("Research design comparison\n\n")

print_console_header("Compare design code")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a list, eg

labels = c("code_comparison"="design code", "data_comparison" = "draw_data(design)")

for(n in names(labels)) {
  print_console_header(paste("Compare", labels[n))
  print(x[[n]])
}


estimands_comparison <- compare_design_estimands(design1, design2, format = format, mode = mode, pager = pager, context = context)

estimates_comparison <- compare_design_estimates(design1, design2, format = format, mode = mode, pager = pager, context = context)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eek. Use a list to cut down on verbosity.

fns <- list(code_comparison=compare_design_code, data_comparison=compare_design_data, ...)

vals <- lappy(fns, function(f) f(design1, design2, format=format, mode=mode, pager=pager, context=context)

class(vals) <- "design_comparison"
vals

@graemeblair graemeblair merged commit f4468d5 into master Mar 4, 2019
@graemeblair graemeblair deleted the diff_design_code branch March 4, 2019 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants