2021-08-30
compareGroups 的使用:descrTable(fomula,data=) :
formula: group~variable(. 表示全部;V1+V2;.-V1-V2 )
其他参数:select=; subset= ; method=
strataTable() :
输入:之前画的表+“分层依据”
输出:分层基线表
export2<>(data,file)
rm(list = ls())
setwd("D:/R/R-4.0.5/bin/project_practise/fuxian/baseline_table")
# 加载R包
#install.packages("compareGroups")
suppressPackageStartupMessages(library(compareGroups))
这1步是重点
需要熟练掌握factor 和label 的使用
# 加载数据
data(predimed)
head(predimed)
## group sex age smoke bmi waist wth htn diab hyperchol
## 1 Control Male 58 Former 33.53 122 0.7530864 No No Yes
## 2 Control Male 77 Current 31.05 119 0.7300614 Yes Yes No
## 4 MedDiet + VOO Female 72 Former 30.86 106 0.6543210 No Yes No
## 5 MedDiet + Nuts Male 71 Former 27.68 118 0.6941177 Yes No Yes
## 6 MedDiet + VOO Female 79 Never 35.94 129 0.8062500 Yes No Yes
## 8 Control Male 63 Former 41.66 143 0.8033708 Yes Yes Yes
## famhist hormo p14 toevent event
## 1 No No 10 5.374401 Yes
## 2 No No 10 6.097194 No
## 4 Yes No 8 5.946612 No
## 5 No No 8 2.907598 Yes
## 6 No No 9 4.761123 No
## 8 No <NA> 9 3.148528 Yes
str(predimed)
## 'data.frame': 6324 obs. of 15 variables:
## $ group : Factor w/ 3 levels "Control","MedDiet + Nuts",..: 1 1 3 2 3 1 3 3 1 1 ...
## ..- attr(*, "label")= chr "Intervention group"
## $ sex : Factor w/ 2 levels "Male","Female": 1 1 2 1 2 1 2 1 1 1 ...
## ..- attr(*, "label")= chr "Sex"
## $ age : num 58 77 72 71 79 63 75 66 71 76 ...
## ..- attr(*, "label")= chr "Age"
## $ smoke : Factor w/ 3 levels "Never","Current",..: 3 2 3 3 1 3 1 1 3 2 ...
## ..- attr(*, "label")= chr "Smoking"
## $ bmi : num 33.5 31.1 30.9 27.7 35.9 ...
## ..- attr(*, "label")= chr "Body mass index"
## $ waist : num 122 119 106 118 129 143 88 85 90 79 ...
## ..- attr(*, "label")= chr "Waist circumference"
## $ wth : num 0.753 0.73 0.654 0.694 0.806 ...
## ..- attr(*, "label")= chr "Waist-to-height ratio"
## $ htn : Factor w/ 2 levels "No","Yes": 1 2 1 2 2 2 1 2 2 2 ...
## ..- attr(*, "label")= chr "Hypertension"
## $ diab : Factor w/ 2 levels "No","Yes": 1 2 2 1 1 2 2 2 1 2 ...
## ..- attr(*, "label")= chr "Type-2 diabetes"
## $ hyperchol: Factor w/ 2 levels "No","Yes": 2 1 1 2 2 2 2 1 2 1 ...
## ..- attr(*, "label")= chr "Dyslipidemia"
## $ famhist : Factor w/ 2 levels "No","Yes": 1 1 2 1 1 1 1 2 1 1 ...
## ..- attr(*, "label")= chr "Family history of premature CHD"
## $ hormo : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 NA NA 1 1 1 ...
## ..- attr(*, "label")= chr "Hormone-replacement therapy"
## $ p14 : num 10 10 8 8 9 9 8 9 14 9 ...
## ..- attr(*, "label")= chr "MeDiet Adherence score"
## $ toevent : num 5.37 6.1 5.95 2.91 4.76 ...
## ..- attr(*, "label")= chr "follow-up to main event (years)"
## $ event : Factor w/ 2 levels "No","Yes": 2 1 1 2 1 2 1 1 2 1 ...
## ..- attr(*, "label")= Named chr "AMI, stroke, or CV Death"
## .. ..- attr(*, "names")= chr "varlabel"
准备数据主要要做2件事 * 分类变量需要变成因子形式,注意是否为有序变量 * 为变量加上标签,生成的三线表会显示标签
factor() 函数的使用:levels:加上自己想要的顺序
labels: 必须在有levels 之后才能用,添加标签
ordered:等级数据,注意等级别错了
descrTable()函数绘制三线表# 描述总研究人群(overall列)
descrTable(~.,data=predimed)
##
## --------Summary descriptives table ---------
##
## __________________________________________________
## [ALL] N
## N=6324
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## Intervention group: 6324
## Control 2042 (32.3%)
## MedDiet + Nuts 2100 (33.2%)
## MedDiet + VOO 2182 (34.5%)
## Sex: 6324
## Male 2679 (42.4%)
## Female 3645 (57.6%)
## Age 67.0 (6.17) 6324
## Smoking: 6324
## Never 3892 (61.5%)
## Current 858 (13.6%)
## Former 1574 (24.9%)
## Body mass index 30.0 (3.82) 6324
## Waist circumference 100 (10.6) 6324
## Waist-to-height ratio 0.63 (0.07) 6324
## Hypertension: 6324
## No 1089 (17.2%)
## Yes 5235 (82.8%)
## Type-2 diabetes: 6324
## No 3322 (52.5%)
## Yes 3002 (47.5%)
## Dyslipidemia: 6324
## No 1746 (27.6%)
## Yes 4578 (72.4%)
## Family history of premature CHD: 6324
## No 4895 (77.4%)
## Yes 1429 (22.6%)
## Hormone-replacement therapy: 5661
## No 5564 (98.3%)
## Yes 97 (1.71%)
## MeDiet Adherence score 8.68 (1.94) 6324
## follow-up to main event (years) 4.36 (1.69) 6324
## AMI, stroke, or CV Death: 6324
## No 6072 (96.0%)
## Yes 252 (3.98%)
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
# 分组描述
descrTable(group~.,data=predimed)
##
## --------Summary descriptives table by 'Intervention group'---------
##
## ____________________________________________________________________________________
## Control MedDiet + Nuts MedDiet + VOO p.overall
## N=2042 N=2100 N=2182
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## Sex: <0.001
## Male 812 (39.8%) 968 (46.1%) 899 (41.2%)
## Female 1230 (60.2%) 1132 (53.9%) 1283 (58.8%)
## Age 67.3 (6.28) 66.7 (6.02) 67.0 (6.21) 0.003
## Smoking: 0.444
## Never 1282 (62.8%) 1259 (60.0%) 1351 (61.9%)
## Current 270 (13.2%) 296 (14.1%) 292 (13.4%)
## Former 490 (24.0%) 545 (26.0%) 539 (24.7%)
## Body mass index 30.3 (3.96) 29.7 (3.77) 29.9 (3.71) <0.001
## Waist circumference 101 (10.8) 100 (10.6) 100 (10.4) 0.045
## Waist-to-height ratio 0.63 (0.07) 0.62 (0.06) 0.63 (0.06) <0.001
## Hypertension: 0.249
## No 331 (16.2%) 362 (17.2%) 396 (18.1%)
## Yes 1711 (83.8%) 1738 (82.8%) 1786 (81.9%)
## Type-2 diabetes: 0.017
## No 1072 (52.5%) 1150 (54.8%) 1100 (50.4%)
## Yes 970 (47.5%) 950 (45.2%) 1082 (49.6%)
## Dyslipidemia: 0.423
## No 563 (27.6%) 561 (26.7%) 622 (28.5%)
## Yes 1479 (72.4%) 1539 (73.3%) 1560 (71.5%)
## Family history of premature CHD: 0.581
## No 1580 (77.4%) 1640 (78.1%) 1675 (76.8%)
## Yes 462 (22.6%) 460 (21.9%) 507 (23.2%)
## Hormone-replacement therapy: 0.850
## No 1811 (98.3%) 1835 (98.4%) 1918 (98.2%)
## Yes 31 (1.68%) 30 (1.61%) 36 (1.84%)
## MeDiet Adherence score 8.44 (1.94) 8.81 (1.90) 8.77 (1.97) <0.001
## follow-up to main event (years) 4.09 (1.74) 4.31 (1.70) 4.64 (1.60) <0.001
## AMI, stroke, or CV Death: 0.064
## No 1945 (95.2%) 2030 (96.7%) 2097 (96.1%)
## Yes 97 (4.75%) 70 (3.33%) 85 (3.90%)
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
# 只描述部分特征
var1+var2或.-var1-var2描述部分变量subset =<expr> 描述亚组selec = list(expr1,expr2) 进行复杂的选择## 描述部分变量
descrTable(group~sex+age+smoke+bmi+waist+htn+diab,data=predimed)
##
## --------Summary descriptives table by 'Intervention group'---------
##
## _______________________________________________________________________
## Control MedDiet + Nuts MedDiet + VOO p.overall
## N=2042 N=2100 N=2182
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## Sex: <0.001
## Male 812 (39.8%) 968 (46.1%) 899 (41.2%)
## Female 1230 (60.2%) 1132 (53.9%) 1283 (58.8%)
## Age 67.3 (6.28) 66.7 (6.02) 67.0 (6.21) 0.003
## Smoking: 0.444
## Never 1282 (62.8%) 1259 (60.0%) 1351 (61.9%)
## Current 270 (13.2%) 296 (14.1%) 292 (13.4%)
## Former 490 (24.0%) 545 (26.0%) 539 (24.7%)
## Body mass index 30.3 (3.96) 29.7 (3.77) 29.9 (3.71) <0.001
## Waist circumference 101 (10.8) 100 (10.6) 100 (10.4) 0.045
## Hypertension: 0.249
## No 331 (16.2%) 362 (17.2%) 396 (18.1%)
## Yes 1711 (83.8%) 1738 (82.8%) 1786 (81.9%)
## Type-2 diabetes: 0.017
## No 1072 (52.5%) 1150 (54.8%) 1100 (50.4%)
## Yes 970 (47.5%) 950 (45.2%) 1082 (49.6%)
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
descrTable(group~. -sex-waist-hormo-diab-hyperchol,
data=predimed)
##
## --------Summary descriptives table by 'Intervention group'---------
##
## ____________________________________________________________________________________
## Control MedDiet + Nuts MedDiet + VOO p.overall
## N=2042 N=2100 N=2182
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## Age 67.3 (6.28) 66.7 (6.02) 67.0 (6.21) 0.003
## Smoking: 0.444
## Never 1282 (62.8%) 1259 (60.0%) 1351 (61.9%)
## Current 270 (13.2%) 296 (14.1%) 292 (13.4%)
## Former 490 (24.0%) 545 (26.0%) 539 (24.7%)
## Body mass index 30.3 (3.96) 29.7 (3.77) 29.9 (3.71) <0.001
## Waist-to-height ratio 0.63 (0.07) 0.62 (0.06) 0.63 (0.06) <0.001
## Hypertension: 0.249
## No 331 (16.2%) 362 (17.2%) 396 (18.1%)
## Yes 1711 (83.8%) 1738 (82.8%) 1786 (81.9%)
## Family history of premature CHD: 0.581
## No 1580 (77.4%) 1640 (78.1%) 1675 (76.8%)
## Yes 462 (22.6%) 460 (21.9%) 507 (23.2%)
## MeDiet Adherence score 8.44 (1.94) 8.81 (1.90) 8.77 (1.97) <0.001
## follow-up to main event (years) 4.09 (1.74) 4.31 (1.70) 4.64 (1.60) <0.001
## AMI, stroke, or CV Death: 0.064
## No 1945 (95.2%) 2030 (96.7%) 2097 (96.1%)
## Yes 97 (4.75%) 70 (3.33%) 85 (3.90%)
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## 选取亚组
descrTable(group~age+smoke+waist+hormo,
data=predimed,
subset=sex=="Female")
##
## --------Summary descriptives table by 'group'---------
##
## ________________________________________________________________________________
## Control MedDiet + Nuts MedDiet + VOO p.overall
## N=1230 N=1132 N=1283
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## Age 68.0 (5.96) 67.4 (5.57) 67.7 (5.84) 0.056
## Smoking: 0.907
## Never 1077 (87.6%) 993 (87.7%) 1115 (86.9%)
## Current 66 (5.37%) 54 (4.77%) 71 (5.53%)
## Former 87 (7.07%) 85 (7.51%) 97 (7.56%)
## Waist circumference 99.0 (11.0) 97.8 (11.0) 98.0 (10.5) 0.016
## Hormone-replacement therapy: 0.898
## No 1143 (97.4%) 1036 (97.2%) 1183 (97.0%)
## Yes 31 (2.64%) 30 (2.81%) 36 (2.95%)
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## 某个变量里面只描述亚组特征
descrTable(group ~ age + sex + smoke + waist + hormo,
data = predimed,
selec = list(hormo = sex == "Female", waist = waist > 20)) #只显示waist大于人群特征,且hormo特征里只显示女性人群的结果
##
## --------Summary descriptives table by 'Intervention group'---------
##
## ________________________________________________________________________________
## Control MedDiet + Nuts MedDiet + VOO p.overall
## N=2042 N=2100 N=2182
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## Age 67.3 (6.28) 66.7 (6.02) 67.0 (6.21) 0.003
## Sex: <0.001
## Male 812 (39.8%) 968 (46.1%) 899 (41.2%)
## Female 1230 (60.2%) 1132 (53.9%) 1283 (58.8%)
## Smoking: 0.444
## Never 1282 (62.8%) 1259 (60.0%) 1351 (61.9%)
## Current 270 (13.2%) 296 (14.1%) 292 (13.4%)
## Former 490 (24.0%) 545 (26.0%) 539 (24.7%)
## Waist circumference 101 (10.8) 100 (10.6) 100 (10.4) 0.045
## Hormone-replacement therapy: 0.898
## No 1143 (97.4%) 1036 (97.2%) 1183 (97.0%)
## Yes 31 (2.64%) 30 (2.81%) 36 (2.95%)
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## 同一个变量描述2次
descrTable(group ~ age + sex + bmi + bmi + waist + hormo,
data = predimed,
selec = list(bmi.1 = !is.na(hormo))) #第一次bmi是全体描述结果,第二次bmi是去除na值的描述结果
##
## --------Summary descriptives table by 'Intervention group'---------
##
## ________________________________________________________________________________
## Control MedDiet + Nuts MedDiet + VOO p.overall
## N=2042 N=2100 N=2182
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## Age 67.3 (6.28) 66.7 (6.02) 67.0 (6.21) 0.003
## Sex: <0.001
## Male 812 (39.8%) 968 (46.1%) 899 (41.2%)
## Female 1230 (60.2%) 1132 (53.9%) 1283 (58.8%)
## Body mass index 30.3 (3.96) 29.7 (3.77) 29.9 (3.71) <0.001
## Body mass index 30.3 (3.99) 29.7 (3.81) 30.0 (3.73) <0.001
## Waist circumference 101 (10.8) 100 (10.6) 100 (10.4) 0.045
## Hormone-replacement therapy: 0.850
## No 1811 (98.3%) 1835 (98.4%) 1918 (98.2%)
## Yes 31 (1.68%) 30 (1.61%) 36 (1.84%)
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
首先检测是分类变量还是连续性变量;
默认的连续性变量为正态分布,使用均值+标准差描述
非正态分布使用中位数+四分位数描述,使用method函数指定
str(predimed)
## 'data.frame': 6324 obs. of 15 variables:
## $ group : Factor w/ 3 levels "Control","MedDiet + Nuts",..: 1 1 3 2 3 1 3 3 1 1 ...
## ..- attr(*, "label")= chr "Intervention group"
## $ sex : Factor w/ 2 levels "Male","Female": 1 1 2 1 2 1 2 1 1 1 ...
## ..- attr(*, "label")= chr "Sex"
## $ age : num 58 77 72 71 79 63 75 66 71 76 ...
## ..- attr(*, "label")= chr "Age"
## $ smoke : Factor w/ 3 levels "Never","Current",..: 3 2 3 3 1 3 1 1 3 2 ...
## ..- attr(*, "label")= chr "Smoking"
## $ bmi : num 33.5 31.1 30.9 27.7 35.9 ...
## ..- attr(*, "label")= chr "Body mass index"
## $ waist : num 122 119 106 118 129 143 88 85 90 79 ...
## ..- attr(*, "label")= chr "Waist circumference"
## $ wth : num 0.753 0.73 0.654 0.694 0.806 ...
## ..- attr(*, "label")= chr "Waist-to-height ratio"
## $ htn : Factor w/ 2 levels "No","Yes": 1 2 1 2 2 2 1 2 2 2 ...
## ..- attr(*, "label")= chr "Hypertension"
## $ diab : Factor w/ 2 levels "No","Yes": 1 2 2 1 1 2 2 2 1 2 ...
## ..- attr(*, "label")= chr "Type-2 diabetes"
## $ hyperchol: Factor w/ 2 levels "No","Yes": 2 1 1 2 2 2 2 1 2 1 ...
## ..- attr(*, "label")= chr "Dyslipidemia"
## $ famhist : Factor w/ 2 levels "No","Yes": 1 1 2 1 1 1 1 2 1 1 ...
## ..- attr(*, "label")= chr "Family history of premature CHD"
## $ hormo : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 NA NA 1 1 1 ...
## ..- attr(*, "label")= chr "Hormone-replacement therapy"
## $ p14 : num 10 10 8 8 9 9 8 9 14 9 ...
## ..- attr(*, "label")= chr "MeDiet Adherence score"
## $ toevent : num 5.37 6.1 5.95 2.91 4.76 ...
## ..- attr(*, "label")= chr "follow-up to main event (years)"
## $ event : Factor w/ 2 levels "No","Yes": 2 1 1 2 1 2 1 1 2 1 ...
## ..- attr(*, "label")= Named chr "AMI, stroke, or CV Death"
## .. ..- attr(*, "names")= chr "varlabel"
descrTable(group~age+sex+bmi+waist+hormo,
data=predimed,
method = c(waist=2))
## Warning in cor.test.default(x, as.integer(y), method = "spearman"): Cannot
## compute exact p-value with ties
##
## --------Summary descriptives table by 'Intervention group'---------
##
## ___________________________________________________________________________________
## Control MedDiet + Nuts MedDiet + VOO p.overall
## N=2042 N=2100 N=2182
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## Age 67.3 (6.28) 66.7 (6.02) 67.0 (6.21) 0.003
## Sex: <0.001
## Male 812 (39.8%) 968 (46.1%) 899 (41.2%)
## Female 1230 (60.2%) 1132 (53.9%) 1283 (58.8%)
## Body mass index 30.3 (3.96) 29.7 (3.77) 29.9 (3.71) <0.001
## Waist circumference 101 [94.0;108] 100 [93.0;107] 100 [93.0;107] 0.085
## Hormone-replacement therapy: 0.850
## No 1811 (98.3%) 1835 (98.4%) 1918 (98.2%)
## Yes 31 (1.68%) 30 (1.61%) 36 (1.84%)
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
descrTable(group~age+sex+bmi+waist+hormo,
data=predimed)
##
## --------Summary descriptives table by 'Intervention group'---------
##
## ________________________________________________________________________________
## Control MedDiet + Nuts MedDiet + VOO p.overall
## N=2042 N=2100 N=2182
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## Age 67.3 (6.28) 66.7 (6.02) 67.0 (6.21) 0.003
## Sex: <0.001
## Male 812 (39.8%) 968 (46.1%) 899 (41.2%)
## Female 1230 (60.2%) 1132 (53.9%) 1283 (58.8%)
## Body mass index 30.3 (3.96) 29.7 (3.77) 29.9 (3.71) <0.001
## Waist circumference 101 (10.8) 100 (10.6) 100 (10.4) 0.045
## Hormone-replacement therapy: 0.850
## No 1811 (98.3%) 1835 (98.4%) 1918 (98.2%)
## Yes 31 (1.68%) 30 (1.61%) 36 (1.84%)
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
method = c(var = )
1为正态分布;2为非正态分布;3为分类变量;NA让R自己检查
利用strataTable() 函数在原有基线表的上面再加一个分组
table1 <- descrTable(group~age+bmi+waist+hormo,
data=predimed)
strataTable(table1,"sex")
## Warning in cor(as.integer(x), as.integer(y)): 标准差为零
##
## --------Summary descriptives table ---------
##
## ____________________________________________________________________________________________________________________________________
## Male Female
## __________________________________________________ ___________________________________________________
## Control MedDiet + Nuts MedDiet + VOO p.overall Control MedDiet + Nuts MedDiet + VOO p.overall
## N=812 N=968 N=899 N=1230 N=1132 N=1283
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## Age 66.4 (6.62) 65.8 (6.40) 66.1 (6.61) 0.215 68.0 (5.96) 67.4 (5.57) 67.7 (5.84) 0.056
## Body mass index 29.6 (3.45) 29.1 (3.28) 29.2 (3.28) 0.018 30.8 (4.20) 30.2 (4.08) 30.4 (3.91) 0.002
## Waist circumference 104 (9.82) 103 (9.36) 103 (9.65) 0.289 99.0 (11.0) 97.8 (11.0) 98.0 (10.5) 0.016
## Hormone-replacement therapy: . 0.898
## No 668 (100%) 799 (100%) 735 (100%) 1143 (97.4%) 1036 (97.2%) 1183 (97.0%)
## Yes 0 (0.00%) 0 (0.00%) 0 (0.00%) 31 (2.64%) 30 (2.81%) 36 (2.95%)
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
结果可以导出为word/excel/csv/pdf 格式
使用export2<> 函数
table1 <- descrTable(group~age+sex+bmi+waist+hormo,
data=predimed)
table1
##
## --------Summary descriptives table by 'Intervention group'---------
##
## ________________________________________________________________________________
## Control MedDiet + Nuts MedDiet + VOO p.overall
## N=2042 N=2100 N=2182
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
## Age 67.3 (6.28) 66.7 (6.02) 67.0 (6.21) 0.003
## Sex: <0.001
## Male 812 (39.8%) 968 (46.1%) 899 (41.2%)
## Female 1230 (60.2%) 1132 (53.9%) 1283 (58.8%)
## Body mass index 30.3 (3.96) 29.7 (3.77) 29.9 (3.71) <0.001
## Waist circumference 101 (10.8) 100 (10.6) 100 (10.4) 0.045
## Hormone-replacement therapy: 0.850
## No 1811 (98.3%) 1835 (98.4%) 1918 (98.2%)
## Yes 31 (1.68%) 30 (1.61%) 36 (1.84%)
## ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ
export2word(table1,"table1.docx")