# ---- examples are taken from Blackstone, 2016 ----
# Example 1: ----
# Mean age is 72.17986, and the standard deviation (SD) is 9.364132.
## Steps:
## - Nine is the first significant figure of the SD.
## - Nine is in the ones place. Thus...
## + round the mean to the ones place (i.e., round(x, digits = 0))
## + round the SD to the tenths place (i.e., round(x, digits = 1))
table_ester(estimate = 72.17986, error = 9.364132)
# > [1] 72 +/- 9.4
# an estimated lower and upper bound for 95% confidence limits
lower <- 72.17986 - 1.96 * 9.364132
upper <- 72.17986 + 1.96 * 9.364132
table_estin(estimate = 72.17986, lower = lower, upper = upper,
form = "{estimate} (95% CI: {lower}, {upper})")
# > [1] "72 (95% CI: 54, 91)"
# Example 2: ----
# Mean cost is $72,347.23, and the standard deviation (SD) is $23,994.06.
## Steps:
## - Two is the first significant figure of the SD.
## - Nine is in the ten thousands place. Thus...
## + round mean to the 10-thousands place (i.e., round(x, digits = -4))
## + round SD to the thousands place (i.e., round(x, digits = -3))
table_ester(estimate = 72347.23, error = 23994.06)
# > [1] "70,000 +/- 24,000"
# an estimated lower and upper bound for 95% confidence limits
lower <- 72347.23 - 1.96 * 23994.06
upper <- 72347.23 + 1.96 * 23994.06
table_estin(estimate = 72347.23, lower = lower, upper = upper,
form = "{estimate} (95% CI: {lower} - {upper})")
# > [1] "70,000 (95% CI: 30,000 - 120,000)"
Run the code above in your browser using DataLab