Skip to content

Commit

Permalink
report_statistics.compare_performance
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Dec 22, 2020
1 parent b765715 commit f86efc1
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ S3method(report_parameters,anova)
S3method(report_parameters,aov)
S3method(report_parameters,aovlist)
S3method(report_parameters,character)
S3method(report_parameters,compare_performance)
S3method(report_parameters,data.frame)
S3method(report_parameters,default)
S3method(report_parameters,factor)
Expand All @@ -119,6 +120,7 @@ S3method(report_parameters,stanreg)
S3method(report_parameters,survreg)
S3method(report_parameters,zeroinfl)
S3method(report_performance,MixMod)
S3method(report_performance,compare_performance)
S3method(report_performance,default)
S3method(report_performance,glm)
S3method(report_performance,glmmTMB)
Expand All @@ -142,6 +144,7 @@ S3method(report_statistics,anova)
S3method(report_statistics,aov)
S3method(report_statistics,aovlist)
S3method(report_statistics,character)
S3method(report_statistics,compare_performance)
S3method(report_statistics,data.frame)
S3method(report_statistics,default)
S3method(report_statistics,factor)
Expand Down Expand Up @@ -188,6 +191,7 @@ S3method(report_text,aovlist)
S3method(report_text,bayesfactor_inclusion)
S3method(report_text,bayesfactor_models)
S3method(report_text,character)
S3method(report_text,compare_performance)
S3method(report_text,data.frame)
S3method(report_text,default)
S3method(report_text,factor)
Expand Down
103 changes: 101 additions & 2 deletions R/report.compare_performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#' @param x Object of class \code{NEW OBJECT}.
#' @inheritParams report
#' @inheritParams report.lm
#'
#' @inherit report return seealso
#'
Expand All @@ -21,18 +22,116 @@
#' # summary(r)
#' # as.data.frame(r)
#' # summary(as.data.frame(r))
#'
#' # Specific reports
#' report_table(x)
#' report_statistics(x)
#' report_parameters(x)
#' }
#'
#' @export
report.compare_performance <- function(x, ...) {
print("Support for compare_performance not fully implemented yet :(")
text <- report_text(x, ...)
table <- report_table(x, ...)
as.report(text = text, table = table, ...)
}

# report_table ------------------------------------------------------------

#' @rdname report.compare_performance
#' @export
report_table.compare_performance <- function(x, ...) {
table <- x
table_short <- x
table_short <- x[!names(x) %in% c("Type", "Sigma")]
as.report_table(table, summary = table_short)
}


# report_statistics ------------------------------------------------------------

#' @rdname report.compare_performance
#' @export
report_statistics.compare_performance <- function(x, table = NULL, ...) {
if (is.null(table)) {
table <- report_table(x, ...)
}

text <- text_short <- ""
if("R2" %in% names(table)){
text <- text_paste(text, paste0("R2 = ", insight::format_value(table$R2)))
if("R2_adjusted" %in% names(table)){
text <- text_paste(text, paste0("adj. R2 = ", insight::format_value(table$R2_adjusted)))
text_short <- text_paste(text_short, paste0("adj. R2 = ", insight::format_value(table$R2_adjusted)))
} else{
text_short <- text_paste(text, paste0("R2 = ", insight::format_value(table$R2)))
}
}
if("AIC" %in% names(table)){
text <- text_paste(text, paste0("AIC = ", insight::format_value(table$AIC)))
}
if("BIC" %in% names(table)){
text <- text_paste(text, paste0("BIC = ", insight::format_value(table$BIC)))
text_short <- text_paste(text_short, paste0("BIC = ", insight::format_value(table$BIC)))
}
if("WAIC" %in% names(table)){
text <- text_paste(text, paste0("WAIC = ", insight::format_value(table$WAIC)))
text_short <- text_paste(text_short, paste0("WAIC = ", insight::format_value(table$WAIC)))
}
if("RMSE" %in% names(table)){
text <- text_paste(text, paste0("RMSE = ", insight::format_value(table$RMSE)))
}
if("Sigma" %in% names(table)){
text <- text_paste(text, paste0("Sigma = ", insight::format_value(table$Sigma)))
}

as.report_statistics(text, summary = text_short, table = table)
}

# report_parameters ------------------------------------------------------------

#' @rdname report.compare_performance
#' @export
report_parameters.compare_performance <- function(x, table = NULL, ...) {
stats <- report_statistics(x, table = table, ...)
table <- attributes(stats)$table

text <- paste0(table$Model, " (", stats, ")")
text_short <- paste0(table$Model, " (", summary(stats), ")")

as.report_parameters(text, summary = text_short, table = table)
}


# report_performance ------------------------------------------------------------

#' @rdname report.compare_performance
#' @export
report_performance.compare_performance <- function(x, table = NULL, ...) {
stats <- report_statistics(x, table = table, ...)
table <- attributes(stats)$table

models <- table$Model
if("BF" %in% names(table)){
bfs <- effectsize::interpret_bf(table$BF, include_value = TRUE)[-1]
text <- paste0(
"Compared to ",
models[1],
", "
)
}

as.report_performance(text, summary = text, table = table)
}




# report_text ------------------------------------------------------------

#' @rdname report.compare_performance
#' @export
report_text.compare_performance <- function(x, ...) {
text <- "Something"
text_short <- "Something"
as.report_text(text, summary = text_short)
}
4 changes: 4 additions & 0 deletions R/report.lavaan.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
#' model <- lavaan::sem(structure, data = PoliticalDemocracy)
#' r <- report(model)
#' r
#' # summary(r)
#' # as.data.frame(r)
#' # summary(as.data.frame(r))
#'
#' # Specific reports
#' report_table(model)
#' report_performance(model)
#' }
Expand Down
2 changes: 2 additions & 0 deletions man/report.Rd

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

2 changes: 2 additions & 0 deletions man/report.aov.Rd

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

2 changes: 2 additions & 0 deletions man/report.bayesfactor_models.Rd

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

21 changes: 21 additions & 0 deletions man/report.compare_performance.Rd

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

2 changes: 2 additions & 0 deletions man/report.default.Rd

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

2 changes: 2 additions & 0 deletions man/report.htest.Rd

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

6 changes: 6 additions & 0 deletions man/report.lavaan.Rd

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

2 changes: 2 additions & 0 deletions man/report.lm.Rd

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

4 changes: 3 additions & 1 deletion man/report.stanreg.Rd

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

2 changes: 2 additions & 0 deletions man/report_date.Rd

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

0 comments on commit f86efc1

Please sign in to comment.