tableone是帮助我们快速生成文章中table1表格的一个包,通常来说一篇SCI文章的第一个表都会给出样本的基线情况。而tableone就是可以帮我们快速地汇总描述所有样本的基线变量的一个包。
今天就给大家写写tableone,其实还有一个包叫做table1,功能差不多,以后给大家写。
实例解析
还是写一个例子帮助大家理解,用到的数据是R自带的pbc数据集。这个数据集是梅奥诊所收治的肝硬化病人的数据,共424个。
This data is from the Mayo Clinic trial in primary biliary cirrhosis (PBC) of the liver conducted between 1974 and 1984. A total of 424 PBC patients, referred to Mayo Clinic during that ten-year interval, met eligibility criteria for the randomized placebo controlled trial of the drug D-penicillamine。
这个数据集大概长这样:
现在我想要看看整个数据集的描述性分析,那么我就可以:
CreateTableOne(data = pbc)
输出如下:
看到没,所有的数值变量都给你以均值标准差的形式描述好了,因子变量频数百分比也描述好了,不用你再用什么SPSS一个一个来描述统计了。
等等,问题还是有滴,比如:
- 数据库中其实有很多变量应该是因子类型的,但是都给整成整数型了
- 连ID都给描述了,这玩意我不需要
我们来调整一下,比如我论文中只需要描述如下的变量: