## ----setup, include=FALSE----------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ## ----------------------------------------------------------------------------- library(pubformat) ## ----------------------------------------------------------------------------- format_p(0.048) format_p(0.0002) ## ----------------------------------------------------------------------------- format_p(0.001) format_p(0.0009) ## ----------------------------------------------------------------------------- format_p(0.048, sig = TRUE) format_p(0.006, sig = TRUE) format_p(0.0002, sig = TRUE) ## ----------------------------------------------------------------------------- format_p(0.0499, sig = TRUE) ## ----------------------------------------------------------------------------- format_ci(1.08, 1.87) ## ----------------------------------------------------------------------------- format_ci(1.08, 1.87, level = 0.99) ## ----------------------------------------------------------------------------- format_ci(0.21, 0.48) ## ----------------------------------------------------------------------------- format_ci(0.21, 0.48, leading_zero = FALSE) ## ----------------------------------------------------------------------------- format_r(0.42) format_r(-0.31) ## ----------------------------------------------------------------------------- format_cor(0.42, method = "pearson") format_cor(0.42, method = "spearman") format_cor(0.42, method = "kendall") ## ----------------------------------------------------------------------------- rho <- cor( mtcars$mpg, mtcars$wt, method = "spearman" ) format_cor(rho, method = "spearman") ## ----------------------------------------------------------------------------- format_percent(0.423) ## ----------------------------------------------------------------------------- format_percent(42.3, input = "percent") ## ----------------------------------------------------------------------------- format_percent(0.42) format_percent(42, input = "percent") ## ----------------------------------------------------------------------------- format_percent(c(0.25, 0.50, 0.75)) ## ----------------------------------------------------------------------------- format_percent(-12.5, input = "percent") format_percent(150, input = "percent") ## ----------------------------------------------------------------------------- format_t(0.86, df = 20) ## ----------------------------------------------------------------------------- format_t(-2.14, df = 48) ## ----------------------------------------------------------------------------- format_t(3.27, df = 105.5) ## ----------------------------------------------------------------------------- format_t( 0.86, df = 20, p = 0.041 ) ## ----------------------------------------------------------------------------- format_t( statistic = c(3.10, 3.20), df = c(40, 40), p = c(0.001, 0.0009) ) ## ----------------------------------------------------------------------------- format_f( 2.50, df1 = 2, df2 = 30 ) ## ----------------------------------------------------------------------------- format_f( 4.4344, df1 = 1, df2 = 3262.9 ) ## ----------------------------------------------------------------------------- format_f( 4.4344, df1 = 1, df2 = 3262.9, p = 0.03530 ) ## ----------------------------------------------------------------------------- format_f( 107.8924, df1 = 1, df2 = 86.7, p = 2e-16 ) ## ----------------------------------------------------------------------------- format_f( 4.4344, df1 = 1, df2 = 3262.9, p = 0.03530, style = "markdown" ) ## ----------------------------------------------------------------------------- format_d(0.52) ## ----------------------------------------------------------------------------- format_d( 0.52, lower = 0.18, upper = 0.86 ) ## ----------------------------------------------------------------------------- format_d( -0.31, lower = -0.62, upper = 0.00 ) ## ----------------------------------------------------------------------------- format_d( 0.52, lower = 0.18, upper = 0.86, style = "markdown" ) ## ----------------------------------------------------------------------------- format_g(0.49) ## ----------------------------------------------------------------------------- format_g( 0.49, lower = 0.16, upper = 0.82 ) ## ----------------------------------------------------------------------------- format_g( 0.49, lower = 0.16, upper = 0.82, style = "markdown" ) ## ----------------------------------------------------------------------------- format_eta2(0.14) ## ----------------------------------------------------------------------------- format_eta2( 0.14, lower = 0.08, upper = 0.21 ) ## ----------------------------------------------------------------------------- format_eta2( eta2 = c(0.14, 0.00, 0.67), lower = c(0.08, 0.00, 0.55), upper = c(0.21, 0.04, 0.78) ) ## ----------------------------------------------------------------------------- format_partial_eta2(0.14) ## ----------------------------------------------------------------------------- format_partial_eta2( 0.14, lower = 0.08, upper = 0.21 ) ## ----------------------------------------------------------------------------- format_omega2(0.08) ## ----------------------------------------------------------------------------- format_omega2( 0.08, lower = 0.02, upper = 0.15 ) ## ----------------------------------------------------------------------------- format_omega2(-0.02) ## ----------------------------------------------------------------------------- format_omega2( 0.01, lower = -0.03, upper = 0.05 ) ## ----------------------------------------------------------------------------- model <- lm(mpg ~ wt, data = mtcars) summary(model) ## ----------------------------------------------------------------------------- p_value <- summary(model)$coefficients["wt", "Pr(>|t|)"] p_value format_p(p_value) ## ----------------------------------------------------------------------------- ci <- confint(model, "wt") ci format_ci(ci[1], ci[2]) ## ----------------------------------------------------------------------------- r_value <- cor(mtcars$mpg, mtcars$wt) r_value format_r(r_value) ## ----------------------------------------------------------------------------- coef_table <- summary(model)$coefficients t_value <- coef_table["wt", "t value"] p_value <- coef_table["wt", "Pr(>|t|)"] df_value <- df.residual(model) format_t( statistic = t_value, df = df_value, p = p_value ) ## ----------------------------------------------------------------------------- d_value <- 0.52 d_lower <- 0.18 d_upper <- 0.86 ## ----------------------------------------------------------------------------- format_d( d_value, lower = d_lower, upper = d_upper ) ## ----------------------------------------------------------------------------- p_values <- c(0.032, 0.006, 0.0004, 0.213) format_p(p_values) ## ----------------------------------------------------------------------------- correlations <- c(0.42, -0.31, 0.18) format_r(correlations) ## ----------------------------------------------------------------------------- proportions <- c(0.24, 0.51, 0.83) format_percent(proportions) ## ----------------------------------------------------------------------------- format_t( statistic = c(0.86, -2.14, 3.27), df = c(20, 48, 105.5), p = c(0.041, 0.038, 0.0012) ) ## ----------------------------------------------------------------------------- format_f( statistic = c(2.50, 4.4344), df1 = c(2, 1), df2 = c(30, 3262.9), p = c(0.091, 0.03530) ) ## ----------------------------------------------------------------------------- format_d( d = c(0.52, -0.31, 1.14), lower = c(0.18, -0.62, 0.80), upper = c(0.86, 0.00, 1.48) ) ## ----------------------------------------------------------------------------- format_omega2( omega2 = c(0.08, -0.02, 0.31), lower = c(0.02, -0.06, 0.20), upper = c(0.15, 0.02, 0.42) ) ## ----------------------------------------------------------------------------- format_eta2( eta2 = c(0.14, NA, 0.67), lower = c(0.08, 0.01, 0.55), upper = c(0.21, 0.10, 0.78) ) .