Description Usage Arguments Details Value Functions Author(s) Examples
expandtbl()
generates a data.frame based on vectors.
1 2 3 4 5 6 7 8 9 10 |
... |
vectors |
exp_name |
Name of |
exp_lvl |
Names of two categories in the order of Exposed and non-exposed |
case_name |
Name of |
case_lvl |
names of two categories in the order of |
strata_name |
Name of stratified variable |
data |
frequency table in data.frame |
freq |
name of variable for the weighted frequency |
expandtbl
uses the vectors of 2x2
tables and
generates a data frame of at least two columns:
exp and case.
1 |
Strata
Multiple tables can be used to construct a dataset by specifying
strata_name
as follow. Strata can be included
using multiple named vectors.
1 2 3 4 5 6 7 8 9 10 |
Labels for variables
If names or levels of variables are not specified, the followings are applied.
exp Name: exp
exp levels: exposed
and unexposed
case Name: case
case levels: case
and control
Strata Name: strata
Note: Strata levels are not considered as vectors must be named.
expandfreq() uses the weighted frequencies in
data.frame format and construct another data.frame
based on the frequency weight.
The name of the frequency weighted variable can be
specified by freq
argument.
data.frame
expandfreq
: expandfreq()
expands a frequency-weighted table
into a data.frame.
Email: dr.myominnoo@gmail.com
Website: https://myominnoo.github.io/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | ## Asthma Example from Essential Medical Statistics
## page 160
asthma <- expandtbl(c(81, 995, 57, 867),
exp_name = "sex",
exp_lvl = c("woman", "man"),
case_name = "asthma",
case_lvl = c("yes", "no"))
## Not run:
## label variable and dataset
asthma <- label(asthma, "Hypothetical Data of Asthma Prevalence")
asthma <- label(asthma, sex = "Man or Woman",
asthma = "Asthma or No Asthma")
## Checking codebook
codebook(asthma)
## simple tabulation
tab(asthma)
## cross-tabulation
tab(asthma, sex, by = asthma)
## End(Not run)
## Example for expanding frequency weighted data
## Example from UCLA website
## you can download the dataset here:
## https://stats.idre.ucla.edu/stat/stata/examples/icda/afterlife.dta
x <- data.frame(gender = c(1, 1, 0, 0),
aftlife = c(1, 0, 1, 0),
freq = c(435, 147, 375, 134))
y <- expandfreq(x, freq)
## check the numbers by tabulation
## tab(y, gender, by = aftlife)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.