Hazard ratios and p-values are computed taking into account time-to cardiovascular event and censoring.
compareGroups
package from CRAN and then load it by typing:install.packages("compareGroups")
library(compareGroups)
compareGroups
package:data(predimed)
by using Surv
function from survival
package.
predimed$tevent <- with(predimed, Surv(toevent, event == "Yes"))
label(predimed$tevent) <- "CV event"
compareGroups
function.Note the use of formula
argument as usual in R
, so “.” indicates all variables in the dataset while “-” sign indicates removing. Put time-to-cardiovascular event computed at previous step on left side of “~” sign. Store the results in an object that can be used afterwards to perform plots or bivariate table itself. By the argument method
we set wtn
and p14
varible to be reported as median and quartiles instead of mean and standard deviation.
res <- compareGroups(tevent ~ . - toevent - event, data = predimed, method = c(wtn = 2, p14 = 2))
creaTable
functionand passing the previous object computed by compareGroups
function (res
). Using this function you can customize how categorical variables are displayed (only percertage or absolute frequencies or both) by type
argument or whether standard deviation appears inside brackets or separated by plus/minus symbol by sd.type
argument. Also note the use of hide.no
category which is useful to hide “no” level for those binary variables. If you only want to show “Female” category use hide
argument for sex
variable indicating which category is going to be hiden. This argument also applies to categorical variables with more than two categories. To show how many individuals have non-missing values in each described variable, set hide.n
argument to TRUE
. In order to show p-value for each category show.p.overall=FALSE
. To specify the number of decimal digits to show use digits
arguments. In this example p14
have no decimals and for hormo
only one digit. Finally, do not forget to type show.ratio=TRUE
to display Hazard Ratio.
restab <- createTable(res, digits = c(p14 = 0, hormo=1), type = 1, sd.type = 2, hide = c(sex = "Male"), hide.no = "no", show.n = TRUE, show.ratio = TRUE, show.p.overall = FALSE)
This can be printed in the R
console using the method print
, i.e. just typing the name of the object:
restab
--------Summary descriptives table by 'CV event'---------
_________________________________________________________________________________
No event Event HR p.ratio N
N=6072 N=252
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Intervention group: 6324
Control 32.0% 38.5% Ref. Ref.
MedDiet + Nuts 33.4% 27.8% 0.66 [0.48;0.89] 0.008
MedDiet + VOO 34.5% 33.7% 0.70 [0.53;0.94] 0.018
Sex: Female 58.4% 40.1% 0.49 [0.38;0.63] <0.001 6324
Age 66.9±6.14 69.4±6.65 1.06 [1.04;1.09] <0.001 6324
Smoking: 6324
Never 62.2% 45.2% Ref. Ref.
Current 13.3% 19.4% 1.96 [1.40;2.74] <0.001
Former 24.5% 35.3% 2.02 [1.53;2.67] <0.001
Body mass index 30.0±3.81 29.8±3.92 0.99 [0.96;1.02] 0.455 6324
Waist circumference 100±10.6 102±10.6 1.02 [1.01;1.03] 0.003 6324
Waist-to-height ratio 0.63±0.07 0.63±0.07 5.27 [0.83;33.6] 0.079 6324
Hypertension 82.8% 83.3% 1.10 [0.79;1.53] 0.578 6324
Type-2 diabetes 46.8% 63.9% 1.88 [1.46;2.44] <0.001 6324
Dyslipidemia 72.9% 59.9% 0.62 [0.49;0.80] <0.001 6324
Family history of premature CHD 22.7% 20.2% 0.93 [0.68;1.26] 0.640 6324
Hormone-replacement therapy 1.8% 0.4% 0.29 [0.04;2.10] 0.223 5661
MeDiet Adherence score 9 [7;10] 8 [7;10] 0.88 [0.83;0.94] <0.001 6324
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Or if you want to change some bivariate table header, such “p-value” instead of “p.ratio” use header.labels
argument:
print(restab, header.labels = c(p.ratio = "p-value"))
--------Summary descriptives table by 'CV event'---------
_________________________________________________________________________________
No event Event HR p-value N
N=6072 N=252
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Intervention group: 6324
Control 32.0% 38.5% Ref. Ref.
MedDiet + Nuts 33.4% 27.8% 0.66 [0.48;0.89] 0.008
MedDiet + VOO 34.5% 33.7% 0.70 [0.53;0.94] 0.018
Sex: Female 58.4% 40.1% 0.49 [0.38;0.63] <0.001 6324
Age 66.9±6.14 69.4±6.65 1.06 [1.04;1.09] <0.001 6324
Smoking: 6324
Never 62.2% 45.2% Ref. Ref.
Current 13.3% 19.4% 1.96 [1.40;2.74] <0.001
Former 24.5% 35.3% 2.02 [1.53;2.67] <0.001
Body mass index 30.0±3.81 29.8±3.92 0.99 [0.96;1.02] 0.455 6324
Waist circumference 100±10.6 102±10.6 1.02 [1.01;1.03] 0.003 6324
Waist-to-height ratio 0.63±0.07 0.63±0.07 5.27 [0.83;33.6] 0.079 6324
Hypertension 82.8% 83.3% 1.10 [0.79;1.53] 0.578 6324
Type-2 diabetes 46.8% 63.9% 1.88 [1.46;2.44] <0.001 6324
Dyslipidemia 72.9% 59.9% 0.62 [0.49;0.80] <0.001 6324
Family history of premature CHD 22.7% 20.2% 0.93 [0.68;1.26] 0.640 6324
Hormone-replacement therapy 1.8% 0.4% 0.29 [0.04;2.10] 0.223 5661
MeDiet Adherence score 9 [7;10] 8 [7;10] 0.88 [0.83;0.94] <0.001 6324
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Or if you want to create a PDF document with the table in a publish-ready format
export2pdf(restab, file = "example3.pdf", header.labels = c(p.ratio = "p-value"))
To create tables in PDF you must have some LaTeX compiler installed on your computer.