文章目录
委屈巴巴:
好不容易从选题熬到统计,谁知道会在基线资料表还能再掉一次坑!
好羡慕能有手把手教R的,隔壁的小孩、孩爸、孩妈、孩姥爷、孩佬佬。。。。。都都都馋哭了
Q&A
Q:要不要做正态性检验
A:似乎不太见得到论文里谁声明自己做了正态性检验、方差齐性检验之类的。但是一个成熟的基线资料表,备注那里会鬼鬼祟祟地声明什么样的数据用的什么样的统计方法。自己看着办吧。
Q:到底正态性检验说的是自变量还是检验因变量
A:选择统计学方法的时候检验的是因变量Y。但是基线资料表不是得按照数据类型展示么!所以也检验X。描述性分析中,单独对每个变量进行正态性检验,W统计量大于0.05则认为数据服从正态 展示均均数,否则展示中位数。
Q:table one能检验正态性、方差齐用性吗?
A:用summary函数,会给出峰度(Kurtosis)和偏度(Skewness),偏度可以用来判断正态性。参见数据的偏度和峰度——df.skew()、df.kurt()&偏度与峰度的正态性分布判断。至于方差齐性没见到判断的地方。再说了,方差齐不齐的,又不影响X的展示。。。
讲真,看数字判断正态性真累
Q:特殊情况:一个连续变量分组变成了分类变量,每组自己还是连续变量,table one怎么展示?
A :分类以后table one展示的是百分比,也有SCI这么做
总结
- 支持连续变量和分类变量,以及 p 值和标准化均值差。通过survey包支持加权数据
CreateTableOne()
是对整个数据集进行总结。是不是正态分布,要自己检查,然后传递给参数,继而生成表格。- table one的逻辑是:表格1通常不涉及统计测试。但是,您可能需要测试不平衡,从而进一步引发研究问题。默认情况下,表格1包括多个统计检验。通过设置
test=TRUE
得到的是统计测试的P值,但是,他只告诉你,这是nonnorm
检验,具体是什么样的检验并没有说。如果你不需要具体到卡方、t检验等方式,用table one也就够了。可是怎么能不具体?用一件东西不能透彻了解用法这种事。。。 - 当然,输出的table one会告诉你数据展现方式:
(median [IQR]) 中位数 四分位数
(%) 百分比
(mean (SD)) 均值 标准差 - 对于复杂的情况,table one 会帮你 去掉 烦恼:例如贫困指数,是连续变量,我将它按照预定的阈值分成两组(X1,X2),它其实是两组连续变量的。table one 会把它识别成二分类变量,展示的是(%)。如果结局是二分类变量(是/否)。那么问题来了:我想看X1和Y的关系,应该是连续变量vs二分类变量。table one 会把它识别成二分类变量以后,我还可以这么认为吗?在这个细节上,我觉得table one 的统计是失控的。
- 即便,我没有在基线资料这一步做统计检验的打算,那么对于一个连续变量按照百分比展示,也违背了
连续变量正态分布:均值±标准差
/连续变量非正态分布:中位数±四分位数
的一般原则。
对于上述疑虑,我还没有找到明确的解法,目前最好的解法就是。。。换个包!知道解法的大佬,还请赐教,不甚感激!
包要用的好,要从了解包开始
以下是Github上table one包的说明文档
地址:https://github.com/kaz-yos/tableone
An R package to create “Table 1”, description of baseline characteristics
用于创建“表 1”的 R 包,基线特征说明
Creates “Table 1”, i.e., description of baseline patient characteristics, which is essential in every medical research. Supports both continuous and categorical variables, as well as p-values and standardized mean differences. Weighted data are supported via the survey package.
创建“表1”,即基线患者特征的描述,这在每项医学研究中都是必不可少的。支持连续变量和分类变量,以及 p 值和标准化均值差。通过survey包支持加权数据。
tableone was inspired by descriptive statistics functions in Deducer , a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for command-line users.
tableone的灵感来自Ian Fellows的基于Java的GUI包Deducer中的描述性统计函数。此软件包不需要 GUI 或 Java,适用于命令行用户。
In this table, continuous and categorical variables can be placed in any order. The p-valeus are from exact tests for pre-specified variables. For nonnormal variables, it shows median and IQR instead of mean and SD, and p-values are from nonparametric tests. Numerically coded categorical variables can be transformed on the fly with factorVars. SMD stands for standardized mean differences. For weighted data, first created a svydesign object, and use the svyCreateTableOne() function. Most other options remain the same.
- 在此表中,连续变量和分类变量可以按任意顺序放置。p-valeus来自预先指定变量的精确检验。
- 对于非正态变量,它显示中位数和 IQR,而不是平均值和 SD,
- p 值来自非参数检验。
- 数字编码的分类变量可以使用 factorVars 即时转换。
- SMD 代表标准化均数差。
- 对于加权数据,首先创建一个 svydesign 对象,并使用 svyCreateTableOne() 函数。
大多数其他选项保持不变。
## Load package
library(tableone)
## Load data
data(pbc, package = "survival")
# drop ID from variable list
vars <- names(pbc)[-1]
## Create Table 1 stratified by trt (can add more stratifying variables)
tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc,
factorVars = c("status","edema","stage"))
## Specifying nonnormal variables will show the variables appropriately,
## and show nonparametric test p-values. Specify variables in the exact
## argument to obtain the exact test p-values.
print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"),
exact = c("status","stage"), smd = TRUE,
formatOptions = list(big.mark = ","))
## Stratified by trt
## 1 2 p test SMD
## n 158 154
## time (mean (SD)) 2,015.62 (1,094.12) 1,996.86 (1,155.93) 0.883 0.017
## status (%) 0.884 exact 0.054
## 0 83 (52.5) 85 (55.2)
## 1 10 ( 6.3) 9 ( 5.8)
## 2 65 (41.1) 60 (39.0)
## trt (mean (SD)) 1.00 (0.00) 2.00 (0.00) <0.001 Inf
## age (mean (SD)) 51.42 (11.01) 48.58 (9.96) 0.018 0.270
## sex = f (%) 137 (86.7) 139 (90.3) 0.421 0.111
## ascites (mean (SD)) 0.09 (0.29) 0.06 (0.25) 0.434 0.089
## hepato (mean (SD)) 0.46 (0.50) 0.56 (0.50) 0.069 0.206
## spiders (mean (SD)) 0.28 (0.45) 0.29 (0.46) 0.886 0.016
## edema (%) 0.877 0.058
## 0 132 (83.5) 131 (85.1)
## 0.5 16 (10.1) 13 ( 8.4)
## 1 10 ( 6.3) 10 ( 6.5)
## bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm 0.171
## chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm 0.038
## albumin (mean (SD)) 3.52 (0.44) 3.52 (0.40) 0.874 0.018
## copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm <0.001
## alk.phos (median [IQR]) 1,214.50 [840.75, 2,028.00] 1,283.00 [922.50, 1,949.75] 0.812 nonnorm 0.037
## ast (mean (SD)) 120.21 (54.52) 124.97 (58.93) 0.460 0.084
## trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm 0.017
## platelet (mean (SD)) 258.75 (100.32) 265.20 (90.73) 0.555 0.067
## protime (mean (SD)) 10.65 (0.85) 10.80 (1.14) 0.197 0.146
## stage (%) 0.205 exact 0.246
## 1 12 ( 7.6) 4 ( 2.6)
## 2 35 (22.2) 32 (20.8)
## 3 56 (35.4) 64 (41.6)
## 4 55 (34.8) 54 (35.1)
This version of tableone package for R is developmetal, and may not be available from the CRAN. You can install it using one of the following way.
这个版本的 R.tableone 包是 developmetal,可能无法从 CRAN 获得。您可以使用以下方法之一安装它。
Direct installation from github
从 github 直接安装
You first need to install the devtools package to do the following. You can choose from the latest stable version and the latest development version.
首先需要安装 devtools 包才能执行以下操作。您可以从最新的稳定版本和最新的开发版本中进行选择。
- Install devtools (if you do not have it already)
install.packages("devtools")
- Install directly from github (develop branch)
devtools::install_github(repo = "kaz-yos/tableone", ref = "develop")
Using devtools may requires some preparation, please see the following link for information.
使用 devtools 可能需要一些准备,请参阅以下链接以获取信息。
https://www.rstudio.com/projects/devtools/
这是table one包的help
以下是关于tableone的介绍的翻译:
tableone简介
- 作者:Kazuki Yoshida
- 日期:2020年7月25日
什么是tableone?
tableone包是一个R包,用于简化构建“表1”的过程,即在生物医学研究论文中常见的患者基线特征表。该包可以总结混合在同一个表中的连续和分类变量。分类变量可以汇总为计数和/或百分比。连续变量可以以“正态”方式(均值和标准差)或“非正态”方式(中位数和四分位数范围)汇总。
加载包
## tableone包本身
library(tableone)
## Mayo Clinic的PBC数据的survival包
library(survival)
data(pbc)
单组汇总
最简单的用例是对整个数据集进行总结。只需将数据框传递给主要的工作函数CreateTableOne()
。你可以看到数据集中有418名患者。
CreateTableOne(data = pbc)
分类变量转换
大多数分类变量都以数字编码,因此我们要么必须将它们转换为数据集中的因子,要么使用factorVars
参数进行即时转换。此外,最好通过vars
参数指定要汇总的变量,并排除ID变量。
我们如何知道哪些是数字编码的分类变量呢?请查看您的数据字典(在本例中为help(pbc)
)。这次我将结果对象保存在一个变量中。
## 获取变量名称
dput(names(pbc))
c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato",
"spiders", "edema", "bili", "chol", "albumin", "copper", "alk.phos",
"ast", "trig", "platelet", "protime", "stage")
## 要汇总的变量向量
myVars <- c("time", "status", "trt", "age", "sex", "ascites", "hepato",
"spiders", "edema", "bili", "chol", "albumin", "copper", "alk.phos",
"ast", "trig", "platelet", "protime", "stage")
## 需要转换的分类变量的向量
catVars <- c("status", "trt", "ascites", "hepato",
"spiders", "edema", "stage")
## 创建TableOne对象
tab2 <- CreateTableOne(vars = myVars, data = pbc, factorVars = catVars)
以更可解释的方式呈现
现在更容易解释了。二元分类变量被汇总为第二级别的计数和百分比。例如,如果它被编码为0和1,则汇总“1”级别。对于3+类别变量,会汇总所有级别。
请记住,在排除缺失值后计算百分比。
tab2
显示分类变量的所有级别
如果您想显示所有级别,可以使用showAllLevels
参数传递给print()
方法。
print(tab2, showAllLevels = TRUE, formatOptions = list(big.mark = ","))
包括缺失信息的详细信息
如果需要更详细的信息,包括数量/比例的缺失值,请在结果对象上使用summary()
方法。首先显示连续变量,然后显示分类变量。
summary(tab2)
总结非正态变量
除了时间、年龄、白蛋白和血小板之外,大多数连续变量都高度偏斜(生物标志物通常具有强烈的正偏分布)。以非正态参数对它们进行汇总可能更合适。
tab3 <- CreateTableOne(vars = myVars, data = pbc, factorVars = catVars,
test = FALSE,
includeNA = TRUE,
nonnormal = c("bili", "chol", "copper", "alk.phos", "ast", "trig"))
print(tab3, showAllLevels = TRUE)
不要进行统计测试
表格1通常不涉及统计测试。但是,您可能需要测试不平衡,从而进一步引发研究问题。默认情况下,表格1包括多个统计检验。在这个例子中,让我们禁用它们。
tab4 <- CreateTableOne(vars = myVars, data = pbc, factorVars = catVars,
test = FALSE,
includeNA = TRUE)
print(tab4, showAllLevels = TRUE, quote = FALSE)
根据分类变量拆分表格
如果要根据分类变量拆分表格,可以使用strata
参数。
tab5 <- CreateTableOne(vars = myVars, data = pbc, factorVars = catVars,
strata = "stage",
test = FALSE,
includeNA = TRUE)
print(tab5, showAllLevels = TRUE)
将表格1保存为CSV
使用WriteCsv()
函数可以将表格1对象保存为CSV文件。
WriteCsv(tab4, file = "table1.csv")
以上是有关tableone包的简要介绍和示例。这个包是用于在生物医学研究中创建表1的有用工具,帮助研究人员汇总和比较患者基线特征。如果您需要更多详细信息或有其他问题,请随时提出。
SMD 使用标准化均值差
Kazuki Yoshida
2022年03月27日
标准化均值差
标准化均值差是一种衡量一个或多个变量下两个组均值之间距离的指标。在实际应用中,它经常被用作在倾向评分匹配之前和之后个体协变量的平衡度量。由于它是标准化的,因此可以比较不同尺度的变量。
有关定义,请参阅 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3144483
使用tableone可以轻松计算标准化均值差。此包中的所有标准化均值差都是绝对值,因此没有方向性。
加载包
## tableone package itself
library(tableone)
## PS matching
library(Matching)
## Weighted analysis
library(survey)
## Reorganizing data
library(reshape2)
## plotting
library(ggplot2)
加载数据
The right heart catheterization dataset is available at https://biostat.app.vumc.org/wiki/Main/DataSets. This dataset was originally used in Connors et al. JAMA 1996;276:889-897, and has been made publicly available.
Right heart cath dataset
rhc <- read.csv("https://biostat.app.vumc.org/wiki/pub/Main/DataSets/rhc.csv")
未匹配表格
在50个协变量中,有32个协变量的标准化均值差大于0.1,这通常被认为是重要的协变量不平衡的标志(https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3144483/#s11title)。
## Covariates
vars <- c("age","sex","race","edu","income","ninsclas","cat1","das2d3pc","dnr1",
"ca","surv2md1","aps1","scoma1","wtkilo1","temp1","meanbp1","resp1",
"hrt1","pafi1","paco21","ph1","wblc1","hema1","sod1","pot1","crea1",
"bili1","alb1","resp","card","neuro","gastr","renal","meta","hema",
"seps","trauma","ortho","cardiohx","chfhx","dementhx","psychhx",
"chrpulhx","renalhx","liverhx","gibledhx","malighx","immunhx",
"transhx","amihx")
## Construct a table
tabUnmatched <- CreateTableOne(vars = vars, strata = "swang1", data = rhc, test = FALSE)
## Show table with SMD
print(tabUnmatched, smd = TRUE)
Stratified by swang1
No RHC RHC SMD
n 3551 2184
age (mean (SD)) 61.76 (17.29) 60.75 (15.63) 0.061
sex = Male (%) 1914 (53.9) 1278 (58.5) 0.093
race (%) 0.036
black 585 (16.5) 335 (15.3)
other 213 ( 6.0) 142 ( 6.5)
white 2753 (77.5) 1707 (78.2)
edu (mean (SD)) 11.57 (3.13) 11.86 (3.16) 0.091
income (%) 0.142
$11-$25k 713 (20.1) 452 (20.7)
$25-$50k 500 (14.1) 393 (18.0)
> $50k 257 ( 7.2) 194 ( 8.9)
Under $11k 2081 (58.6) 1145 (52.4)
ninsclas (%) 0.194
Medicaid 454 (12.8) 193 ( 8.8)
Medicare 947 (26.7) 511 (23.4)
Medicare & Medicaid 251 ( 7.1) 123 ( 5.6)
No insurance 186 ( 5.2) 136 ( 6.2)
Private 967 (27.2) 731 (33.5)
Private & Medicare 746 (21.0) 490 (22.4)
cat1 (%) 0.583
ARF 1581 (44.5) 909 (41.6)
CHF 247 ( 7.0) 209 ( 9.6)
COPD 399 (11.2) 58 ( 2.7)
Cirrhosis 175 ( 4.9) 49 ( 2.2)
Colon Cancer 6 ( 0.2) 1 ( 0.0)
Coma 341 ( 9.6) 95 ( 4.3)
Lung Cancer 34 ( 1.0) 5 ( 0.2)
MOSF w/Malignancy 241 ( 6.8) 158 ( 7.2)
MOSF w/Sepsis 527 (14.8) 700 (32.1)
das2d3pc (mean (SD)) 20.37 (5.48) 20.70 (5.03) 0.063
dnr1 = Yes (%) 499 (14.1) 155 ( 7.1) 0.228
ca (%) 0.107
Metastatic 261 ( 7.4) 123 ( 5.6)
No 2652 (74.7) 1727 (79.1)
Yes 638 (18.0) 334 (15.3)
surv2md1 (mean (SD)) 0.61 (0.19) 0.57 (0.20) 0.198
aps1 (mean (SD)) 50.93 (18.81) 60.74 (20.27) 0.501
scoma1 (mean (SD)) 22.25 (31.37) 18.97 (28.26) 0.110
wtkilo1 (mean (SD)) 65.04 (29.50) 72.36 (27.73) 0.256
temp1 (mean (SD)) 37.63 (1.74) 37.59 (1.83) 0.021
meanbp1 (mean (SD)) 84.87 (38.87) 68.20 (34.24) 0.455
resp1 (mean (SD)) 28.98 (13.95) 26.65 (14.17) 0.165
hrt1 (mean (SD)) 112.87 (40.94) 118.93 (41.47) 0.147
pafi1 (mean (SD)) 240.63 (116.66) 192.43 (105.54) 0.433
paco21 (mean (SD)) 39.95 (14.24) 36.79 (10.97) 0.249
ph1 (mean (SD)) 7.39 (0.11) 7.38 (0.11) 0.120
wblc1 (mean (SD)) 15.26 (11.41) 16.27 (12.55) 0.084
hema1 (mean (SD)) 32.70 (8.79) 30.51 (7.42) 0.269
sod1 (mean (SD)) 137.04 (7.68) 136.33 (7.60) 0.092
pot1 (mean (SD)) 4.08 (1.04) 4.05 (1.01) 0.027
crea1 (mean (SD)) 1.92 (2.03) 2.47 (2.05) 0.270
bili1 (mean (SD)) 2.00 (4.43) 2.71 (5.33) 0.145
alb1 (mean (SD)) 3.16 (0.67) 2.98 (0.93) 0.230
resp = Yes (%) 1481 (41.7) 632 (28.9) 0.270
card = Yes (%) 1007 (28.4) 924 (42.3) 0.295
neuro = Yes (%) 575 (16.2) 118 ( 5.4) 0.353
gastr = Yes (%) 522 (14.7) 420 (19.2) 0.121
renal = Yes (%) 147 ( 4.1) 148 ( 6.8) 0.116
meta = Yes (%) 172 ( 4.8) 93 ( 4.3) 0.028
hema = Yes (%) 239 ( 6.7) 115 ( 5.3) 0.062
seps = Yes (%) 515 (14.5) 516 (23.6) 0.234
trauma = Yes (%) 18 ( 0.5) 34 ( 1.6) 0.104
ortho = Yes (%) 3 ( 0.1) 4 ( 0.2) 0.027
cardiohx (mean (SD)) 0.16 (0.37) 0.20 (0.40) 0.116
chfhx (mean (SD)) 0.17 (0.37) 0.19 (0.40) 0.069
dementhx (mean (SD)) 0.12 (0.32) 0.07 (0.25) 0.163
psychhx (mean (SD)) 0.08 (0.27) 0.05 (0.21) 0.143
chrpulhx (mean (SD)) 0.22 (0.41) 0.14 (0.35) 0.192
renalhx (mean (SD)) 0.04 (0.20) 0.05 (0.21) 0.032
liverhx (mean (SD)) 0.07 (0.26) 0.06 (0.24) 0.049
gibledhx (mean (SD)) 0.04 (0.19) 0.02 (0.16) 0.070
malighx (mean (SD)) 0.25 (0.43) 0.20 (0.40) 0.101
immunhx (mean (SD)) 0.26 (0.44) 0.29 (0.45) 0.080
transhx (mean (SD)) 0.09 (0.29) 0.15 (0.36) 0.170
amihx (mean (SD)) 0.03 (0.17) 0.04 (0.20) 0.074
## Count covariates with important imbalance
addmargins(table(ExtractSmd(tabUnmatched) > 0.1))
FALSE TRUE Sum
18 32 50
倾向评分估计
通常,使用 logistic 回归模型来估计个体的倾向评分。此模型取自“如何使用倾向评分分析”。预测的概率包括被分配到右心导管插管、不被分配到右心导管插管、被分配到真实分配以及被分配到右心导管插管或不被分配到右心导管插管的概率中较小的一个,这些概率将在后续的倾向评分匹配和加权中用于计算。
rhc$swang1 <- factor(rhc$swang1, levels = c("No RHC", "RHC"))
## Fit model
psModel <- glm(formula = swang1 ~ age + sex + race + edu + income + ninsclas +
cat1 + das2d3pc + dnr1 + ca + surv2md1 + aps1 + scoma1 +
wtkilo1 + temp1 + meanbp1 + resp1 + hrt1 + pafi1 +
paco21 + ph1 + wblc1 + hema1 + sod1 + pot1 + crea1 +
bili1 + alb1 + resp + card + neuro + gastr + renal +
meta + hema + seps + trauma + ortho + cardiohx + chfhx +
dementhx + psychhx + chrpulhx + renalhx + liverhx + gibledhx +
malighx + immunhx + transhx + amihx,
family = binomial(link = "logit"),
data = rhc)
## Predicted probability of being assigned to RHC
rhc$pRhc <- predict(psModel, type = "response")
## Predicted probability of being assigned to no RHC
rhc$pNoRhc <- 1 - rhc$pRhc
## Predicted probability of being assigned to the
## treatment actually assigned (either RHC or no RHC)
rhc$pAssign <- NA
rhc$pAssign[rhc$swang1 == "RHC"] <- rhc$pRhc[rhc$swang1 == "RHC"]
rhc$pAssign[rhc$swang1 == "No RHC"] <- rhc$pNoRhc[rhc$swang1 == "No RHC"]
## Smaller of pRhc vs pNoRhc for matching weight
rhc$pMin <- pmin(rhc$pRhc, rhc$pNoRhc)
倾向评分匹配
可以使用 Matching 包进行倾向评分匹配。倾向评分的 logit 值通常用作匹配尺度,匹配的 caliper 常常为0.2倍标准差(SD)(logit(PS))。有关建议,请参阅 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3144483/#s5title。匹配完成后,所有标准化均值差都在0.1以下。
listMatch <- Match(Tr = (rhc$swang1 == "RHC"), # Need to be in 0,1
## logit of PS,i.e., log(PS/(1-PS)) as matching scale
X = log(rhc$pRhc / rhc$pNoRhc),
## 1:1 matching
M = 1,
## caliper = 0.2 * SD(logit(PS))
caliper = 0.2,
replace = FALSE,
ties = TRUE,
version = "fast")
## Extract matched data
rhcMatched <- rhc[unlist(listMatch[c("index.treated","index.control")]), ]
## Construct a table
tabMatched <- CreateTableOne(vars = vars, strata = "swang1", data = rhcMatched, test = FALSE)
## Show table with SMD
print(tabMatched, smd = TRUE)
Stratified by swang1
No RHC RHC SMD
n 1562 1562
age (mean (SD)) 60.53 (17.61) 60.55 (15.72) 0.001
sex = Male (%) 884 (56.6) 890 (57.0) 0.008
race (%) 0.009
black 245 (15.7) 247 (15.8)
other 97 ( 6.2) 100 ( 6.4)
white 1220 (78.1) 1215 (77.8)
edu (mean (SD)) 11.87 (3.13) 11.78 (3.16) 0.029
income (%) 0.028
$11-$25k 324 (20.7) 335 (21.4)
$25-$50k 252 (16.1) 262 (16.8)
> $50k 127 ( 8.1) 124 ( 7.9)
Under $11k 859 (55.0) 841 (53.8)
ninsclas (%) 0.026
Medicaid 163 (10.4) 152 ( 9.7)
Medicare 364 (23.3) 370 (23.7)
Medicare & Medicaid 94 ( 6.0) 95 ( 6.1)
No insurance 85 ( 5.4) 88 ( 5.6)
Private 502 (32.1) 498 (31.9)
Private & Medicare 354 (22.7) 359 (23.0)
cat1 (%) 0.058
ARF 714 (45.7) 680 (43.5)
CHF 162 (10.4) 175 (11.2)
COPD 54 ( 3.5) 57 ( 3.6)
Cirrhosis 42 ( 2.7) 47 ( 3.0)
Colon Cancer 1 ( 0.1) 1 ( 0.1)
Coma 84 ( 5.4) 76 ( 4.9)
Lung Cancer 4 ( 0.3) 5 ( 0.3)
MOSF w/Malignancy 121 ( 7.7) 128 ( 8.2)
MOSF w/Sepsis 380 (24.3) 393 (25.2)
das2d3pc (mean (SD)) 20.58 (5.48) 20.58 (5.08) <0.001
dnr1 = Yes (%) 125 ( 8.0) 130 ( 8.3) 0.012
ca (%) 0.022
Metastatic 102 ( 6.5) 98 ( 6.3)
No 1201 (76.9) 1193 (76.4)
Yes 259 (16.6) 271 (17.3)
surv2md1 (mean (SD)) 0.58 (0.20) 0.59 (0.20) 0.015
aps1 (mean (SD)) 57.13 (19.65) 57.26 (19.66) 0.007
scoma1 (mean (SD)) 19.37 (29.18) 18.88 (28.26) 0.017
wtkilo1 (mean (SD)) 70.24 (26.23) 70.70 (27.20) 0.017
temp1 (mean (SD)) 37.65 (1.89) 37.62 (1.74) 0.017
meanbp1 (mean (SD)) 73.70 (35.75) 73.11 (35.74) 0.016
resp1 (mean (SD)) 28.18 (13.87) 28.04 (14.15) 0.010
hrt1 (mean (SD)) 116.49 (43.19) 117.78 (40.25) 0.031
pafi1 (mean (SD)) 209.05 (106.18) 211.22 (108.06) 0.020
paco21 (mean (SD)) 37.55 (10.82) 37.46 (11.56) 0.008
ph1 (mean (SD)) 7.39 (0.11) 7.39 (0.11) 0.002
wblc1 (mean (SD)) 15.73 (12.03) 15.92 (13.00) 0.015
hema1 (mean (SD)) 30.78 (7.97) 30.88 (7.53) 0.014
sod1 (mean (SD)) 136.61 (7.87) 136.63 (7.43) 0.002
pot1 (mean (SD)) 4.04 (1.03) 4.05 (0.99) 0.009
crea1 (mean (SD)) 2.31 (2.39) 2.29 (1.97) 0.008
bili1 (mean (SD)) 2.54 (5.53) 2.55 (5.09) 0.002
alb1 (mean (SD)) 3.05 (0.69) 3.04 (0.96) 0.007
resp = Yes (%) 538 (34.4) 520 (33.3) 0.024
card = Yes (%) 587 (37.6) 598 (38.3) 0.015
neuro = Yes (%) 114 ( 7.3) 109 ( 7.0) 0.012
gastr = Yes (%) 273 (17.5) 291 (18.6) 0.030
renal = Yes (%) 93 ( 6.0) 95 ( 6.1) 0.005
meta = Yes (%) 72 ( 4.6) 74 ( 4.7) 0.006
hema = Yes (%) 94 ( 6.0) 97 ( 6.2) 0.008
seps = Yes (%) 333 (21.3) 331 (21.2) 0.003
trauma = Yes (%) 15 ( 1.0) 12 ( 0.8) 0.021
ortho = Yes (%) 2 ( 0.1) 1 ( 0.1) 0.021
cardiohx (mean (SD)) 0.20 (0.40) 0.20 (0.40) 0.006
chfhx (mean (SD)) 0.20 (0.40) 0.20 (0.40) 0.011
dementhx (mean (SD)) 0.07 (0.25) 0.07 (0.26) 0.017
psychhx (mean (SD)) 0.05 (0.23) 0.05 (0.23) <0.001
chrpulhx (mean (SD)) 0.15 (0.36) 0.15 (0.36) 0.007
renalhx (mean (SD)) 0.06 (0.23) 0.05 (0.22) 0.031
liverhx (mean (SD)) 0.07 (0.25) 0.07 (0.26) 0.005
gibledhx (mean (SD)) 0.03 (0.17) 0.03 (0.17) 0.004
malighx (mean (SD)) 0.23 (0.42) 0.23 (0.42) 0.009
immunhx (mean (SD)) 0.30 (0.46) 0.28 (0.45) 0.041
transhx (mean (SD)) 0.13 (0.33) 0.12 (0.33) 0.014
amihx (mean (SD)) 0.03 (0.17) 0.03 (0.17) 0.004
## Count covariates with important imbalance
addmargins(table(ExtractSmd(tabMatched) > 0.1))
FALSE Sum
50 50
倾向评分匹配加权
匹配权重方法是一种与1:1成对算法匹配类似的加权方法(https://pubmed.ncbi.nlm.nih.gov/23902694/)。匹配权重被定义为接受治疗或不接受治疗的预测概率与患者实际分配到的治疗组的预测概率中较小的那个。加权后,所有标准化均值差都在0.1以下。加权数据中的标准化均值差在 https://pubmed.ncbi.nlm.nih.gov/26238958/ 中有解释说明。
## Matching weight
rhc$mw <- rhc$pMin / rhc$pAssign
## Weighted data
rhcSvy <- svydesign(ids = ~ 1, data = rhc, weights = ~ mw)
## Construct a table (This is a bit slow.)
tabWeighted <- svyCreateTableOne(vars = vars, strata = "swang1", data = rhcSvy, test = FALSE)
## Show table with SMD
print(tabWeighted, smd = TRUE)
Stratified by swang1
No RHC RHC SMD
n 1522.89 1520.27
age (mean (SD)) 60.82 (17.16) 60.77 (15.79) 0.003
sex = Male (%) 875.8 (57.5) 872.3 (57.4) 0.003
race (%) 0.009
black 238.1 (15.6) 235.8 (15.5)
other 94.9 ( 6.2) 97.8 ( 6.4)
white 1189.9 (78.1) 1186.6 (78.1)
edu (mean (SD)) 11.80 (3.17) 11.80 (3.09) 0.002
income (%) 0.004
$11-$25k 316.5 (20.8) 317.0 (20.9)
$25-$50k 251.7 (16.5) 250.8 (16.5)
> $50k 127.1 ( 8.3) 128.4 ( 8.4)
Under $11k 827.6 (54.3) 824.1 (54.2)
ninsclas (%) 0.014
Medicaid 153.7 (10.1) 151.9 (10.0)
Medicare 361.1 (23.7) 369.0 (24.3)
Medicare & Medicaid 91.5 ( 6.0) 91.2 ( 6.0)
No insurance 85.8 ( 5.6) 86.6 ( 5.7)
Private 487.0 (32.0) 482.2 (31.7)
Private & Medicare 343.7 (22.6) 339.3 (22.3)
cat1 (%) 0.017
ARF 685.8 (45.0) 679.9 (44.7)
CHF 160.1 (10.5) 163.2 (10.7)
COPD 56.2 ( 3.7) 57.2 ( 3.8)
Cirrhosis 45.0 ( 3.0) 47.0 ( 3.1)
Colon Cancer 0.9 ( 0.1) 1.0 ( 0.1)
Coma 79.4 ( 5.2) 77.4 ( 5.1)
Lung Cancer 4.2 ( 0.3) 5.0 ( 0.3)
MOSF w/Malignancy 122.4 ( 8.0) 121.5 ( 8.0)
MOSF w/Sepsis 368.9 (24.2) 368.1 (24.2)
das2d3pc (mean (SD)) 20.58 (5.45) 20.56 (5.05) 0.005
dnr1 = Yes (%) 131.5 ( 8.6) 129.2 ( 8.5) 0.005
ca (%) 0.006
Metastatic 98.6 ( 6.5) 98.0 ( 6.4)
No 1160.5 (76.2) 1162.3 (76.5)
Yes 263.7 (17.3) 259.9 (17.1)
surv2md1 (mean (SD)) 0.58 (0.20) 0.58 (0.20) 0.010
aps1 (mean (SD)) 57.30 (19.53) 57.13 (19.73) 0.008
scoma1 (mean (SD)) 19.12 (29.10) 19.10 (28.51) 0.001
wtkilo1 (mean (SD)) 70.19 (26.54) 70.19 (27.30) <0.001
temp1 (mean (SD)) 37.63 (1.88) 37.64 (1.74) <0.001
meanbp1 (mean (SD)) 73.18 (35.48) 73.22 (35.50) 0.001
resp1 (mean (SD)) 28.16 (13.84) 28.10 (14.09) 0.004
hrt1 (mean (SD)) 116.96 (42.74) 116.71 (40.28) 0.006
pafi1 (mean (SD)) 209.93 (107.48) 210.31 (108.23) 0.004
paco21 (mean (SD)) 37.56 (10.80) 37.51 (11.59) 0.004
ph1 (mean (SD)) 7.39 (0.11) 7.39 (0.11) 0.003
wblc1 (mean (SD)) 15.82 (12.03) 15.69 (12.69) 0.010
hema1 (mean (SD)) 30.90 (8.10) 30.95 (7.57) 0.007
sod1 (mean (SD)) 136.54 (7.86) 136.58 (7.38) 0.005
pot1 (mean (SD)) 4.04 (1.04) 4.05 (0.99) 0.004
crea1 (mean (SD)) 2.27 (2.31) 2.27 (1.95) <0.001
bili1 (mean (SD)) 2.50 (5.37) 2.54 (5.15) 0.008
alb1 (mean (SD)) 3.04 (0.70) 3.04 (0.97) <0.001
resp = Yes (%) 516.6 (33.9) 512.6 (33.7) 0.004
card = Yes (%) 582.2 (38.2) 585.6 (38.5) 0.006
neuro = Yes (%) 109.6 ( 7.2) 109.0 ( 7.2) 0.001
gastr = Yes (%) 270.3 (17.8) 272.7 (17.9) 0.005
renal = Yes (%) 89.5 ( 5.9) 90.7 ( 6.0) 0.004
meta = Yes (%) 70.0 ( 4.6) 70.2 ( 4.6) 0.001
hema = Yes (%) 93.5 ( 6.1) 95.0 ( 6.2) 0.004
seps = Yes (%) 325.5 (21.4) 322.0 (21.2) 0.005
trauma = Yes (%) 14.8 ( 1.0) 14.3 ( 0.9) 0.003
ortho = Yes (%) 1.0 ( 0.1) 0.9 ( 0.1) 0.003
cardiohx (mean (SD)) 0.20 (0.40) 0.20 (0.40) <0.001
chfhx (mean (SD)) 0.20 (0.40) 0.20 (0.40) 0.004
dementhx (mean (SD)) 0.08 (0.26) 0.08 (0.26) 0.003
psychhx (mean (SD)) 0.05 (0.23) 0.05 (0.22) 0.004
chrpulhx (mean (SD)) 0.16 (0.36) 0.16 (0.36) 0.001
renalhx (mean (SD)) 0.05 (0.22) 0.05 (0.22) 0.001
liverhx (mean (SD)) 0.07 (0.25) 0.07 (0.25) 0.003
gibledhx (mean (SD)) 0.03 (0.17) 0.03 (0.17) 0.007
malighx (mean (SD)) 0.23 (0.42) 0.23 (0.42) 0.007
immunhx (mean (SD)) 0.28 (0.45) 0.28 (0.45) <0.001
transhx (mean (SD)) 0.12 (0.33) 0.12 (0.33) 0.004
amihx (mean (SD)) 0.03 (0.18) 0.03 (0.18) 0.006
## Count covariates with important imbalance
addmargins(table(ExtractSmd(tabWeighted) > 0.1))
FALSE Sum
50 50
倾向评分重叠加权
重叠权重方法是另一种替代的加权方法(https://amstat.tandfonline.com/doi/abs/10.1080/01621459.2016.1260466)。加权后,所有标准化均值差都在0.1以下。
## Overlap weight
rhc$ow <- (rhc$pAssign * (1 - rhc$pAssign)) / rhc$pAssign
## Weighted data
rhcSvyOw <- svydesign(ids = ~ 1, data = rhc, weights = ~ ow)
## Construct a table (This is a bit slow.)
tabWeightedOw <- svyCreateTableOne(vars = vars, strata = "swang1", data = rhcSvyOw, test = FALSE)
## Show table with SMD
print(tabWeightedOw, smd = TRUE)
Stratified by swang1
No RHC RHC SMD
n 1005.82 1005.82
age (mean (SD)) 60.88 (17.19) 60.88 (15.73) <0.001
sex = Male (%) 574.3 (57.1) 574.3 (57.1) <0.001
race (%) <0.001
black 157.5 (15.7) 157.5 (15.7)
other 62.0 ( 6.2) 62.0 ( 6.2)
white 786.3 (78.2) 786.3 (78.2)
edu (mean (SD)) 11.78 (3.16) 11.78 (3.08) <0.001
income (%) <0.001
$11-$25k 208.4 (20.7) 208.4 (20.7)
$25-$50k 163.3 (16.2) 163.3 (16.2)
> $50k 83.8 ( 8.3) 83.8 ( 8.3)
Under $11k 550.3 (54.7) 550.3 (54.7)
ninsclas (%) <0.001
Medicaid 104.1 (10.4) 104.1 (10.4)
Medicare 242.5 (24.1) 242.5 (24.1)
Medicare & Medicaid 60.7 ( 6.0) 60.7 ( 6.0)
No insurance 57.1 ( 5.7) 57.1 ( 5.7)
Private 315.9 (31.4) 315.9 (31.4)
Private & Medicare 225.5 (22.4) 225.5 (22.4)
cat1 (%) <0.001
ARF 450.0 (44.7) 450.0 (44.7)
CHF 100.3 (10.0) 100.3 (10.0)
COPD 43.8 ( 4.4) 43.8 ( 4.4)
Cirrhosis 32.5 ( 3.2) 32.5 ( 3.2)
Colon Cancer 0.7 ( 0.1) 0.7 ( 0.1)
Coma 56.4 ( 5.6) 56.4 ( 5.6)
Lung Cancer 3.3 ( 0.3) 3.3 ( 0.3)
MOSF w/Malignancy 79.1 ( 7.9) 79.1 ( 7.9)
MOSF w/Sepsis 239.7 (23.8) 239.7 (23.8)
das2d3pc (mean (SD)) 20.57 (5.46) 20.57 (5.02) <0.001
dnr1 = Yes (%) 90.8 ( 9.0) 90.8 ( 9.0) <0.001
ca (%) <0.001
Metastatic 65.7 ( 6.5) 65.7 ( 6.5)
No 767.4 (76.3) 767.4 (76.3)
Yes 172.7 (17.2) 172.7 (17.2)
surv2md1 (mean (SD)) 0.58 (0.20) 0.58 (0.20) <0.001
aps1 (mean (SD)) 56.94 (19.78) 56.94 (19.79) <0.001
scoma1 (mean (SD)) 19.57 (29.46) 19.57 (28.78) <0.001
wtkilo1 (mean (SD)) 69.80 (26.87) 69.80 (27.65) <0.001
temp1 (mean (SD)) 37.63 (1.87) 37.63 (1.74) <0.001
meanbp1 (mean (SD)) 74.12 (36.09) 74.12 (36.18) <0.001
resp1 (mean (SD)) 28.16 (13.90) 28.16 (14.18) <0.001
hrt1 (mean (SD)) 116.54 (42.66) 116.54 (40.48) <0.001
pafi1 (mean (SD)) 211.64 (108.24) 211.64 (109.43) <0.001
paco21 (mean (SD)) 37.76 (11.12) 37.76 (12.09) <0.001
ph1 (mean (SD)) 7.39 (0.11) 7.39 (0.11) <0.001
wblc1 (mean (SD)) 15.84 (12.07) 15.84 (12.94) <0.001
hema1 (mean (SD)) 30.98 (8.17) 30.98 (7.64) <0.001
sod1 (mean (SD)) 136.61 (7.82) 136.61 (7.31) <0.001
pot1 (mean (SD)) 4.05 (1.04) 4.05 (1.00) <0.001
crea1 (mean (SD)) 2.25 (2.30) 2.25 (1.95) <0.001
bili1 (mean (SD)) 2.50 (5.37) 2.50 (5.05) <0.001
alb1 (mean (SD)) 3.05 (0.70) 3.05 (1.05) <0.001
resp = Yes (%) 347.3 (34.5) 347.3 (34.5) <0.001
card = Yes (%) 378.1 (37.6) 378.1 (37.6) <0.001
neuro = Yes (%) 81.0 ( 8.1) 81.0 ( 8.1) <0.001
gastr = Yes (%) 177.6 (17.7) 177.6 (17.7) <0.001
renal = Yes (%) 58.3 ( 5.8) 58.3 ( 5.8) <0.001
meta = Yes (%) 46.3 ( 4.6) 46.3 ( 4.6) <0.001
hema = Yes (%) 62.9 ( 6.2) 62.9 ( 6.2) <0.001
seps = Yes (%) 208.1 (20.7) 208.1 (20.7) <0.001
trauma = Yes (%) 9.4 ( 0.9) 9.4 ( 0.9) <0.001
ortho = Yes (%) 0.7 ( 0.1) 0.7 ( 0.1) <0.001
cardiohx (mean (SD)) 0.20 (0.40) 0.20 (0.40) <0.001
chfhx (mean (SD)) 0.20 (0.40) 0.20 (0.40) <0.001
dementhx (mean (SD)) 0.08 (0.27) 0.08 (0.27) <0.001
psychhx (mean (SD)) 0.06 (0.23) 0.06 (0.23) <0.001
chrpulhx (mean (SD)) 0.16 (0.37) 0.16 (0.37) <0.001
renalhx (mean (SD)) 0.05 (0.22) 0.05 (0.22) <0.001
liverhx (mean (SD)) 0.07 (0.25) 0.07 (0.25) <0.001
gibledhx (mean (SD)) 0.03 (0.17) 0.03 (0.17) <0.001
malighx (mean (SD)) 0.23 (0.42) 0.23 (0.42) <0.001
immunhx (mean (SD)) 0.28 (0.45) 0.28 (0.45) <0.001
transhx (mean (SD)) 0.12 (0.33) 0.12 (0.33) <0.001
amihx (mean (SD)) 0.03 (0.18) 0.03 (0.18) <0.001
## Count covariates with important imbalance
addmargins(table(ExtractSmd(tabWeightedOw) > 0.1))
FALSE Sum
50 50
在匹配和/或加权之前和之后评估平衡
通常会绘制一个显示协变量平衡的图表,以展示匹配和/或加权的平衡效果。在相同的倾向评分模型下,匹配权重方法通常能够实现比匹配更好的协变量平衡。
## Construct a data frame containing variable name and SMD from all methods
dataPlot <- data.frame(variable = rownames(ExtractSmd(tabUnmatched)),
Unmatched = as.numeric(ExtractSmd(tabUnmatched)),
Matched = as.numeric(ExtractSmd(tabMatched)),
Weighted = as.numeric(ExtractSmd(tabWeighted)),
WeightedOw = as.numeric(ExtractSmd(tabWeightedOw)))
## Create long-format data for ggplot2
dataPlotMelt <- melt(data = dataPlot,
id.vars = c("variable"),
variable.name = "Method",
value.name = "SMD")
## Order variable names by magnitude of SMD
varNames <- as.character(dataPlot$variable)[order(dataPlot$Unmatched)]
## Order factor levels in the same order
dataPlotMelt$variable <- factor(dataPlotMelt$variable,
levels = varNames)
## Plot using ggplot2
ggplot(data = dataPlotMelt,
mapping = aes(x = variable, y = SMD, group = Method, color = Method)) +
geom_line() +
geom_point() +
geom_hline(yintercept = 0.1, color = "black", size = 0.1) +
coord_flip() +
theme_bw() +
theme(legend.key = element_blank())
要构建一个并列表格,可以将数据提取为矩阵,并使用 print()
方法将其组合,该方法实际上会返回一个矩阵,但在打印时将其呈现为表格形式。
## Column bind tables
resCombo <- cbind(print(tabUnmatched, printToggle = FALSE),
print(tabMatched, printToggle = FALSE),
print(tabWeighted, printToggle = FALSE),
print(tabWeightedOw, printToggle = FALSE))
## Add group name row, and rewrite column names
resCombo <- rbind(Group = rep(c("No RHC","RHC"), 4), resCombo)
colnames(resCombo) <- c("Unmatched","","Matched","","MW","","OW","")
print(resCombo, quote = FALSE)
Unmatched Matched MW
Group No RHC RHC No RHC RHC No RHC RHC
n 3551 2184 1562 1562 1522.89 1520.27
age (mean (SD)) 61.76 (17.29) 60.75 (15.63) 60.53 (17.61) 60.55 (15.72) 60.82 (17.16) 60.77 (15.79)
sex = Male (%) 1914 (53.9) 1278 (58.5) 884 (56.6) 890 (57.0) 875.8 (57.5) 872.3 (57.4)
race (%)
black 585 (16.5) 335 (15.3) 245 (15.7) 247 (15.8) 238.1 (15.6) 235.8 (15.5)
other 213 ( 6.0) 142 ( 6.5) 97 ( 6.2) 100 ( 6.4) 94.9 ( 6.2) 97.8 ( 6.4)
white 2753 (77.5) 1707 (78.2) 1220 (78.1) 1215 (77.8) 1189.9 (78.1) 1186.6 (78.1)
edu (mean (SD)) 11.57 (3.13) 11.86 (3.16) 11.87 (3.13) 11.78 (3.16) 11.80 (3.17) 11.80 (3.09)
income (%)
$11-$25k 713 (20.1) 452 (20.7) 324 (20.7) 335 (21.4) 316.5 (20.8) 317.0 (20.9)
$25-$50k 500 (14.1) 393 (18.0) 252 (16.1) 262 (16.8) 251.7 (16.5) 250.8 (16.5)
> $50k 257 ( 7.2) 194 ( 8.9) 127 ( 8.1) 124 ( 7.9) 127.1 ( 8.3) 128.4 ( 8.4)
Under $11k 2081 (58.6) 1145 (52.4) 859 (55.0) 841 (53.8) 827.6 (54.3) 824.1 (54.2)
ninsclas (%)
Medicaid 454 (12.8) 193 ( 8.8) 163 (10.4) 152 ( 9.7) 153.7 (10.1) 151.9 (10.0)
Medicare 947 (26.7) 511 (23.4) 364 (23.3) 370 (23.7) 361.1 (23.7) 369.0 (24.3)
Medicare & Medicaid 251 ( 7.1) 123 ( 5.6) 94 ( 6.0) 95 ( 6.1) 91.5 ( 6.0) 91.2 ( 6.0)
No insurance 186 ( 5.2) 136 ( 6.2) 85 ( 5.4) 88 ( 5.6) 85.8 ( 5.6) 86.6 ( 5.7)
Private 967 (27.2) 731 (33.5) 502 (32.1) 498 (31.9) 487.0 (32.0) 482.2 (31.7)
Private & Medicare 746 (21.0) 490 (22.4) 354 (22.7) 359 (23.0) 343.7 (22.6) 339.3 (22.3)
cat1 (%)
ARF 1581 (44.5) 909 (41.6) 714 (45.7) 680 (43.5) 685.8 (45.0) 679.9 (44.7)
CHF 247 ( 7.0) 209 ( 9.6) 162 (10.4) 175 (11.2) 160.1 (10.5) 163.2 (10.7)
COPD 399 (11.2) 58 ( 2.7) 54 ( 3.5) 57 ( 3.6) 56.2 ( 3.7) 57.2 ( 3.8)
Cirrhosis 175 ( 4.9) 49 ( 2.2) 42 ( 2.7) 47 ( 3.0) 45.0 ( 3.0) 47.0 ( 3.1)
Colon Cancer 6 ( 0.2) 1 ( 0.0) 1 ( 0.1) 1 ( 0.1) 0.9 ( 0.1) 1.0 ( 0.1)
Coma 341 ( 9.6) 95 ( 4.3) 84 ( 5.4) 76 ( 4.9) 79.4 ( 5.2) 77.4 ( 5.1)
Lung Cancer 34 ( 1.0) 5 ( 0.2) 4 ( 0.3) 5 ( 0.3) 4.2 ( 0.3) 5.0 ( 0.3)
MOSF w/Malignancy 241 ( 6.8) 158 ( 7.2) 121 ( 7.7) 128 ( 8.2) 122.4 ( 8.0) 121.5 ( 8.0)
MOSF w/Sepsis 527 (14.8) 700 (32.1) 380 (24.3) 393 (25.2) 368.9 (24.2) 368.1 (24.2)
das2d3pc (mean (SD)) 20.37 (5.48) 20.70 (5.03) 20.58 (5.48) 20.58 (5.08) 20.58 (5.45) 20.56 (5.05)
dnr1 = Yes (%) 499 (14.1) 155 ( 7.1) 125 ( 8.0) 130 ( 8.3) 131.5 ( 8.6) 129.2 ( 8.5)
ca (%)
Metastatic 261 ( 7.4) 123 ( 5.6) 102 ( 6.5) 98 ( 6.3) 98.6 ( 6.5) 98.0 ( 6.4)
No 2652 (74.7) 1727 (79.1) 1201 (76.9) 1193 (76.4) 1160.5 (76.2) 1162.3 (76.5)
Yes 638 (18.0) 334 (15.3) 259 (16.6) 271 (17.3) 263.7 (17.3) 259.9 (17.1)
surv2md1 (mean (SD)) 0.61 (0.19) 0.57 (0.20) 0.58 (0.20) 0.59 (0.20) 0.58 (0.20) 0.58 (0.20)
aps1 (mean (SD)) 50.93 (18.81) 60.74 (20.27) 57.13 (19.65) 57.26 (19.66) 57.30 (19.53) 57.13 (19.73)
scoma1 (mean (SD)) 22.25 (31.37) 18.97 (28.26) 19.37 (29.18) 18.88 (28.26) 19.12 (29.10) 19.10 (28.51)
wtkilo1 (mean (SD)) 65.04 (29.50) 72.36 (27.73) 70.24 (26.23) 70.70 (27.20) 70.19 (26.54) 70.19 (27.30)
temp1 (mean (SD)) 37.63 (1.74) 37.59 (1.83) 37.65 (1.89) 37.62 (1.74) 37.63 (1.88) 37.64 (1.74)
meanbp1 (mean (SD)) 84.87 (38.87) 68.20 (34.24) 73.70 (35.75) 73.11 (35.74) 73.18 (35.48) 73.22 (35.50)
resp1 (mean (SD)) 28.98 (13.95) 26.65 (14.17) 28.18 (13.87) 28.04 (14.15) 28.16 (13.84) 28.10 (14.09)
hrt1 (mean (SD)) 112.87 (40.94) 118.93 (41.47) 116.49 (43.19) 117.78 (40.25) 116.96 (42.74) 116.71 (40.28)
pafi1 (mean (SD)) 240.63 (116.66) 192.43 (105.54) 209.05 (106.18) 211.22 (108.06) 209.93 (107.48) 210.31 (108.23)
paco21 (mean (SD)) 39.95 (14.24) 36.79 (10.97) 37.55 (10.82) 37.46 (11.56) 37.56 (10.80) 37.51 (11.59)
ph1 (mean (SD)) 7.39 (0.11) 7.38 (0.11) 7.39 (0.11) 7.39 (0.11) 7.39 (0.11) 7.39 (0.11)
wblc1 (mean (SD)) 15.26 (11.41) 16.27 (12.55) 15.73 (12.03) 15.92 (13.00) 15.82 (12.03) 15.69 (12.69)
hema1 (mean (SD)) 32.70 (8.79) 30.51 (7.42) 30.78 (7.97) 30.88 (7.53) 30.90 (8.10) 30.95 (7.57)
sod1 (mean (SD)) 137.04 (7.68) 136.33 (7.60) 136.61 (7.87) 136.63 (7.43) 136.54 (7.86) 136.58 (7.38)
pot1 (mean (SD)) 4.08 (1.04) 4.05 (1.01) 4.04 (1.03) 4.05 (0.99) 4.04 (1.04) 4.05 (0.99)
crea1 (mean (SD)) 1.92 (2.03) 2.47 (2.05) 2.31 (2.39) 2.29 (1.97) 2.27 (2.31) 2.27 (1.95)
bili1 (mean (SD)) 2.00 (4.43) 2.71 (5.33) 2.54 (5.53) 2.55 (5.09) 2.50 (5.37) 2.54 (5.15)
alb1 (mean (SD)) 3.16 (0.67) 2.98 (0.93) 3.05 (0.69) 3.04 (0.96) 3.04 (0.70) 3.04 (0.97)
resp = Yes (%) 1481 (41.7) 632 (28.9) 538 (34.4) 520 (33.3) 516.6 (33.9) 512.6 (33.7)
card = Yes (%) 1007 (28.4) 924 (42.3) 587 (37.6) 598 (38.3) 582.2 (38.2) 585.6 (38.5)
neuro = Yes (%) 575 (16.2) 118 ( 5.4) 114 ( 7.3) 109 ( 7.0) 109.6 ( 7.2) 109.0 ( 7.2)
gastr = Yes (%) 522 (14.7) 420 (19.2) 273 (17.5) 291 (18.6) 270.3 (17.8) 272.7 (17.9)
renal = Yes (%) 147 ( 4.1) 148 ( 6.8) 93 ( 6.0) 95 ( 6.1) 89.5 ( 5.9) 90.7 ( 6.0)
meta = Yes (%) 172 ( 4.8) 93 ( 4.3) 72 ( 4.6) 74 ( 4.7) 70.0 ( 4.6) 70.2 ( 4.6)
hema = Yes (%) 239 ( 6.7) 115 ( 5.3) 94 ( 6.0) 97 ( 6.2) 93.5 ( 6.1) 95.0 ( 6.2)
seps = Yes (%) 515 (14.5) 516 (23.6) 333 (21.3) 331 (21.2) 325.5 (21.4) 322.0 (21.2)
trauma = Yes (%) 18 ( 0.5) 34 ( 1.6) 15 ( 1.0) 12 ( 0.8) 14.8 ( 1.0) 14.3 ( 0.9)
ortho = Yes (%) 3 ( 0.1) 4 ( 0.2) 2 ( 0.1) 1 ( 0.1) 1.0 ( 0.1) 0.9 ( 0.1)
cardiohx (mean (SD)) 0.16 (0.37) 0.20 (0.40) 0.20 (0.40) 0.20 (0.40) 0.20 (0.40) 0.20 (0.40)
chfhx (mean (SD)) 0.17 (0.37) 0.19 (0.40) 0.20 (0.40) 0.20 (0.40) 0.20 (0.40) 0.20 (0.40)
dementhx (mean (SD)) 0.12 (0.32) 0.07 (0.25) 0.07 (0.25) 0.07 (0.26) 0.08 (0.26) 0.08 (0.26)
psychhx (mean (SD)) 0.08 (0.27) 0.05 (0.21) 0.05 (0.23) 0.05 (0.23) 0.05 (0.23) 0.05 (0.22)
chrpulhx (mean (SD)) 0.22 (0.41) 0.14 (0.35) 0.15 (0.36) 0.15 (0.36) 0.16 (0.36) 0.16 (0.36)
renalhx (mean (SD)) 0.04 (0.20) 0.05 (0.21) 0.06 (0.23) 0.05 (0.22) 0.05 (0.22) 0.05 (0.22)
liverhx (mean (SD)) 0.07 (0.26) 0.06 (0.24) 0.07 (0.25) 0.07 (0.26) 0.07 (0.25) 0.07 (0.25)
gibledhx (mean (SD)) 0.04 (0.19) 0.02 (0.16) 0.03 (0.17) 0.03 (0.17) 0.03 (0.17) 0.03 (0.17)
malighx (mean (SD)) 0.25 (0.43) 0.20 (0.40) 0.23 (0.42) 0.23 (0.42) 0.23 (0.42) 0.23 (0.42)
immunhx (mean (SD)) 0.26 (0.44) 0.29 (0.45) 0.30 (0.46) 0.28 (0.45) 0.28 (0.45) 0.28 (0.45)
transhx (mean (SD)) 0.09 (0.29) 0.15 (0.36) 0.13 (0.33) 0.12 (0.33) 0.12 (0.33) 0.12 (0.33)
amihx (mean (SD)) 0.03 (0.17) 0.04 (0.20) 0.03 (0.17) 0.03 (0.17) 0.03 (0.18) 0.03 (0.18)
OW
Group No RHC RHC
n 1005.82 1005.82
age (mean (SD)) 60.88 (17.19) 60.88 (15.73)
sex = Male (%) 574.3 (57.1) 574.3 (57.1)
race (%)
black 157.5 (15.7) 157.5 (15.7)
other 62.0 ( 6.2) 62.0 ( 6.2)
white 786.3 (78.2) 786.3 (78.2)
edu (mean (SD)) 11.78 (3.16) 11.78 (3.08)
income (%)
$11-$25k 208.4 (20.7) 208.4 (20.7)
$25-$50k 163.3 (16.2) 163.3 (16.2)
> $50k 83.8 ( 8.3) 83.8 ( 8.3)
Under $11k 550.3 (54.7) 550.3 (54.7)
ninsclas (%)
Medicaid 104.1 (10.4) 104.1 (10.4)
Medicare 242.5 (24.1) 242.5 (24.1)
Medicare & Medicaid 60.7 ( 6.0) 60.7 ( 6.0)
No insurance 57.1 ( 5.7) 57.1 ( 5.7)
Private 315.9 (31.4) 315.9 (31.4)
Private & Medicare 225.5 (22.4) 225.5 (22.4)
cat1 (%)
ARF 450.0 (44.7) 450.0 (44.7)
CHF 100.3 (10.0) 100.3 (10.0)
COPD 43.8 ( 4.4) 43.8 ( 4.4)
Cirrhosis 32.5 ( 3.2) 32.5 ( 3.2)
Colon Cancer 0.7 ( 0.1) 0.7 ( 0.1)
Coma 56.4 ( 5.6) 56.4 ( 5.6)
Lung Cancer 3.3 ( 0.3) 3.3 ( 0.3)
MOSF w/Malignancy 79.1 ( 7.9) 79.1 ( 7.9)
MOSF w/Sepsis 239.7 (23.8) 239.7 (23.8)
das2d3pc (mean (SD)) 20.57 (5.46) 20.57 (5.02)
dnr1 = Yes (%) 90.8 ( 9.0) 90.8 ( 9.0)
ca (%)
Metastatic 65.7 ( 6.5) 65.7 ( 6.5)
No 767.4 (76.3) 767.4 (76.3)
Yes 172.7 (17.2) 172.7 (17.2)
surv2md1 (mean (SD)) 0.58 (0.20) 0.58 (0.20)
aps1 (mean (SD)) 56.94 (19.78) 56.94 (19.79)
scoma1 (mean (SD)) 19.57 (29.46) 19.57 (28.78)
wtkilo1 (mean (SD)) 69.80 (26.87) 69.80 (27.65)
temp1 (mean (SD)) 37.63 (1.87) 37.63 (1.74)
meanbp1 (mean (SD)) 74.12 (36.09) 74.12 (36.18)
resp1 (mean (SD)) 28.16 (13.90) 28.16 (14.18)
hrt1 (mean (SD)) 116.54 (42.66) 116.54 (40.48)
pafi1 (mean (SD)) 211.64 (108.24) 211.64 (109.43)
paco21 (mean (SD)) 37.76 (11.12) 37.76 (12.09)
ph1 (mean (SD)) 7.39 (0.11) 7.39 (0.11)
wblc1 (mean (SD)) 15.84 (12.07) 15.84 (12.94)
hema1 (mean (SD)) 30.98 (8.17) 30.98 (7.64)
sod1 (mean (SD)) 136.61 (7.82) 136.61 (7.31)
pot1 (mean (SD)) 4.05 (1.04) 4.05 (1.00)
crea1 (mean (SD)) 2.25 (2.30) 2.25 (1.95)
bili1 (mean (SD)) 2.50 (5.37) 2.50 (5.05)
alb1 (mean (SD)) 3.05 (0.70) 3.05 (1.05)
resp = Yes (%) 347.3 (34.5) 347.3 (34.5)
card = Yes (%) 378.1 (37.6) 378.1 (37.6)
neuro = Yes (%) 81.0 ( 8.1) 81.0 ( 8.1)
gastr = Yes (%) 177.6 (17.7) 177.6 (17.7)
renal = Yes (%) 58.3 ( 5.8) 58.3 ( 5.8)
meta = Yes (%) 46.3 ( 4.6) 46.3 ( 4.6)
hema = Yes (%) 62.9 ( 6.2) 62.9 ( 6.2)
seps = Yes (%) 208.1 (20.7) 208.1 (20.7)
trauma = Yes (%) 9.4 ( 0.9) 9.4 ( 0.9)
ortho = Yes (%) 0.7 ( 0.1) 0.7 ( 0.1)
cardiohx (mean (SD)) 0.20 (0.40) 0.20 (0.40)
chfhx (mean (SD)) 0.20 (0.40) 0.20 (0.40)
dementhx (mean (SD)) 0.08 (0.27) 0.08 (0.27)
psychhx (mean (SD)) 0.06 (0.23) 0.06 (0.23)
chrpulhx (mean (SD)) 0.16 (0.37) 0.16 (0.37)
renalhx (mean (SD)) 0.05 (0.22) 0.05 (0.22)
liverhx (mean (SD)) 0.07 (0.25) 0.07 (0.25)
gibledhx (mean (SD)) 0.03 (0.17) 0.03 (0.17)
malighx (mean (SD)) 0.23 (0.42) 0.23 (0.42)
immunhx (mean (SD)) 0.28 (0.45) 0.28 (0.45)
transhx (mean (SD)) 0.12 (0.33) 0.12 (0.33)
amihx (mean (SD)) 0.03 (0.18) 0.03 (0.18)
最终分析可以使用匹配和加权数据进行。匹配和匹配权重的结果是相似的。可以使用 ShowRegTable() 函数来方便地查看结果。
## Unmatched model (unadjusted)
glmUnmatched <- glm(formula = (death == "Yes") ~ swang1,
family = binomial(link = "logit"),
data = rhc)
## Matched model
glmMatched <- glm(formula = (death == "Yes") ~ swang1,
family = binomial(link = "logit"),
data = rhcMatched)
## Weighted model
glmWeighted <- svyglm(formula = (death == "Yes") ~ swang1,
family = binomial(link = "logit"),
design = rhcSvy)
## Show results together
resTogether <- list(Unmatched = ShowRegTable(glmUnmatched, printToggle = FALSE),
Matched = ShowRegTable(glmMatched, printToggle = FALSE),
Weighted = ShowRegTable(glmWeighted, printToggle = FALSE))
print(resTogether, quote = FALSE)
$Unmatched
exp(coef) [confint] p
(Intercept) 1.70 [1.59, 1.82] <0.001
swang1RHC 1.25 [1.12, 1.40] <0.001
$Matched
exp(coef) [confint] p
(Intercept) 1.78 [1.61, 1.98] <0.001
swang1RHC 1.26 [1.09, 1.46] 0.002
$Weighted
exp(coef) [confint] p
(Intercept) 1.70 [1.55, 1.85] <0.001
swang1RHC 1.31 [1.14, 1.49] <0.001
- Authored by Kazuki Yoshida
- CRAN page: https://cran.r-project.org/package=tableone
- github page: https://github.com/kaz-yos/tableone
CreateTableOne
:创建一个汇总基线变量(包括连续和分类变量)的对象
CreateTableOne
函数用于创建一个汇总基线变量(包括连续和分类变量)的对象,并可选择按一个或多个分层变量进行分层,并执行统计检验。这个对象生成一个表格,非常适用于医学研究论文。
使用示例:
# 导入tableone包
library(tableone)
# 创建一个数据框,例如 mydata
# vars 参数包含你要总结的变量的名称,以字符向量的形式提供
# strata 参数包含你要分层的变量的名称,以字符向量的形式提供
# data 参数是包含这些变量的数据框
# factorVars 参数包含应该被处理为分类变量的数值编码变量的名称,以字符向量的形式提供
# includeNA 参数指定是否将NA视为常规因子水平而不是缺失值
# test 参数指定是否执行组间比较
# testApprox、argsApprox、testExact、argsExact、testNormal、argsNormal、testNonNormal、argsNonNormal 参数用于指定不同类型的统计检验方法
# smd 参数用于计算标准化均值差
# addOverall 参数在提供分层时,可选地添加一个总体列到表中
result <- CreateTableOne(
vars = c("Age", "Gender", "BMI"),
strata = "Treatment",
data = mydata,
factorVars = c("Gender"),
includeNA = FALSE,
test = TRUE,
testApprox = chisq.test,
argsApprox = list(correct = TRUE),
testExact = fisher.test,
argsExact = list(workspace = 2 * 10^5),
testNormal = oneway.test,
argsNormal = list(var.equal = TRUE),
testNonNormal = kruskal.test,
argsNonNormal = list(NULL),
smd = TRUE,
addOverall = FALSE
)
# 打印汇总结果
print(result)
这将创建一个包含基线变量汇总信息的表格,并显示在R的控制台中。你可以根据需要将结果用于进一步的分析或将其嵌入到你的研究论文中。
详情
- 标准化均值差(SMD)的定义在Flury等人的1986年的文章中可以找到,包括单变量和多变量情况(本质上是马哈拉诺比斯距离的平方根)。关于二分类变量的扩展讨论在Austin的2009年文章中,而关于多分类变量的扩展则在Yang等人的2012年文章中提出。多项式扩展将单个多项式变量视为多个非冗余的二元变量,并使用马哈拉诺比斯距离。第3页协方差矩阵的非对角线元素存在错误,需要取负值。在加权数据中,可以使用相同的定义,只是均值和标准差的估计值是加权估计(Li等人的2013年文章和Austin等人的2015年文章)。在tableone中,所有加权估计都是使用survey包中的加权估计函数计算的。
返回值
CreateTableOne
函数返回一个TableOne类的对象,其中包含三个子对象:
ContTable
:包含连续变量的对象CatTable
:包含分类变量的对象MetaData
:包含有关变量的元数据的列表
作者
- Kazuki Yoshida
- Justin Bohn
- Alexander Bartel
参考文献
- Flury, BK. and Riedwyl, H. (1986). Standard distance in univariate and multivariate analysis. The American >Statistician, 40, 249-251.
- Austin, PC. (2009). Using the Standardized Difference to Compare the Prevalence of a Binary Variable Between Two >Groups in Observational Research. Communications in Statistics - Simulation and Computation, 38, 1228-1234.
- Yang, D. and Dalton, JE. (2012). A unified approach to measuring the effect size between two groups using SAS. SAS Global Forum 2012, Paper 335-2012.
- Li, L. and Greene, T. (2013). A weighting analogue to pair matching in propensity score analysis. International Journal of Biostatistics, 9, 215-234.
- Austin, PC. and Stuart, EA. (2015). Moving towards best practice when using inverse probability of treatment weighting (IPTW) using the propensity score to estimate causal treatment effects in observational studies. Statistics in Medicine, Online on August 3, 2015.
上述是关于CreateTableOne
函数的详细说明,它用于创建基线变量的汇总对象,可用于医学研究和统计分析。使用时,通常需要提供变量、数据框和其他参数来指定分析的方式。
svyCreateCatTable
:创建一个汇总加权数据的分类变量的对象
svyCreateCatTable
函数用于创建一个汇总加权数据的分类变量的对象,可选择按一个或多个分层变量进行分层,并执行统计检验。通常情况下,svyCreateTableOne
应该用作同时适用于连续和分类数据的通用前端。
用法
svyCreateCatTable(
vars,
strata,
data,
includeNA = FALSE,
test = TRUE,
testApprox = svyTestChisq,
argsApprox = NULL,
smd = TRUE,
addOverall = FALSE
)
参数
vars
:要汇总的变量,以字符向量的形式提供。strata
:分层(分组)变量的名称,以字符向量的形式提供。如果省略,将返回总体结果。data
:包含这些变量的调查设计对象。所有变量(包括 vars 和 strata)必须在此调查设计对象中。调查设计对象通常使用 survey 包中的svydesign
函数创建。includeNA
:如果为 TRUE,则将 NA 视为常规因子水平而不是缺失值。NA 在表中显示为最后一个因子水平。仅对分类变量有效。test
:如果为 TRUE(默认值),并且有两组以上,将执行组内比较。执行基于大样本近似和精确测试的两种测试。可以从打印方法中获取其中一种结果。testApprox
:用于执行基于大样本近似的测试的函数。默认值是 svychisq。argsApprox
:传递给 testApprox 指定的函数的参数的命名列表。smd
:如果为 TRUE(默认值),并且有两组以上,将计算所有成对比较的标准化均值差。addOverall
:(可选,仅在提供 strata 时使用)将一个总体列添加到表中。SMD 和 p-值计算仅使用分层列。
返回值
一个类为 svyCatTable
的对象。
这个函数用于创建一个汇总加权数据的分类变量的对象,可用于执行统计分析和生成报告。
summary.svyCatTable
summary.svyCatTable
函数用于显示 svyCatTable
类对象的所有数据,包括(可选的分层)部分的汇总统计信息以及来自近似方法测试(默认为 chisq.test
)和精确方法测试(默认为 fisher.test
)的p-值(如果可用),以及所有可能的成对对比的标准化均值差。
用法
## S3 method for class 'svyCatTable'
summary(object, digits = 1, ...)
参数
object
:具有svyCatTable
类的对象,需要展示其结果。digits
:要打印的小数位数。...
:为了与通用函数兼容而保留的参数,忽略。
返回值
无返回值,结果将被打印。
作者
Kazuki Yoshida
参见
svyCreateTableOne
svyCreateCatTable
print.svyCatTable
这个函数用于展示 svyCatTable
类对象的所有数据,可用于查看汇总统计信息、p-值以及标准化均值差等相关信息。这对于数据分析和研究中的结果可视化和报告非常有用。
print.svyCatTable
print.svyCatTable
函数用于格式化和打印 svyCatTable
类对象的结果,这些对象是由 svyCreateCatTable
函数创建的。这个函数用于以可读的方式呈现汇总统计信息、p-值、标准化均值差等结果。
用法
## S3 method for class 'svyCatTable'
print(
x,
digits = 1,
pDigits = 3,
quote = FALSE,
missing = FALSE,
explain = TRUE,
printToggle = TRUE,
noSpaces = FALSE,
format = c("fp", "f", "p", "pf")[1],
showAllLevels = FALSE,
cramVars = NULL,
dropEqual = FALSE,
test = TRUE,
exact = NULL,
smd = FALSE,
CrossTable = FALSE,
formatOptions = list(scientific = FALSE),
...
)
参数
x
:svyCreateCatTable 函数的调用结果。digits
:在表格中要打印的小数位数。pDigits
:要打印的p-值的小数位数(也用于标准化均值差)。quote
:是否将所有内容都显示在引号中。默认值为 FALSE。如果为 TRUE,则包括行和列名称在内的所有内容都将用引号括起,以便轻松复制到 Excel 中。missing
:是否显示缺失数据信息。explain
:是否在变量名称中添加解释,即当显示百分比时,是否在变量名称后添加 (%)。printToggle
:是否打印输出。如果为 FALSE,则不会创建输出,并且会返回一个不可见的矩阵对象。noSpaces
:是否删除用于对齐的空格。如果您希望在其他软件中自行对齐数字,可以使用此选项。format
:默认值为 “fp”(频率百分比)。您还可以选择 “f”(频率)、“p”(百分比)和 “pf”(百分比和频率)。showAllLevels
:是否显示所有级别。默认值为 FALSE,即对于二级分类变量,只显示较高级别,以避免冗余信息。cramVars
:一个字符向量,用于指定应该在一行中显示两个级别的二级分类变量。dropEqual
:是否删除指示哪个级别对于二级分类变量的 " = second level name" 描述。test
:是否显示p-值。默认为 TRUE。如果为 FALSE,则只显示数值摘要。exact
:此选项对于加权数据的表格不可用。smd
:是否显示标准化均值差。默认为 FALSE。如果存在多个对比,将显示所有可能的标准化均值差的平均值。对于单个对比,请使用summary
。CrossTable
:是否显示内部使用gmodels::CrossTable
函数保存的交叉表对象。这将产生类似于 SAS 中的 PROC FREQ 的输出。
返回值
返回一个包含与输出相同内容的矩阵对象。可以为其指定名称并通过 write.csv
导出。
这个函数用于格式化和打印 svyCatTable
类对象的结果,可用于数据分析和研究中的结果可视化和报告。
svyCreateTableOne
:汇总加权数据的基线变量
svyCreateTableOne
函数是 tableone
包中的一个函数,用于创建一个对象,该对象汇总了加权数据的基线变量(包括连续和分类变量),并可选择通过一个或多个分层变量进行分层,并进行统计检验。这个对象生成一个易于在医学研究论文中使用的表格。
以下是 svyCreateTableOne
函数的主要参数和用法:
svyCreateTableOne(
vars,
strata,
data,
factorVars,
includeNA = FALSE,
test = TRUE,
testApprox = svyTestChisq,
argsApprox = NULL,
testNormal = svyTestNormal,
argsNormal = list(method = "Wald"),
testNonNormal = svyTestNonNormal,
argsNonNormal = NULL,
smd = TRUE,
addOverall = FALSE
)
参数说明:
vars
:要汇总的变量,以字符向量的形式提供。因子(Factor)将被处理为分类变量(Categorical),而数值变量将被处理为连续变量(Continuous)。strata
:用作分层(分组)变量的名称,以字符向量的形式提供。如果省略,则返回总体结果。data
:包含这些变量的调查设计对象(survey design object)。所有变量(包括vars
和strata
中的变量)必须包含在此调查设计对象中。该对象是使用survey
包中的svydesign
函数创建的。factorVars
:要视为分类变量的数值编码变量,以字符向量的形式提供。不包括因子变量,除非您需要通过删除空级别(empty levels)来重新调整它们的级别。如果省略,则只考虑因子变量。includeNA
:一个逻辑值,如果为TRUE,则NA将被视为普通的因子水平而不是缺失值。NA将显示为表中的最后一个因子水平,仅对分类变量有效。test
:一个逻辑值,如果为TRUE(默认),并且存在多个组,则执行组内比较。testApprox
:执行基于大样本近似的测试的函数。默认为svychisq
。argsApprox
:传递给testApprox
指定函数的参数的命名列表。testNormal
:执行基于正态分布假设的测试的函数。默认为使用svyglm
和regTermTest
进行多个自由度测试。当只有两组时,等效于svyttest
。argsNormal
:传递给testNormal
指定函数的参数的命名列表。testNonNormal
:执行非参数测试的函数。默认为svyranktest
。argsNonNormal
:传递给testNonNormal
指定函数的参数的命名列表。smd
:一个逻辑值,如果为TRUE(默认)并且存在多个组,则计算所有成对比较的标准化均值差。addOverall
:一个可选的逻辑值,仅在提供了分层变量时使用。如果为TRUE,则在表格中添加一个总体列。标准化均值差和p值的计算仅在分层列中进行。
返回值:
svyCreateTableOne
函数返回一个 svyTableOne
类的对象,该对象包含了三个部分:
ContTable
:包含连续变量的对象,属于svyContTable
类。CatTable
:包含分类变量的对象,属于svyCatTable
类。MetaData
:包含变量相关元数据的列表。
这个函数的详细信息可以查看 CreateTableOne
函数的详细信息,因为它是 CreateTableOne
函数的一个变体。
如果需要查看对象的内容或执行更详细的操作,可以使用 summary
函数、print
函数或直接访问对象的部分来进行进一步操作。
以下是示例代码,演示了如何使用 svyCreateTableOne
函数:
# 示例代码见上述 "Examples" 部分
这些示例代码展示了如何使用 svyCreateTableOne
函数来创建
和操作加权数据的汇总表格对象。