knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
In this vignette we will see how to modify your outputs. Basically you can:
regroup()
functionreport.quanti()
functionreport.quali()
functionadd.stat()
functionsplit()
functionStart by loading all usual libraries.
library(ClinReport) library(officer) library(flextable) library(emmeans)
Load your data.
# We will use fake data data(datafake) print(head(datafake))
You can mix qualitative and quantitative outputs. It's possible only if there is only 1 explicative variable, and it should be the same variable for both response:
tab1=report.quanti(data=datafake,y="y_numeric", x1="GROUP",subjid="SUBJID",y.label="Y numeric") tab2=report.quali(data=datafake,y="y_logistic", x1="GROUP",subjid="SUBJID",y.label="Y logistic") tab3=regroup(tab1,tab2,rbind.label="The label of your choice") report.doc(tab3,title="Mixed Qualitative and Quantitative output", colspan.value="Treatment group")
You will have to specify the function corresponding to the statistics
and use the func.stat
argument
es=function(x) mean(x,na.rm=T)/sd(x,na.rm=T) tab=report.quanti(data=datafake,y="y_numeric",x1="GROUP", total=TRUE,subjid="SUBJID", func.stat=es, func.stat.name="Effect size") report.doc(tab,title="Example of a specific statistic reporting", colspan.value="Treatment group")
You can also add a specific (or several) statistics to an existing table.
Let's say you want the default statistics (mean, median, sd etc..) plus some specific statistics like the mode or the coefficient of variation.
In this case, you can use the add.stat()
function with the pos
argument
to choose where you want to add this statistic:
# 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) report.doc(tab1.cv,title="Example of adding a coefficient of variation") # 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) # 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) report.doc(tab,title="Example of adding 2 more statistics in an existing table", colspan.value="Treatment Group")
If you want to display the row percentages instead of column percentages in
report.quali()
function, you just have to set the argument percent.col
to FALSE
:
tab=report.quali(data=datafake,y="y_logistic",x1="GROUP", total=TRUE,subjid="SUBJID",percent.col=FALSE) report.doc(tab,title="Example of row percentage reporting", colspan.value="Treatment group")
If you want to drop some levels in the table, you can use
drop.x1
drop.x2
or drop.y
if 'y' is a qualitative variable.
For example. If we just want the statistics of group A:
tab=report.quali(data=datafake,y="y_logistic",x1="GROUP", subjid="SUBJID",drop.x1=c("B","C")) report.doc(tab,title="Example of row percentage reporting", colspan.value="Treatment group")
Sometimes it can be useful to remove the missing values so that percentages are
computed only on non missing observations.
For that, just use the remove.missing
argument in report.quali
:
tab=report.quali(data=datafake,y="y_logistic",x1="GROUP", remove.missing=TRUE) report.doc(tab,title="Example of dropping missing values", colspan.value="Treatment group")
tab=report.quali(data=datafake, y="y_logistic",x1="GROUP", subjid="SUBJID",remove.missing=T) # The default output report.doc(tab) # The transposed output report.doc(transpose(tab))
mod=lm(y_numeric~GROUP,data=datafake) pairs=pairs(emmeans(mod,~GROUP)) tab=report.lsmeans(pairs,transpose=TRUE) report.doc(tab,title="Example of transposing LS-Means in column", colspan.value="Treatment group")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.