Description Usage Arguments Details Value See Also Examples
View source: R/add.stat.desc.R
add.stat.desc
enables to add a specific quantitative statistic into an existing table of statistics.
1 2 3 4 5 |
tab |
A desc object |
data |
The data frame used to create tab |
func.stat |
Passed to |
func.stat.name |
Passed to |
pos |
Numeric used to specify the position of the new statistics |
... |
Other parameters |
Add a specific statistic in a desc object (only works for quantitative statistics for now).
It calls the report.quanti
function with the same attributes as the tab argument and
uses the regroup
function to bind the two results.
A "quanti" desc object (desc$type.desc equal to "quanti")
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 41 42 | # Load the data
data(datafake)
# The default statistics are given here:
tab1=report.quanti(data=datafake,y="y_numeric",x1="GROUP",total=TRUE,subjid="SUBJID")
# Define the function corresponding to the coefficient of variation for example
cv=function(y) sd(y,na.rm=TRUE)/mean(y,na.rm=TRUE)
# We use the add.stat function to add CV at the second row:
tab1.cv=add.stat(tab1,datafake,func.stat=cv,func.stat.name="Coef. Var",
pos=2)
tab1.cv
# Same with 2 explicative variables
tab=report.quanti(data=datafake,y="y_numeric",x1="GROUP",
x2="TIMEPOINT",total=TRUE,subjid="SUBJID",
at.row="TIMEPOINT")
tab=add.stat(tab,datafake,func.stat=cv,func.stat.name="Coef. Var",
pos=2)
tab
# And on position 5, we can add for example the mode
mode=function(x)
{
x=na.omit(x)
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
tab=add.stat(tab,datafake,func.stat=mode,func.stat.name="Mode",
pos=5)
tab
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.