Creates a table comparing the mean of y
across levels of x
.
tabmeans.svy(formula, design, columns = c("xgroups", "p"),
parenth = "sd", sep.char = ", ", xlevels = NULL, yname = NULL,
text.label = NULL, decimals = 1, anova.svyglm.list = NULL,
formatp.list = NULL, n.headings = FALSE, N.headings = FALSE,
print.html = FALSE, html.filename = "table1.html")
Formula, e.g. BMI ~ Sex
.
Survey design object from svydesign
.
Character vector specifying what columns to include. Choices
for each element are "n"
for total sample size, "overall"
for
overall mean, "xgroups"
for x
group means, "diff"
for
difference in x
group means (this one and the next two are only
available for binary x
), "diffci"
for 95
x
group means, "diff.ci"
for difference in group means and 95
confidence interval, and "p"
for p-value.
Character string specifying what statistic to display in
parentheses after the means. Choices are "none"
, "sd"
,
"se"
, "t.ci"
, "z.ci"
, "range"
, and
"minmax"
.
Character string with separator to place between lower and
upper bound of confidence intervals. Typically "-"
or ", "
.
Character vector with labels for the levels of x
, used
in column headings.
Character string with a label for the y
variable.
Character string with text to put after the y
variable name, identifying what cell values and parentheses represent
Numeric value specifying number of decimal places for numbers other than p-values.
List of arguments to pass to
anova.svyglm
. Only used if x
has three or more
levels.
List of arguments to pass to formatp
.
Logical value for whether to display group sample sizes in parentheses in column headings.
Logical value for whether to display weighted sample sizes in parentheses in column headings.
Logical value for whether to write a .html file with the table to the current working directory.
Character string specifying the name of the .html file
that gets written if print.html = TRUE
.
Data frame which you can print in R (e.g. with xtable's
xtable
or knitr's kable
)
or export to Word, Excel, or some other program. To export the table, set
print.html = TRUE
. This will result in a .html file being written to
your current working directory, which you can open and copy/paste into your
document.
Basically tabmeans
for complex survey data. Relies heavily on
the survey package.
# NOT RUN {
# Create survey design object
library("survey")
design <- svydesign(
data = tabsvydata,
ids = ~sdmvpsu,
strata = ~sdmvstra,
weights = ~wtmec2yr,
nest = TRUE
)
# Compare mean BMI by sex
(meanstable <- tabmeans.svy(BMI ~ Sex, design = design))
# }
Run the code above in your browser using DataLab