add.stat.desc enables to add a specific quantitative statistic into an existing table of statistics.

add.stat(tab, data, func.stat, func.stat.name, pos, ...)

# S3 method for desc
add.stat(tab, data, func.stat, func.stat.name, pos = NULL,
  ...)

Arguments

tab

A desc object

data

The data frame used to create tab

func.stat

Passed to report.quanti function

func.stat.name

Passed to report.quanti function

pos

Numeric used to specify the position of the new statistics

...

Other parameters

Value

A "quanti" desc object (desc$type.desc equal to "quanti")

Details

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.

See also

Examples

# 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
#> #> ############################################ #> #> ############################################ #> #> Statistics A (N=30) B (N=21) C (N=17) Total (N=68) #> 6 N 180 120 96 396 #> 11 Coef. Var 1.03 0.64 0.65 0.86 #> 3 Mean (SD) 1.46(1.50) 3.15(2.00) 3.87(2.52) 2.56(2.20) #> 4 Median 1.59 3.75 4.73 2.71 #> 2 [Q1;Q3] [0.45;2.50] [2.46;4.44] [3.44;5.30] [1.04;4.33] #> 1 [Min;Max] [-2.34;4.36] [-2.44;6.19] [-2.99;7.96] [-2.99;7.96] #> 5 Missing 4 4 2 10 #> #> ############################################ #>
# 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
#> #> ############################################ #> #> ############################################ #> #> TIMEPOINT Statistics A (N=30) B (N=21) C (N=17) Total (N=68) #> 1 D0 N 30 20 16 66 #> 2 D0 Coef. Var -0.92 -1.62 -0.78 -1.04 #> 3 D0 Mean (SD) -0.93(0.86) -0.67(1.09) -1.19(0.92) -0.92(0.95) #> 4 D0 Median -0.82 -0.69 -1.26 -0.86 #> 5 D0 [Q1;Q3] [-1.59;-0.16] [-1.39;-0.06] [-1.62;-0.83] [-1.55;-0.16] #> 6 D0 [Min;Max] [-2.34;0.36] [-2.44;2.10] [-2.99;0.66] [-2.99;2.10] #> 7 D0 Missing 1 1 0 2 #> 8 #> 9 D1 N 30 20 16 66 #> 10 D1 Coef. Var 0.57 0.31 0.14 0.52 #> 11 D1 Mean (SD) 1.83(1.04) 4.17(1.28) 4.98(0.69) 3.33(1.73) #> 12 D1 Median 1.78 4.19 5.08 3.57 #> 13 D1 [Q1;Q3] [ 0.94; 2.54] [ 3.23; 4.92] [ 4.58; 5.46] [ 1.78; 4.91] #> 14 D1 [Min;Max] [ 0.11;3.88] [ 1.48;6.19] [ 3.80;6.23] [ 0.11;6.23] #> 15 D1 Missing 1 0 0 1 #> 16 #> 17 D2 N 30 20 16 66 #> 18 D2 Coef. Var 0.60 0.22 0.28 0.51 #> 19 D2 Mean (SD) 1.97(1.17) 4.04(0.89) 4.90(1.36) 3.32(1.70) #> 20 D2 Median 1.66 4.19 5.06 3.57 #> 21 D2 [Q1;Q3] [ 1.23; 2.86] [ 3.62; 4.36] [ 4.34; 5.20] [ 1.89; 4.44] #> 22 D2 [Min;Max] [-0.18;4.36] [ 2.03;5.63] [ 2.39;7.96] [-0.18;7.96] #> 23 D2 Missing 1 1 0 2 #> 24 #> 25 D3 N 30 20 16 66 #> 26 D3 Coef. Var 0.66 0.25 0.22 0.56 #> 27 D3 Mean (SD) 1.78(1.17) 3.81(0.94) 5.07(1.12) 3.15(1.75) #> 28 D3 Median 1.78 3.63 5.22 3.15 #> 29 D3 [Q1;Q3] [ 0.93; 2.42] [ 3.13; 4.44] [ 4.11; 5.66] [ 1.80; 4.39] #> 30 D3 [Min;Max] [-0.16;3.90] [ 2.46;6.01] [ 3.16;7.37] [-0.16;7.37] #> 31 D3 Missing 0 1 1 2 #> 32 #> 33 D4 N 30 20 16 66 #> 34 D4 Coef. Var 0.46 0.25 0.20 0.52 #> 35 D4 Mean (SD) 1.83(0.85) 3.80(0.95) 5.17(1.03) 3.22(1.66) #> 36 D4 Median 1.67 3.83 4.88 3.16 #> 37 D4 [Q1;Q3] [ 1.26; 2.32] [ 3.12; 4.42] [ 4.69; 5.50] [ 1.69; 4.48] #> 38 D4 [Min;Max] [ 0.38;3.97] [ 2.31;5.41] [ 3.24;6.96] [ 0.38;6.96] #> 39 D4 Missing 1 1 1 3 #> 40 #> 41 D5 N 30 20 16 66 #> 42 D5 Coef. Var 0.53 0.33 0.22 0.45 #> 43 D5 Mean (SD) 2.27(1.20) 3.64(1.19) 4.43(0.98) 3.21(1.45) #> 44 D5 Median 2.50 3.86 4.57 3.28 #> 45 D5 [Q1;Q3] [ 1.77; 3.21] [ 2.59; 4.60] [ 3.44; 4.97] [ 2.42; 4.44] #> 46 D5 [Min;Max] [-1.19;4.31] [ 0.91;5.12] [ 2.95;6.54] [-1.19;6.54] #> 47 D5 Missing 0 0 0 0 #> #> ############################################ #>
# 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
#> #> ############################################ #> #> ############################################ #> #> TIMEPOINT Statistics A (N=30) B (N=21) C (N=17) Total (N=68) #> 1 D0 N 30 20 16 66 #> 2 D0 Coef. Var -0.92 -1.62 -0.78 -1.04 #> 3 D0 Mean (SD) -0.93(0.86) -0.67(1.09) -1.19(0.92) -0.92(0.95) #> 4 D0 Median -0.82 -0.69 -1.26 -0.86 #> 5 D0 Mode -0.42 -0.36 -0.75 -0.42 #> 6 D0 [Q1;Q3] [-1.59;-0.16] [-1.39;-0.06] [-1.62;-0.83] [-1.55;-0.16] #> 7 D0 [Min;Max] [-2.34;0.36] [-2.44;2.10] [-2.99;0.66] [-2.99;2.10] #> 8 D0 Missing 1 1 0 2 #> 9 #> 10 D1 N 30 20 16 66 #> 11 D1 Coef. Var 0.57 0.31 0.14 0.52 #> 12 D1 Mean (SD) 1.83(1.04) 4.17(1.28) 4.98(0.69) 3.33(1.73) #> 13 D1 Median 1.78 4.19 5.08 3.57 #> 14 D1 Mode 3.88 5.71 5.02 3.88 #> 15 D1 [Q1;Q3] [ 0.94; 2.54] [ 3.23; 4.92] [ 4.58; 5.46] [ 1.78; 4.91] #> 16 D1 [Min;Max] [ 0.11;3.88] [ 1.48;6.19] [ 3.80;6.23] [ 0.11;6.23] #> 17 D1 Missing 1 0 0 1 #> 18 #> 19 D2 N 30 20 16 66 #> 20 D2 Coef. Var 0.60 0.22 0.28 0.51 #> 21 D2 Mean (SD) 1.97(1.17) 4.04(0.89) 4.90(1.36) 3.32(1.70) #> 22 D2 Median 1.66 4.19 5.06 3.57 #> 23 D2 Mode 1.35 4.35 6.58 1.35 #> 24 D2 [Q1;Q3] [ 1.23; 2.86] [ 3.62; 4.36] [ 4.34; 5.20] [ 1.89; 4.44] #> 25 D2 [Min;Max] [-0.18;4.36] [ 2.03;5.63] [ 2.39;7.96] [-0.18;7.96] #> 26 D2 Missing 1 1 0 2 #> 27 #> 28 D3 N 30 20 16 66 #> 29 D3 Coef. Var 0.66 0.25 0.22 0.56 #> 30 D3 Mean (SD) 1.78(1.17) 3.81(0.94) 5.07(1.12) 3.15(1.75) #> 31 D3 Median 1.78 3.63 5.22 3.15 #> 32 D3 Mode 2.54 4.44 5.66 2.54 #> 33 D3 [Q1;Q3] [ 0.93; 2.42] [ 3.13; 4.44] [ 4.11; 5.66] [ 1.80; 4.39] #> 34 D3 [Min;Max] [-0.16;3.90] [ 2.46;6.01] [ 3.16;7.37] [-0.16;7.37] #> 35 D3 Missing 0 1 1 2 #> 36 #> 37 D4 N 30 20 16 66 #> 38 D4 Coef. Var 0.46 0.25 0.20 0.52 #> 39 D4 Mean (SD) 1.83(0.85) 3.80(0.95) 5.17(1.03) 3.22(1.66) #> 40 D4 Median 1.67 3.83 4.88 3.16 #> 41 D4 Mode 2.32 3.50 4.88 2.32 #> 42 D4 [Q1;Q3] [ 1.26; 2.32] [ 3.12; 4.42] [ 4.69; 5.50] [ 1.69; 4.48] #> 43 D4 [Min;Max] [ 0.38;3.97] [ 2.31;5.41] [ 3.24;6.96] [ 0.38;6.96] #> 44 D4 Missing 1 1 1 3 #> 45 #> 46 D5 N 30 20 16 66 #> 47 D5 Coef. Var 0.53 0.33 0.22 0.45 #> 48 D5 Mean (SD) 2.27(1.20) 3.64(1.19) 4.43(0.98) 3.21(1.45) #> 49 D5 Median 2.50 3.86 4.57 3.28 #> 50 D5 Mode 1.87 3.89 2.95 1.87 #> 51 D5 [Q1;Q3] [ 1.77; 3.21] [ 2.59; 4.60] [ 3.44; 4.97] [ 2.42; 4.44] #> 52 D5 [Min;Max] [-1.19;4.31] [ 0.91;5.12] [ 2.95;6.54] [-1.19;6.54] #> 53 D5 Missing 0 0 0 0 #> #> ############################################ #>