Description Usage Arguments Details Value Author(s) Examples
Create tables for any descriptive statistic, using variables in a data.frame. You can create simple to highly customized tables, with or without weighting.
1 2 3 4 5 |
x_vars |
This variable will be used to calculate the statistics for it.
|
xname |
Labels for x.
|
y_vars |
This variable can be used to calculate bivariable statistics.
|
yname |
Labels for y.
|
z_vars |
This variable can be used for additional calculations.
|
zname |
Labels for z.
|
rows |
This factors will be used to separate the rows of the table in subgroups.
|
rnames |
Labels for rows.
|
cols |
This factors will be used to separate the columns of the table in subgroups.
|
cnames |
Labels for cols.
|
w |
This numeric variable will be used to weighting the table.
|
data |
A data frame with all used variables. |
FUN |
A abstract cell function to calculate statistic in every cell of the table. See details. |
allnames |
Logical asking whether to fill every cell with labels or only the first one. |
nonames |
Logical asking whether to use dimnames for variable labels or make all labeling in the table self. |
alllabel |
Label for overall Group without splitting in this Factor. |
inset |
Inset text in each cell, '?' will be replaced with the value of the cell. |
remove |
Remove a character string from each cell. |
n_min |
min N in each cell, it will be only passed in the cell function. But it is necessary to not calculate statistics from 1 or 2 values. |
... |
additional parameters passed to the FUN |
FUN can be a cell function from this package or your own function. If you wanna writing you own cell function. It must take following parameters. But it must not use them.
x, The whole x variable.
y, The whole y variable.
z, The whole z variable.
w, The whole w variable.
cell_ids, Index vector to select values that belong in this cell.
row_ids, Index vector to select values that belong in this row.
col_ids, Index vector to select values that belong in this col.
vnames, A vector of length 3, with labels of variables (x,y,z)
vars, A vector of length 3, with names of variables (x,y,z)
n_min , Min needed N for calculation.
... , additional own parameters.
An example with simple mean see below.
A character Matrix.(Table)
ADES <[email protected]>
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 | # 1) simple own FUN cell function.
s_mean<- function(x, y, z, w, cell_ids, row_ids, col_ids, vnames, vars, n_min, ds=3){
out<- ''
if(length(cell_ids)>= n_min){
out<- format(mean(x[cell_ids], na.rm=TRUE), digits=ds)
}
return(out)
}
##########################################
# 2) simple 2 x 2 table of means
sex <- factor(rbinom(5000, 1, 0.5), labels=c('Men', 'Women'))
age <- round(runif(5000, 18, 89))
treat <- factor(rbinom(5000, 1, 0.3), labels=c('control', 'treated'))
d<-data.frame(sex, age, treat)
tabular.ade(x_vars='age', xname='Age [y]', rows='sex', rnames='Sex', cols='treat',
cnames='Treatment', data=d, nonames=FALSE, FUN=s_mean)
##########################################
# 3) Relative frequency table
d$dosis <- round(runif(5000, 0.5, 6.49))
tabular.ade(x_vars='age', xname='Age [y]', rows=c('sex', 'treat'),
rnames=c('Sex', 'Treatment'), cols='dosis', cnames='Dosis', data=d, FUN=n_cell,
type='pct')
##########################################
# 4) Weighted median table
d$w <- runif(5000, 0.1, 5)
d$bmi <- rnorm(5000, 30, 3)
tabular.ade(x_vars=c('age', 'bmi'), xname=c('Age', 'BMI'),
cols=c('sex', 'ALL', 'treat'),
cnames=c('Sex', 'Treatment'), w='w', data=d, FUN=quantile_cell)
##########################################
# 5) Correlation table between age and bmi
tabular.ade(x_vars='age', xname='Age', y_vars='bmi', yname='BMI',
rows=c('dosis'), rnames=c('Dosis'), cols=c('sex', 'treat'),
cnames=c('Sex', 'Treatment'), data=d, FUN=corr_p_cell)
##########################################
# 6) Multiple statistics
tabular.ade(x_vars=c('N', 'MEAN', 'SD', 'SKEW', 'KURT', 'RANGE'),
y_vars=c('age', 'bmi'), yname=c('Age', 'BMI'),
cols=c('sex', 'ALL', 'treat'), cnames=c('Sex', 'Treatment'),
w='w', data=d, FUN=stat_cell)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.