前言
rcssci包横空出世,限制性立方样条 rcssci包V0.1.0版本上一期笔者详细介绍了原理及案例细节,小伙伴们反馈非常非常好。此次更新V0.3.0版,大量修复了目前小伙伴们反馈的各种bug,且提供了自定义knot选项。但是,由于R4.2.2更新且相应的R包也对应更新,导致本包prob功能失效。笔者测试了很久R4.2.0和 R4.2.1都没有发现问题所在(应该是tidyverse等众包都更新到了R4.2.2的原因),且无奈官网昨天才接收V0.2.0版(2022-11-07),只能放出V0.3.0版,需要小伙伴们手动加载,加载方式如图。
上一期笔者放出V0.1.0版本和个人微信号,但是加的人太多了,许多人压根没有认真看说明就劈头盖脸问一堆很基础的问题,尽管笔者耐心解答了问题,但是其实这是对自己与他人的不尊重。此次,笔者再次详细说明下用法,以飨水友,请不要问baidu随便可搜到的问题!
rcssci包V0.3.0核心函数有3个,rcssci_cox、rcssci_logistic、rcssci_linear。笔者内置了团队数据sbpdata.rdata文件,比V0.1.0版升级了全部数据更贴近上一期文章数据。
先手动加载rcssciV0.3.0包。
rcssci_logistic命令搞定logistic分析rcs绘制,prob推荐0.1,不写默认0.5。在setwd()工作路径下,自动输出4套RCS双坐标图分别为:fig.logistic_proball.pdf,fig.logistic_ushapall.PDF,fig.logistic_nshapall.PDF,fig.logistic_lshapall.PDF。
sbpdata <- rcssci::sbpdata
pacman::p_load(rcssci)
#一次输出4个PDF图,不设置knot则默认根据AIC最小全自动建模
rcssci_logistic(data=sbpdata, y = "status",x = "sbp",covs=c("age","gender"),prob=0.1,filepath= "bugfig")
#一次输出4个PDF图,设置knot=4(推荐3或4)则手动建模,注意,此时需要前期类似研究或者文章中多个rcs表众数knot
rcssci_logistic(knot=4,data=sbpdata, y = "status",x = "sbp",covs=c("age","gender"),prob=0.1,filepath= "bugfig")
当然,也可以使用命令rcs_logistic.prob,rcs_logistic.lshap,rcs_logistic.nshap,rcs_logistic.ushap一个个图选择性输出。
#单个图单独输出,例如
rcs_logistic.prob(knot=4,data=sbpdata, y = "status",x = "sbp",covs=c("age","gender"),prob=0.1,filepath= "bugfig")
rcs_logistic.ushap(knot=4,data=sbpdata, y = "status",x = "sbp",covs=c("age","gender"),prob=0.1,filepath= "bugfig")
#一次输出4个PDF图,设置knot=4(推荐3或4)则手动建模,注意,此时需要前期类似研究或者文章中多个rcs表众数knot 当然,也可以使用命令rcs_cox.prob,rcs_ cox.lshap,rcs_ cox.nshap,rcs_ cox.ushap一个个图选择性输出。
rcssci_cox(knot=4,data=sbpdata, y = "status",x = "sbp",time="time",covs=c("age","gender"),prob=0.1,filepath= "bugfig")
#一次输出4个PDF图,设置knot=4(推荐3或4)则手动建模,注意,此时需要前期类似研究或者文章中多个rcs表众数knot
rcssci_linear(knot=4,data=sbpdata, y = "status",x = "sbp",covs=c("age","gender"),prob=0.1,filepath= "bugfig")
当然,也可以使用命令rcs_linear.prob,rcs_linear.lshap,rcs_linear.nshap,rcs_linear.ushap一个个图选择性输出。
R4.2.0以上需要安装RTools4.2系列, 安装文件见
https://cran.r-project.org/bin/windows/Rtools/
rcssci_cox(data=dat2, y = "outcome",x = "x",time = "ftime",covs=c("age","gender"), prob=0.1,filepath="C:/Users/HBL/Documents")
不加协变量能跑,加入协变量后就不行了 Error in solve.default(imat, u) : system is computationally singular: reciprocal condition number = 1.3057e-16
rcssciV0.3.0代码:#默认AIC最小选取knot rcssci_cox(data=dat2, y = "outcome",x = "x",time = "ftime",covs=c("age","gender"), prob=0.1,filepath="C:/Users/ Documents") #当knot=6 或7 且曲线很乱时,可参考AIC差值酌情自行选取knot 3 4 5,本例选knot=4 rcssci_cox(data=dat2, knot=4,,y = "outcome",x = "x",time = "ftime",covs=c("age","gender"), prob=0.1,filepath="C:/Users/ Documents")
自定义Knot=3,Knot=4
Knot 依据AIC min=7
$aics [1] 5107.766 5106.369 5108.026 5108.230 5102.996 查看AIC 3-7,AIC差距较小。选择fig.cox_proball.PDF图,7过于复杂,knot=不够美观,knot=4是不错的选择,HR急速下降后缓坡的L型,最后选择fig.cox_lshapall.PDF图,切点为x=1.128。
PH假设也是devianced均匀分布在x = 0的参考线两边为宜,P>0.05适用于经典cox分析。
I've dealt with the exact same problem. My teacher told me that this is because one of my variables is much bigger than the others. (In my case, the trading volume was much bigger than the returns in two different moments.) The problem is because of limitations in floating-point computations and precision, not anything inherently mathematical or statistical. bug问题在于浮点计算和精度的限制。Therefore I've divided the biggest variable by 1000000. dataVolume / 1000000 10w人数据量,需要
covs少,且最小AIC=3 $aics [1] 7509.905 7510.794 7512.716 7514.716 7516.294
当covs提高到几十个,强制拉升人为设置knot=5-7时,会error。此时,建议保留AIC min为标注。
取完log 在用rcssci就能行,原始数据不行
关闭PDF重启跑一次, 有可能是rcssci包没安装好,重装一次RTools4.2和rcssci。大家需要安装adobe pdf reader或者 acrobat 。当然,也可能是你的filepath路径名称命名错误。
拉大右下角
#尽量不要原始数据有x变量,如有需要直接替换x。M111x,exp(1)) rcs_logistic.lshap(data=M111, y = "y",x = "x", prob=0.1,filepath="D:/聂个人文件/我的公众号/RCS/rcssciV2.0/bug反馈") 方法学写上:Log transformation was used because of the positive skew of x value
BUG 8 prob定义失效
更新R4.2.2后,rcssci包的prob定义失效。请更新rcssci v0.3.0版本。
百度盘如下。链接:https://pan.baidu.com/s/1wMZVyMySgZpc9LFG3kYAqA?pwd=f21q 提取码:f21q
小结
rcssci V0.3.0更新了knot手动设定,修复了8个bug。
为了更好的高效交流,本公众号建立了学术交流群。注意,本群仅供SCI学术交流,代码讨论,拒绝广告水文,拒绝潜水。由于人数有限,需要实名制,入群请说明:姓名-学校(单位)-专业。
如果你觉得rcssci好,请分享给你的课题组吧,多些人受益也是笔者更新的动力。
原创不易,转载请说明来自本公众号。