The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Overview of prmisc

Martin Papenberg, Juli Nagel

library(prmisc)
library(effectsize)
library(afex)
#> Warning in check_dep_version(): ABI version mismatch: 
#> lme4 was built with Matrix ABI version 1
#> Current Matrix ABI version is 2
#> Please re-install lme4 from source or restore original 'Matrix' package

prmisc

prmisc is a small package that formats numbers and statistical test results according to APA style guidelines. The output can be included in Quarto or R Markdown documents. It covers some basic statistical tests (t-test, ANOVA, correlation, \(\chi^2\) test, Mann-Whitney-U test) and some basic number printing manipulations: formatting p-values, removing leading zeros for numbers that cannot be greater than one, and others.

Packages with a more rich set of functionality are papaja and apa. However, we find ourselves returning to prmisc because it offers some convenience functions not available in these packages

Usage

t-test

prmisc uses the output of the base R t.test() function, and optionally effectsize::cohens_d() to display the results of a t-test:

We must include this as “inline code” to properly display it in the output of an R Markdown / Quarto file:

The results were significant, \(t(22) = -5.15\), \(p < .001\), \(d = -2.13\).

An example for paired data:

\(t(9) = -4.06\), \(p = .003\), \(d_z = -1.28\)

We can also print the confidence interval of the effect size:

\(t(9) = -4.06\), \(p = .003\), \(d_z = -1.28\), \(95\%\) \(CI\) \([-2.12\), \(-0.41]\)

The information about the CI is taken from the effectsize object:

\(t(9) = -4.06\), \(p = .003\), \(d_z = -1.28\), \(80\%\) \(CI\) \([-1.81\), \(-0.70]\)

The effect size object can also be left out:

\(t(9) = -4.06\), \(p = .003\)

Correlation coefficient

Printing the results of a correlation including the significance test is straight forward. prmisc::print_cortest() uses the output of the base R function cor.test() as input.

\(r(7) = .57\), \(p = .108\)

ANOVA

prmisc can format ANOVA results as returned by the afex package.

\(F(1.92\), \(17.31) = 40.72\), \(p < .001\), \(\eta_G^2 = .39\)

Via the package papaja (papaja::apa_print(aov_results)), we would obtain a more rich output, including an ANOVA table. However, unlike papaja, prmisc can print the nonitalic \(\eta\), which would be required according to APA guidelines. because \(\eta\) is a greek symbol:

This only works with Latex/PDF output. To use it in R Markdown documents, we need to load the upgreek package in the YAML header, using

header-includes: 
  -\usepackageupgreek

We can also use the partial \(\eta^2\), or no effect size index:

\(\chi^2\)-test

Unlike the other functions that display statistical tests, prmisc::print_chi2() can perform the statistical test by itself. By default, prmisc::print_chi2() does not use a continuity correction.

\(\chi^2(1, N = 31) = 1.37\), \(p = .242\), \(\phi = .21\)

\(\chi^2(1, N = 31) = 0.64\), \(p = .423\), \(\phi = .14\)

The \(\phi\) index is displayed as measure of effect size if the input is a 2x2 contingency table. Using the es argument can prevent this:

Like for \(\eta\) in the output of print_anova(), we can also use the nonitalic symbol for \(\chi\) and \(\phi\), which would be required by APA guidelines (because they are greek symbols). Again, this only works for Latex/PDF output and we would need the upgreek package.

Some functions for printing numbers

prmisc includes several functions to format numbers. We find these particularly useful for writing papers according to APA style, for example when we create custom tables with numeric results.

An important function is force_decimals(), which ensures that a specified number of decimals is shown in the output.

Note that the function round() will not produce the same results as force_decimals() because unfortunately trailing zeros are removed in the R Markdown / Quarto output.

This is because round() returns a numeric vector and force_decimals() (as all other functions in prmisc) returns a string.

Small numbers that are close to zero are rounded to zero by default. This behaviour can be controlled using the argument round_zero:

Sometimes we want to leave integers intact (without decimals), which can be accomplished via force_or_cut():

Compare to:

If we do not want the zero, e.g., for p-values or correlation coefficients, use decimals_only():

We can format a p-value, the default is 3 decimals:

Or we format several p-values with one function call:

While all other number printing functions have two decimals by default, format_p() has three decimals by default.

We often want to just print the mean and standard deviation of a set of observations, we can do this with print_mean_sd():

Inline: \((M = 5.84\), \(SD = 0.83)\)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.