Description Usage Arguments Details Value See Also Examples
View source: R/report.quanti.R
report.quanti
Returns quantitative descriptive statistics such as mean, median, standard deviation etc...
For more examples see the website: ClinReport website
1 2 3 4 5 |
data |
Data.frame object |
y |
Character indicating a numerical vector in the data frame passed to |
x1 |
Character indicating a factor in the data (levels will be displayed in columns) |
x2 |
Character indicating a factor in the data (levels will be displayed in lines) |
y.label |
Character Indicates the label for y parameter to be displayed in the title of the table |
round |
Numeric to indicate how to round statistics |
total |
Logical to indicate if a "Total" column should be added |
scientific |
Logical Indicates if statistics should be displayed in scientific notations or not |
digits |
Numeric (used if scientific=TRUE) to indicate how many digits to use in scientific notation |
at.row |
Character Used to space the results (see examples) |
subjid |
Character Indicates the column in which there is the subject Id to add the number of subjects in the column header if x1 and x2 are not null. |
geomean |
Logical If yes geometric mean is calculated instead of arithmetic mean: |
add.mad |
Logical If yes the Median Absolute Deviance is added to the median statistics (see function |
default.stat |
Logical (default to TRUE). If FALSE you can specify your own example |
func.stat |
Function. If specified then default.stat=FALSE and only the specified statistic is reported |
stat.name |
Character. Indicates the name of the variable that report the statistics Default = "Statistics" |
func.stat.name |
Character. Used only if default.stat=FALSE. Indicates the name of specific statistic you want to report |
drop.x1 |
Character. Indicates one or several levels of the x1 factor that you want to drop in the result |
drop.x2 |
Character. Indicates one or several levels of the x2 factor that you want to drop in the result |
This function computes and reports quantitative statistics on y
. And can gives the statistics by level of two factors (x1
in columns and/or x2
in rows).
See the example to show the results. If total=TRUE
, the last column is the statistics
performed overall levels of x1
for each levels of x2
.
Quantiles are calculated using type 3 (SAS presumed definition) algorithms, but even though,
some differences between SAS and R can appear on quantile values.
"geomean" compute the geometric mean defined as exp(mean(log(y))). The values below or equal 0 are removed and a message is printed to indicate how many values were deleted to calculate the geometric mean.
N
returns the number of observations (including NA values)
stat.name is automatically transformed using make.names
function.
A desc object.
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
data(datafake)
# Quantitative statistics with no factor
report.quanti(data=datafake,y="y_numeric",total=TRUE,y.label="Awesome results")
#' # Quantitative statistics with no factor with geometric mean (option geomean=TRUE)
report.quanti(data=datafake,y="y_numeric",y.label="Awesome results",geomean=TRUE)
# Quantitative statistics with one factor
report.quanti(data=datafake,y="y_numeric",x1="GROUP")
# One factor with total column
report.quanti(data=datafake,y="y_numeric",x1="GROUP",total=TRUE)
# Quantitative statistics with two factors
report.quanti(data=datafake,y="y_numeric",x1="GROUP",x2="TIMEPOINT")
# Quantitative statistics with two factors and a total column
report.quanti(data=datafake,y="y_numeric",x1="GROUP",x2="TIMEPOINT",total=TRUE)
# Add median absolute deviance to the median statistics
report.quanti(data=datafake,y="y_numeric",x1="GROUP",x2="TIMEPOINT",total=TRUE,add.mad=TRUE)
# Quantitative statistics with spacing rows (option at.row)
report.quanti(data=datafake,y="y_numeric",x1="GROUP",
x2="TIMEPOINT",total=TRUE,at.row="TIMEPOINT")
# Add number of subjects in headers (option subjid)
tab=report.quanti(data=datafake,y="y_numeric",x1="GROUP",
x2="TIMEPOINT",total=TRUE,at.row="TIMEPOINT",subjid="SUBJID")
# Print tab output
tab
#Getting a specific statistic and not the default ones
mystat=function(x) quantile(x,0.99,na.rm=TRUE)
tab=report.quanti(data=datafake,y="y_numeric",x1="GROUP",
x2="TIMEPOINT",total=TRUE,subjid="SUBJID",
func.stat=mystat,func.stat.name="99% quantile")
tab
mystat2=function(x) mean(x,na.rm=TRUE)/sd(x,na.rm=TRUE)
tab=report.quanti(data=datafake,y="y_numeric",x1="GROUP",
total=TRUE,subjid="SUBJID",func.stat=mystat2,
func.stat.name="Coefficient of variation")
tab
mode=function(x) {
x=na.omit(x)
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
tab=report.quanti(data=datafake,y="y_numeric",
func.stat=mode,func.stat.name="Mode")
#Getting raw output
tab$raw.output
#Getting a data.frame version of the output
tab$output
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.