| umx_aggregate | R Documentation |
A common task is preparing summary tables, aggregating over some grouping factor.
Like mean and sd of age, by sex. R's aggregate() function is useful and powerful, allowing
xtabs based on a formula.
umx_aggregate makes using it a bit easier. In particular, it has some common functions for summarizing data built-in, like "mean (sd)" (the default).
umx_aggregate(mpg ~ cyl, data = mtcars, what = "mean_sd")
| cyl | mpg |
| 4 (n = 11) | 26.66 (4.51) |
| 6 (n = 7) | 19.74 (1.45) |
| 8 (n = 14) | 15.1 (2.56) |
umx_aggregate(
formula = DV ~ condition,
data = df,
what = c("mean_sd", "n"),
digits = 2,
report = c("markdown", "html", "txt"),
output = c("table", "string")
)
formula |
The aggregation formula. e.g., DV ~ condition. |
data |
frame to aggregate (defaults to df for common case) |
what |
function to use. Default reports "mean (sd)". |
digits |
to round results to. |
report |
Format for the table: Default is markdown. |
output |
Format for the results: "table" (default) or "string". |
table or character vector of formatted strings
https://github.com/tbates/umx, https://tbates.github.io
umx_apply(), aggregate()
Other Reporting Functions:
aic_weights(),
plot.umx_GWAS(),
umx,
umxAPA(),
umxFactorScores(),
umxGetLatents(),
umxGetManifests(),
umxGetModel(),
umxGetParameters(),
umxParameters(),
umx_time()
# =====================================
# = Basic use, compare with aggregate =
# =====================================
aggregate(mpg ~ cyl, FUN = mean, na.rm = TRUE, data = mtcars)
umx_aggregate(mpg ~ cyl, data = mtcars)
# =============================================
# = Use different (or user-defined) functions =
# =============================================
umx_aggregate(mpg ~ cyl, data = mtcars, what = "n")
umx_aggregate(mpg ~ cyl, data = mtcars, what = function(x){sum(!is.na(x))})
# turn off markdown
umx_aggregate(mpg ~ cyl, data = mtcars, report = "txt")
# =========================================================
# = More than one item on the left hand side (Table 1 style)=
# =========================================================
umx_aggregate(cbind(mpg, qsec) ~ cyl, data = mtcars, digits = 3)
# =========================
# = Output as a string =
# =========================
umx_aggregate(mpg ~ cyl, data = mtcars, output = "string")
## Not run:
umx_aggregate(cbind(moodAvg, mood) ~ condition, data = study1)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.