From bbf07d8da9e05353427e5476a541e2fe705fac58 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 26 Nov 2021 19:39:55 +0100 Subject: [PATCH] closes #474 - style NEWS and code - spell check --- NAMESPACE | 5 + NEWS.md | 120 +++++++------- R/compute_variances.R | 10 +- R/get_predicted.R | 2 +- R/get_predicted_ci.R | 6 +- R/standardize_column_order.R | 153 ++++++++++++++++++ R/standardize_names.R | 46 +++--- R/utils_get_data.R | 1 - _pkgdown.yml | 1 + inst/WORDLIST | 1 + man/standardize_column_order.Rd | 60 +++++++ tests/testthat/test-brms.R | 1 - .../testthat/test-standardize_column_order.R | 38 +++++ 13 files changed, 355 insertions(+), 89 deletions(-) create mode 100644 R/standardize_column_order.R create mode 100644 man/standardize_column_order.Rd create mode 100644 tests/testthat/test-standardize_column_order.R diff --git a/NAMESPACE b/NAMESPACE index 4a1189118..ada9c28bb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1388,6 +1388,10 @@ S3method(print,get_predicted) S3method(print,insight_table) S3method(print_html,data.frame) S3method(print_md,data.frame) +S3method(standardize_column_order,data.frame) +S3method(standardize_column_order,effectsize_table) +S3method(standardize_column_order,parameters_distribution) +S3method(standardize_column_order,parameters_model) S3method(standardize_names,data.frame) S3method(standardize_names,default) S3method(standardize_names,effectsize_table) @@ -1489,5 +1493,6 @@ export(print_colour) export(print_html) export(print_md) export(print_parameters) +export(standardize_column_order) export(standardize_names) export(supported_models) diff --git a/NEWS.md b/NEWS.md index 9ed8c570f..b307b8e6a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,16 +9,22 @@ * Support for `bfsl` (*bfsl*) +## New functions + +* New `standardize_column_order()` function can be used to standardize the + column order in output dataframes. + ## General * Improved speed performance for some functions. -* Improved handling of table captions and footers in `export_table()`. See - also the new vignette on exporting data frames into human readable tables - here: https://easystats.github.io/insight/articles/export.html +* Improved handling of table captions and footers in `export_table()`. See also + the new vignette on exporting data frames into human readable tables here: + https://easystats.github.io/insight/articles/export.html -* Revised `width` argument in `export_table()`, which now allows to set different - column widths across table columns. See examples in `?export_table`. +* Revised `width` argument in `export_table()`, which now allows to set + different column widths across table columns. See examples in + `?export_table`. * `get_varcov()` for `MixMod` (package *GLMMadaptive*) was revised, and now allows to return a robust variance-covariance matrix. @@ -27,11 +33,11 @@ ## Bug fixes -* Fixed issues with manual sigma computation to handle dispersion models - in `get_sigma()`. +* Fixed issues with manual sigma computation to handle dispersion models in + `get_sigma()`. -* Fixed issue in `find_formula()` for `BayesFactor::lmBF()` with multiple - random effects. +* Fixed issue in `find_formula()` for `BayesFactor::lmBF()` with multiple random + effects. * Fixed issue in `get_parameters.BFBayesFactor()` with wrong sign of difference estimate for t-tests. @@ -43,9 +49,8 @@ ## New functions -* `find_transformation()` and `get_transformation()` to find or get any - function that was used to transform the response variable in a regression - model. +* `find_transformation()` and `get_transformation()` to find or get any function + that was used to transform the response variable in a regression model. ## General @@ -55,12 +60,12 @@ * `get_modelmatrix()` now supports: `rms::lrm` -* `get_predicted()` supports: `MASS::polr`, `MASS::rlm`, `rms::lrm`, `fixest`, +* `get_predicted()` supports: `MASS::polr`, `MASS::rlm`, `rms::lrm`, `fixest`, `bife::bife`, `ordinal::clm`. * `get_predicted()` standard errors are often much faster to compute. -* `get_predicted()` supports models with "grouped" or "level" outcomes (e.g., +* `get_predicted()` supports models with "grouped" or "level" outcomes (e.g., multinomial logit). * `get_predicted()` handles factors better. @@ -81,7 +86,8 @@ ## Bug fixes -* Fixed issue with parameter names from *emmeans* objects in `get_parameters()`. +* Fixed issue with parameter names from *emmeans* objects in + `get_parameters()`. * Fixed issues with unknown arguments in `get_predicted()`. @@ -103,7 +109,8 @@ ## Changes to functions -* `get_predicted()` gains a new option, `predict = "response"` for binomial models. +* `get_predicted()` gains a new option, `predict = "response"` for binomial + models. * Improved stability of `get_variance()` when computing random-slope-intercept correlation with categorical random slopes. @@ -128,8 +135,8 @@ * `check_if_installed()` gains a `minimum_version` argument, to check if an installed package is not older than the specified version number. -* The `package` argument in `check_if_installed()` is now vectorized, so you - can check for multiple packages in one function call. +* The `package` argument in `check_if_installed()` is now vectorized, so you can + check for multiple packages in one function call. * Value formatting functions (like `format_value()` or `format_ci()`) can now round to significant digits using `digits = "signif"`. @@ -151,9 +158,9 @@ ## New functions -* Added several data management and preparation functions: `data_to_long()`, +* Added several data management and preparation functions: `data_to_long()`, `data_match()`, `data_relocate()`, `data_restoretype()`, `force_numeric()`. - + ## New supported model classes * Support for `pgmm` (*plm*) @@ -166,8 +173,8 @@ * Stability improvements to `get_predicted()`. -* Fixed issues when accessing information from an `afex_aov` model with an - empty `aov` slot (in anticipation for `{afex}` v.1.0.0). +* Fixed issues when accessing information from an `afex_aov` model with an empty + `aov` slot (in anticipation for `{afex}` v.1.0.0). * Fixed issue in `model_info()` for *stanreg* object with non-standard model-family specification. @@ -176,14 +183,14 @@ ## General -* Better support for accessing auxiliary parameters (via `get_sigma()` and - `get_auxiliary()`, as well as `get_parameters(component = "all")`) for +* Better support for accessing auxiliary parameters (via `get_sigma()` and + `get_auxiliary()`, as well as `get_parameters(component = "all")`) for `brmsfit` models. ## New functions -* `get_modelmatrix()` as a robust alternative to `model.matrix()` for - different model classes. +* `get_modelmatrix()` as a robust alternative to `model.matrix()` for different + model classes. * `format_message()` to format warnings and messages by adjusting the maximum line_length, possibly to the width of the console window. @@ -194,8 +201,8 @@ ## New supported model classes -* Support for `mvord` (*mvord*), `SemiParBIV` (*GJRM*), - `selection` (*sampleSelection*) +* Support for `mvord` (*mvord*), `SemiParBIV` (*GJRM*), `selection` + (*sampleSelection*) ## Changes to functions @@ -211,12 +218,13 @@ * `get_sigma()` supports more models/objects. * `get_sigma()` and `get_deviance()` for `lrm` models (package *rms*) now only - return one value, sigma or deviance for the model with intercept and predictors. + return one value, sigma or deviance for the model with intercept and + predictors. * `get_deviance()` now works for `glmerMod`, `MixMod` and `glmmTMB` models. -* The behaviour and documentation of the `effects` and `component` arguments, - in particular for `brmsfit` models, were revised to be more consistent. +* The behaviour and documentation of the `effects` and `component` arguments, in + particular for `brmsfit` models, were revised to be more consistent. * `export_table()` now correctly prints the footer if the input was a list of data frames. @@ -237,36 +245,35 @@ * Fixed issue with `find_parameters()` for *brmsfit* models when auxiliary parameters are directly modelled. -* Fixed issue with `get_parameters()` and `find_parameters()` for - multi-group *blavaan* models. +* Fixed issue with `get_parameters()` and `find_parameters()` for multi-group + *blavaan* models. -* Fixed issue in `ellipsis_info()` when detecting nested models with +* Fixed issue in `ellipsis_info()` when detecting nested models with poly-terms. * Fixed issue in `find_response()` for *brmsfit* models that used the `resp_thres()` function in the model formula. - -* Fixed issue in `get_predicted_ci()` for models with rank-deficient - model matrix. - -* Argument `zap_small` in `format_value()` did not work properly over - vectorized vectors. + +* Fixed issue in `get_predicted_ci()` for models with rank-deficient model + matrix. + +* Argument `zap_small` in `format_value()` did not work properly over vectorized + vectors. # insight 0.13.2 ## General -* `get_predicted()` has be revamped with a new API and a stable output form - (a vector). In the course of this revision, a new function - `get_predicted_ci()` to calculate uncertainty intervals for model - predictions. +* `get_predicted()` has be revamped with a new API and a stable output form (a + vector). In the course of this revision, a new function `get_predicted_ci()` + to calculate uncertainty intervals for model predictions. * Improved support for `orm` (*rms*). ## New supported model classes -* Support for `svy_vglm` (*svyVGAM*), `mjoint` (*joineRML*), - `mhurdle` (*mhurdle*), `sarlm` (*spatialreg*), `model_fit` (*tidymodels*) +* Support for `svy_vglm` (*svyVGAM*), `mjoint` (*joineRML*), `mhurdle` + (*mhurdle*), `sarlm` (*spatialreg*), `model_fit` (*tidymodels*) ## New functions @@ -275,8 +282,8 @@ ## Changes to functions -* Added `iterations` argument to `get_predicted()` to control the - number of draws returned for Bayesian models. +* Added `iterations` argument to `get_predicted()` to control the number of + draws returned for Bayesian models. * `model_info()` now returns `$is_gam` if model is generalized additive model with smooth terms. @@ -289,18 +296,19 @@ * Improved `print_parameters()`, to allow more flexibility and better cope with different output formats. -* `get_parameters()`, `find_parameters()` and `clean_parameters()` for - *emmGrid* and *emm_list* objects were revised and now better match the - actual parameter names (also for contrasts). +* `get_parameters()`, `find_parameters()` and `clean_parameters()` for *emmGrid* + and *emm_list* objects were revised and now better match the actual parameter + names (also for contrasts). ## Bug fixes * Fixed issue in `get_variance()` for models without intercept. -* Fixed labelling issue in `get_parameters()` and `clean_parameters()` for +* Fixed labelling issue in `get_parameters()` and `clean_parameters()` for `blavaan` models. -* `clean_parameters()` for *MCMCglmm* objects did not include random parameters. +* `clean_parameters()` for *MCMCglmm* objects did not include random + parameters. * Fixed minor issue with unintended sub-titles for `print_html()`. @@ -331,9 +339,8 @@ * Fix or disable failing tests on Mac OS. -* Fixed issues in `get_variance()` with non-correlated - random-slope-intercepts for *lme4* models. - +* Fixed issues in `get_variance()` with non-correlated random-slope-intercepts + for *lme4* models. # insight 0.13.0 @@ -723,3 +730,4 @@ matrix-like variables in the model frame (e.g. when using `poly()`). * Fixed issues with `PROreg::BBmm()`, due to changes in latest package update. + diff --git a/R/compute_variances.R b/R/compute_variances.R index 56064429f..a982ac75e 100644 --- a/R/compute_variances.R +++ b/R/compute_variances.R @@ -955,11 +955,11 @@ # Reshape long <- stats::reshape(data, - varying = cols, - idvar = "_Row", - v.names = values_to, - timevar = colnames_to, - direction = "long" + varying = cols, + idvar = "_Row", + v.names = values_to, + timevar = colnames_to, + direction = "long" ) # Sort the dataframe (to match pivot_longer's output) diff --git a/R/get_predicted.R b/R/get_predicted.R index 0d8c5d3e8..8f0b3bf22 100644 --- a/R/get_predicted.R +++ b/R/get_predicted.R @@ -1239,7 +1239,7 @@ get_predicted.faMain <- function(x, data = NULL, ...) { ) iter <- as.data.frame(iter_stacked) names(iter) <- paste0("iter_", names(iter)) - # outcome with a single level + # outcome with a single level } else { # .get_predicted_boot already gives us the correct observation ~ draws format if (is.null(colnames(iter)) || !all(grepl("^iter", colnames(iter)))) { diff --git a/R/get_predicted_ci.R b/R/get_predicted_ci.R index 10d866a14..ccdc5e985 100644 --- a/R/get_predicted_ci.R +++ b/R/get_predicted_ci.R @@ -118,9 +118,9 @@ get_predicted_ci.default <- function(x, out <- .get_predicted_ci_from_iter(iter = iter, ci = ci, ci_method) out <- cbind(se, out) # outcome is multinomial/ordinal/cumulative - if (inherits(predictions, "data.frame") && - "Response" %in% colnames(predictions) && - "Row" %in% colnames(predictions)) { + if (inherits(predictions, "data.frame") && + "Response" %in% colnames(predictions) && + "Row" %in% colnames(predictions)) { out <- cbind(predictions[, c("Row", "Response")], out) } return(out) diff --git a/R/standardize_column_order.R b/R/standardize_column_order.R new file mode 100644 index 000000000..cd1d6ef1e --- /dev/null +++ b/R/standardize_column_order.R @@ -0,0 +1,153 @@ +#' Standardize column order +#' +#' Standardizes order of columns for dataframes and other objects from +#' *easystats* and *broom* ecosystem packages. +#' +#' @return A data frame, with standardized column order. +#' +#' @inheritParams standardize_names +#' +#' @examples +#' # easystats conventions +#' df1 <- cbind.data.frame( +#' CI_low = -2.873, +#' t = 5.494, +#' CI_high = -1.088, +#' p = 0.00001, +#' Parameter = -1.980, +#' CI = 0.95, +#' df = 29.234, +#' Method = "Student's t-test" +#' ) +#' +#' standardize_column_order(df1, style = "easystats") +#' +#' # broom conventions +#' df2 <- cbind.data.frame( +#' conf.low = -2.873, +#' statistic = 5.494, +#' conf.high = -1.088, +#' p.value = 0.00001, +#' estimate = -1.980, +#' conf.level = 0.95, +#' df = 29.234, +#' method = "Student's t-test" +#' ) +#' +#' standardize_column_order(df2, style = "broom") +#' @export + +standardize_column_order <- function(data, ...) { + UseMethod("standardize_column_order") +} + +#' @export +standardize_names.default <- function(data, ...) { + print_color(sprintf("Objects of class '%s' are currently not supported.\n", class(data)[1]), "red") +} + +#' @rdname standardize_column_order +#' @export +standardize_column_order.parameters_model <- function(data, + style = c("easystats", "broom"), + ...) { + style <- match.arg(style) + + # easystats -------------------------------- + + if (style == "easystats") { + col_order <- c( + # estimate + "Parameter1", "Parameter2", "Parameter", "Mean_Parameter1", "Mean_Parameter2", + "Mean_Group1", "Mean_Group2", "Coefficient", "r", "rho", "tau", "Estimate", + "Median", "Mean", "MAP", "MAD", "Dxy", "Difference", "Psihat", + "Trimmed_Mean", "R2", "Mu", + # type of estimate + "Group", "Component", "Response", "Effects", "Weight", + # uncertainty + "SE", "Std. Error", "SD", "Deviance_error", + "CI", "CI_low", "CI_high", "Difference_CI_low", "Difference_CI_high", + "CI_Method", "CI_Distribution", "CI_Iterations", + "Sum_Squares", "Mean_Square", + "pd", "ROPE_CI", "ROPE_low", "ROPE_high", "ROPE_Percentage", "Rhat", "ESS", + # prior details + "Prior_Distribution", "Prior_Location", "Prior_Scale", + # test details + "Method", "method", + # statistic + "t", "t value", "z", "z value", "F", "F value", "Chi2", "Chi2 value", + "chisq", "Chisq", "chi-sq", "t / F", "z / Chisq", "z / Chi2", "W", "S", + # degrees of freedom + "df", "df_error", "df_residual", + # p-value + "p", "BF", "log_BF", + # other details + "Alternative", "n_Obs", + # effectsize details + "Effectsize", + "d", "Cohens_d", "d_CI_low", "d_CI_high", + "g", "Hedges_g", "g_CI_low", "g_CI_high", + "Eta2", "Eta2_CI_low", "Eta2_CI_high", + "Omega2", "Omega2_CI_low", "Omega2_CI_high", + "Epsilon2", "Epsilon2_CI_low", "Epsilon2_CI_high", + "Cramers_v", "Cramers_v_adjusted", "Cramers_CI_low", "Cramers_CI_high", + "phi", "phi_adjusted", "phi_CI_low", "phi_CI_high", + "r_rank_biserial", "rank_biserial_CI_low", "rank_biserial_CI_high", + "rank_epsilon_squared", "rank_epsilon_squared_CI_low", "rank_epsilon_squared_CI_high", + "Kendalls_W", "Kendalls_W_CI_low", "Kendalls_W_CI_high" + ) + } + + # broom ------------------------------------ + + if (style == "broom") { + col_order <- c( + # estimate + "estimate", "mean.group1", "mean.group2", + # type of estimate + "group", "component", "response", "effects", "weight", + # uncertainty + "std.error", "std.dev", + "conf.level", "conf.low", "conf.high", "conf.method", "conf.distribution", "conf.iterations", + "sum.squares", "mean.square", + "pd", "rope.percentage", "rhat", "ess", + # prior details + "prior.distribution", "prior.location", "prior.scale", + # test details + "method", + # statistic + "statistic", + # degrees of freedom + "df", "df.error", "df.residual", + # p-value + "p.value", "bayes.factor", "log(bayes.factor)", + # other details + "alternative", "n.obs", + # effectsize details + "effectsize", + "d", "cohens.d", "d.conf.low", "d.conf.high", + "g", "Hedges.g", "g.conf.low", "g.conf.high", + "eta2", "eta2.conf.low", "eta2.conf.high", + "omega2", "omega2.conf.low", "omega2.conf.high", + "epsilon2", "epsilon2.conf.low", "epsilon2.conf.high", + "cramers.v", "cramers.v.adjusted", "cramers.conf.low", "cramers.conf.high", + "phi", "phi.adjusted", "phi.conf.low", "phi.conf.high", + "r.rank.biserial", "rank.biserial.conf.low", "rank.biserial.conf.high", + "rank.epsilon.squared", "rank.epsilon.squared.conf.low", "rank.epsilon.squared.conf.high", + "kendalls.w", "kendalls.w.conf.low", "kendalls.w.conf.high" + ) + } + + data <- data[intersect(col_order, names(data))] + + data +} + +#' @export +standardize_column_order.effectsize_table <- standardize_column_order.parameters_model + +#' @export +standardize_column_order.data.frame <- standardize_column_order.parameters_model + +#' @export +standardize_column_order.parameters_distribution <- standardize_column_order.parameters_model diff --git a/R/standardize_names.R b/R/standardize_names.R index 143d707e2..6b727b5b4 100644 --- a/R/standardize_names.R +++ b/R/standardize_names.R @@ -112,31 +112,33 @@ standardize_names.parameters_distribution <- standardize_names.parameters_model cn[cn %in% c("df_residual", "df.residual", "Resid..Df", "df.error", "df_error")] <- "df" # convert broom-style to easystats - cn[cn == "term"] <- "Parameter" - cn[cn == "estimate"] <- "Coefficient" - cn[cn == "std.error"] <- "SE" - cn[cn == "std.dev"] <- "SD" - cn[cn == "p.value"] <- "p" + # styler: off + cn[cn == "term"] <- "Parameter" + cn[cn == "estimate"] <- "Coefficient" + cn[cn == "std.error"] <- "SE" + cn[cn == "std.dev"] <- "SD" + cn[cn == "p.value"] <- "p" cn[cn == "bayes.factor"] <- "BF" - cn[cn == "component"] <- "Component" - cn[cn == "effect"] <- "Effects" - cn[cn == "response"] <- "Response" - cn[cn == "statistic"] <- "Statistic" - cn[cn == "conf.low"] <- "CI_low" - cn[cn == "conf.high"] <- "CI_high" - cn[cn == "conf.level"] <- "CI" - cn[cn == "n.obs"] <- "n_Obs" + cn[cn == "component"] <- "Component" + cn[cn == "effect"] <- "Effects" + cn[cn == "response"] <- "Response" + cn[cn == "statistic"] <- "Statistic" + cn[cn == "conf.low"] <- "CI_low" + cn[cn == "conf.high"] <- "CI_high" + cn[cn == "conf.level"] <- "CI" + cn[cn == "n.obs"] <- "n_Obs" # anova - cn[cn == "sumsq"] <- "Sum_Squares" - cn[cn == "meansq"] <- "Mean_Square" - cn[cn == "Resid..Dev"] <- "Deviance_error" + cn[cn == "sumsq"] <- "Sum_Squares" + cn[cn == "meansq"] <- "Mean_Square" + cn[cn == "Resid..Dev"] <- "Deviance_error" # convert classic summary - cn[cn == "Estimate"] <- "Coefficient" - cn[cn == "Std. Error"] <- "SE" - cn[cn == "t value"] <- "Statistic" - cn[cn == "z value"] <- "Statistic" - cn[cn == "Pr(>|t|)"] <- "p" - cn[cn == "Pr(>|z|)"] <- "p" + cn[cn == "Estimate"] <- "Coefficient" + cn[cn == "Std. Error"] <- "SE" + cn[cn == "t value"] <- "Statistic" + cn[cn == "z value"] <- "Statistic" + cn[cn == "Pr(>|t|)"] <- "p" + cn[cn == "Pr(>|z|)"] <- "p" + # styler: on cn } diff --git a/R/utils_get_data.R b/R/utils_get_data.R index eea6ca304..fcb1e04e8 100644 --- a/R/utils_get_data.R +++ b/R/utils_get_data.R @@ -123,7 +123,6 @@ mf_list <- lapply(mf_matrix, as.data.frame, stringsAsFactors = FALSE) mf_matrix <- do.call(cbind, mf_list) mf <- cbind(mf_nonmatrix, mf_matrix) - } else { # fix NA in column names diff --git a/_pkgdown.yml b/_pkgdown.yml index d18ab0598..1812483f2 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -130,6 +130,7 @@ reference: - null_model - print_parameters - standardize_names + - standardize_column_order - check_if_installed - title: "Example Datasets" diff --git a/inst/WORDLIST b/inst/WORDLIST index 5cc9790fe..691acae33 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -43,6 +43,7 @@ colour coloured comparator coxrobust +datawizard dirichlet doi easystats diff --git a/man/standardize_column_order.Rd b/man/standardize_column_order.Rd new file mode 100644 index 000000000..f6e8f0c7c --- /dev/null +++ b/man/standardize_column_order.Rd @@ -0,0 +1,60 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standardize_column_order.R +\name{standardize_column_order} +\alias{standardize_column_order} +\alias{standardize_column_order.parameters_model} +\title{Standardize column order} +\usage{ +standardize_column_order(data, ...) + +\method{standardize_column_order}{parameters_model}(data, style = c("easystats", "broom"), ...) +} +\arguments{ +\item{data}{A data frame. In particular, objects from \emph{easystats} +package functions like +\code{\link[parameters:model_parameters]{parameters::model_parameters()}} or +\code{\link[effectsize:effectsize]{effectsize::effectsize()}} are accepted, but also +data frames returned by \code{broom::tidy()} are valid objects.} + +\item{...}{Currently not used.} + +\item{style}{Standardization can either be based on the naming conventions +from the \href{https://easystats.github.io/easystats/}{easystats-project}, +or on \pkg{broom}'s naming scheme.} +} +\value{ +A data frame, with standardized column order. +} +\description{ +Standardizes order of columns for dataframes and other objects from +\emph{easystats} and \emph{broom} ecosystem packages. +} +\examples{ +# easystats conventions +df1 <- cbind.data.frame( + CI_low = -2.873, + t = 5.494, + CI_high = -1.088, + p = 0.00001, + Parameter = -1.980, + CI = 0.95, + df = 29.234, + Method = "Student's t-test" +) + +standardize_column_order(df1, style = "easystats") + +# broom conventions +df2 <- cbind.data.frame( + conf.low = -2.873, + statistic = 5.494, + conf.high = -1.088, + p.value = 0.00001, + estimate = -1.980, + conf.level = 0.95, + df = 29.234, + method = "Student's t-test" +) + +standardize_column_order(df2, style = "broom") +} diff --git a/tests/testthat/test-brms.R b/tests/testthat/test-brms.R index 87bad3adf..67682421a 100644 --- a/tests/testthat/test-brms.R +++ b/tests/testthat/test-brms.R @@ -44,7 +44,6 @@ if (.runThisTest) { manual <- rstantools::posterior_epred(m8) manual <- apply(manual[, , 1], 2, mean) expect_equal(pred1$Predicted[1:32], manual) - }) test_that("find_statistic", { diff --git a/tests/testthat/test-standardize_column_order.R b/tests/testthat/test-standardize_column_order.R new file mode 100644 index 000000000..3015e4944 --- /dev/null +++ b/tests/testthat/test-standardize_column_order.R @@ -0,0 +1,38 @@ +test_that("get_predicted", { + # easystats conventions + df1 <- cbind.data.frame( + CI_low = -2.873, + t = 5.494, + CI_high = -1.088, + p = 0.00001, + Parameter = -1.980, + CI = 0.95, + df = 29.234, + Method = "Student's t-test" + ) + + expect_equal( + names(standardize_column_order(df1, style = "easystats")), + c("Parameter", "CI", "CI_low", "CI_high", "Method", "t", "df", "p") + ) + + # broom conventions + df2 <- cbind.data.frame( + conf.low = -2.873, + statistic = 5.494, + conf.high = -1.088, + p.value = 0.00001, + estimate = -1.980, + conf.level = 0.95, + df = 29.234, + method = "Student's t-test" + ) + + expect_equal( + names(standardize_column_order(df2, style = "broom")), + c( + "estimate", "conf.level", "conf.low", "conf.high", "method", + "statistic", "df", "p.value" + ) + ) +})