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

Implement method to return a pretty table #22

Open
ellessenne opened this issue Feb 26, 2020 · 6 comments
Open

Implement method to return a pretty table #22

ellessenne opened this issue Feb 26, 2020 · 6 comments
Assignees

Comments

@ellessenne
Copy link
Owner

This would be based on reshaping the output of get_data() and pass it to knitr::kable, or something like that.

@ellessenne ellessenne self-assigned this Feb 26, 2020
ellessenne added a commit that referenced this issue Apr 8, 2020
@ge-li
Copy link

ge-li commented Sep 16, 2021

Hello, thanks for creating such an amazing package for summarizing simulation results. I saw this issue so I want to add a small suggestion here. It seems the print.summary.simsum() function will only print those nice tables but the summary tables are not returned. This is somewhat inconvenient for channeling the R output for other uses. I know I can extract the "tidy" long table from the summary object directly or use the tidy() function but they are not good for presentation purposes. What are your thoughts on this? Thank you very much!

@ellessenne
Copy link
Owner Author

Hi, thanks for your feedback!
Just to understand better your comment, would you like print.summary.simsum() to return the formatted tables that are printed to the R console?

@ge-li
Copy link

ge-li commented Sep 16, 2021

Yes. I'll be more specific. Allow me to explain.

Currently the print.summary.simsum() doesn't return anything other than printing the required summary tables. Personally, I think a better design is that it returns a (list) of summary data frames, maybe the output object in your code. I want this feature because such tables are better suited for presenting the results than the tidy format summary tables if I have a methodvar. And I cannot really use R's printed data frame conveniently for other purposes, e.g., making it into kables.

  ### If methodvar, put them side by side
  if (!is.null(x$methodvar)) {
    x$summ <- .bind_methods(data = x$summ, by = x$by, methodvar = x$methodvar)
  }

  ### Split by summary statistics for printing
  x$summ[["Performance Measure"]] <- droplevels(x$summ[["Performance Measure"]])
  output <- .split_by(data = x$summ, by = "Performance Measure")

  ### Print
  for (i in seq_along(output)) {
    cat(paste0("\n", names(output)[i], ":\n"))
    output[[i]][["Performance Measure"]] <- NULL
    print(output[[i]], row.names = FALSE)
  }

@ellessenne
Copy link
Owner Author

Aha, now I see – something like the example below?

library(rsimsum)
s2 <- simsum(data = relhaz, estvarname = "theta", true = -0.50, se = "se", methodvar = "model", by = c("baseline", "n"))
#> 'ref' method was not specified, Cox set as the reference
a <- print(summary(s2, stats = "bias"))
#> Values are:
#>  Point Estimate (Monte Carlo Standard Error)
#> 
#> Bias in point estimate:
#>     baseline   n              Cox              Exp            RP(2)
#>  Exponential  50  0.0215 (0.0328)  0.0239 (0.0326)  0.0183 (0.0331)
#>  Exponential 250 -0.0215 (0.0149) -0.0214 (0.0151) -0.0227 (0.0149)
#>      Weibull  50 -0.0282 (0.0311)  0.1509 (0.0204) -0.0348 (0.0311)
#>      Weibull 250 -0.0120 (0.0133)  0.1482 (0.0093) -0.0139 (0.0137)
library(knitr)
#> 
#> Attaching package: 'knitr'
#> The following object is masked from 'package:rsimsum':
#> 
#>     kable
kable(a[[1]], caption = names(a)[1], align = "r")
baseline n Cox Exp RP(2)
Exponential 50 0.0215 (0.0328) 0.0239 (0.0326) 0.0183 (0.0331)
Exponential 250 -0.0215 (0.0149) -0.0214 (0.0151) -0.0227 (0.0149)
Weibull 50 -0.0282 (0.0311) 0.1509 (0.0204) -0.0348 (0.0311)
Weibull 250 -0.0120 (0.0133) 0.1482 (0.0093) -0.0139 (0.0137)

Bias in point estimate

Created on 2021-09-16 by the reprex package (v2.0.1)

@ge-li
Copy link

ge-li commented Sep 16, 2021

Yes, that's fantastic!

@ellessenne
Copy link
Owner Author

Awesome! I just pushed this updated version to GitHub, you can try it out with:

library(remotes)
remotes::install_github("ellessenne/github")

Let me know your thoughts it you get the chance to play around with it! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants