{"id":25241,"date":"2024-01-19T16:51:01","date_gmt":"2024-01-19T08:51:01","guid":{"rendered":"http:\/\/www.biocloudservice.com\/wordpress\/?p=25241"},"modified":"2024-01-19T16:51:03","modified_gmt":"2024-01-19T08:51:03","slug":"glm%e5%a6%99%e8%83%bd%ef%bc%9a%e7%94%a8glmnet%e9%a2%84%e6%b5%8b%e7%b3%96%e5%b0%bf%e7%97%85%e7%9a%84lasso%e4%b9%8b%e9%81%93","status":"publish","type":"post","link":"http:\/\/www.biocloudservice.com\/wordpress\/?p=25241","title":{"rendered":"GLM\u5999\u80fd\uff1a\u7528glmnet\u9884\u6d4b\u7cd6\u5c3f\u75c5\u7684Lasso\u4e4b\u9053"},"content":{"rendered":"<p>Lasso\uff08Least Absolute Shrinkage and Selection Operator\uff09\u7b97\u6cd5\u662f\u4e00\u79cd\u7528\u4e8e\u7279\u5f81\u9009\u62e9\u548c\u6a21\u578b\u6b63\u5219\u5316\u7684\u7ebf\u6027\u56de\u5f52\u65b9\u6cd5\u3002\u5b83\u901a\u8fc7\u5728\u635f\u5931\u51fd\u6570\u4e2d\u5f15\u5165L1\u6b63\u5219\u5316\u9879\uff0c\u8feb\u4f7f\u6a21\u578b\u7cfb\u6570\u7a00\u758f\u5316\uff0c\u5c06\u4e00\u4e9b\u7cfb\u6570\u538b\u7f29\u4e3a\u96f6\uff0c\u4ece\u800c\u5b9e\u73b0\u7279\u5f81\u9009\u62e9\u7684\u6548\u679c\u3002<\/p>\n<p>\u60f3\u8981\u6df1\u5165\u4e86\u89e3Lasso\u7b97\u6cd5\u539f\u7406\uff0c\u9700\u8981\u6211\u4eec\u4e00\u6b65\u4e00\u6b65\u5bfb\u627eLasso\u7b97\u6cd5\u7684\u6765\u6e90\uff0c\u5982\u4e0b\u662f\u5c0f\u679c\u7684\u5b66\u4e60\u601d\u8003\u603b\u7ed3\uff1a<\/p>\n<ol>\n<li>\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff1a<\/li>\n<\/ol>\n<p>\u6211\u4eec\u5148\u56de\u987e\u4e00\u4e0b\u7b80\u5355\u7684\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff1ay = \u03b20 + \u03b21&#215;1 + \u03b22&#215;2 + &#8230; + \u03b2nxn\uff0c\u5176\u4e2dy\u662f\u56e0\u53d8\u91cf\uff0cx1, x2, &#8230;, xn\u662f\u81ea\u53d8\u91cf\uff0c\u03b20, \u03b21, \u03b22, &#8230;, \u03b2n\u662f\u6a21\u578b\u7684\u7cfb\u6570\u3002<\/p>\n<ol>\n<li>\u6700\u5c0f\u4e8c\u4e58\u6cd5\uff1a<\/li>\n<\/ol>\n<p>\u5728\u666e\u901a\u7684\u7ebf\u6027\u56de\u5f52\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u6700\u5c0f\u4e8c\u4e58\u6cd5\u6765\u4f30\u8ba1\u6a21\u578b\u7684\u7cfb\u6570\uff0c\u5373\u901a\u8fc7\u6700\u5c0f\u5316\u5b9e\u9645\u89c2\u6d4b\u503c\u548c\u6a21\u578b\u9884\u6d4b\u503c\u4e4b\u95f4\u7684\u6b8b\u5dee\u5e73\u65b9\u548c\u6765\u6c42\u89e3\u7cfb\u6570\u3002\u8fd9\u79cd\u65b9\u6cd5\u6ca1\u6709\u5bf9\u7cfb\u6570\u8fdb\u884c\u4efb\u4f55\u7ea6\u675f\u3002<\/p>\n<ol>\n<li>\u5f15\u5165L1\u6b63\u5219\u5316\u9879\uff1a<\/li>\n<\/ol>\n<p>\u5728Lasso\u7b97\u6cd5\u4e2d\uff0c\u6211\u4eec\u5f15\u5165L1\u6b63\u5219\u5316\u9879\u4f5c\u4e3a\u7ea6\u675f\u6761\u4ef6\uff0c\u4ee5\u4fc3\u4f7f\u6a21\u578b\u7cfb\u6570\u7a00\u758f\u5316\u3002L1\u6b63\u5219\u5316\u9879\u662f\u6a21\u578b\u7cfb\u6570\u7684\u7edd\u5bf9\u503c\u4e4b\u548c\u4e0e\u4e00\u4e2a\u8c03\u8282\u53c2\u6570\u03bb\u7684\u4e58\u79ef\uff0c\u53ef\u4ee5\u5199\u4e3a\uff1a\u03bb * (|\u03b21| + |\u03b22| + &#8230; + |\u03b2n|)\u3002<\/p>\n<ol>\n<li>Lasso\u7684\u4f18\u5316\u76ee\u6807\uff1a<\/li>\n<\/ol>\n<p>Lasso\u7684\u76ee\u6807\u662f\u5c06\u6700\u5c0f\u5316\u7684\u635f\u5931\u51fd\u6570\u4e0eL1\u6b63\u5219\u5316\u9879\u76f8\u7ed3\u5408\uff0c\u5f62\u6210\u4f18\u5316\u76ee\u6807\u51fd\u6570\uff1aminimize(\u5e73\u65b9\u635f\u5931\u51fd\u6570 + \u03bb * (|\u03b21| + |\u03b22| + &#8230; + |\u03b2n|))\u3002<\/p>\n<ol>\n<li>\u6700\u5c0f\u5316\u76ee\u6807\u51fd\u6570\uff1a<\/li>\n<\/ol>\n<p>\u6211\u4eec\u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u6765\u6700\u5c0f\u5316\u76ee\u6807\u51fd\u6570\uff0c\u4e00\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u5750\u6807\u4e0b\u964d\u6cd5\uff08coordinate descent\uff09\u3002\u5728\u5750\u6807\u4e0b\u964d\u6cd5\u4e2d\uff0c\u6211\u4eec\u9010\u4e2a\u66f4\u65b0\u6a21\u578b\u7cfb\u6570\uff0c\u901a\u8fc7\u8fed\u4ee3\u4f18\u5316\u6765\u9010\u6b65\u903c\u8fd1\u6700\u4f18\u89e3\u3002<\/p>\n<ol>\n<li>\u5750\u6807\u4e0b\u964d\u6cd5\u7684\u8fed\u4ee3\u8fc7\u7a0b\uff1a<\/li>\n<\/ol>\n<p>\u2460\u521d\u59cb\u5316\u6a21\u578b\u7cfb\u6570\u03b2\u4e3a\u96f6\u6216\u4e00\u4e2a\u8f83\u5c0f\u7684\u503c\u3002<\/p>\n<p>\u2461\u9488\u5bf9\u6bcf\u4e2a\u7cfb\u6570\u03b2i\uff0c\u56fa\u5b9a\u5176\u4ed6\u7cfb\u6570\u4e0d\u53d8\uff0c\u901a\u8fc7\u6c42\u89e3\u6700\u5c0f\u5316\u76ee\u6807\u51fd\u6570\u7684\u4e00\u7ef4\u5b50\u95ee\u9898\u6765\u66f4\u65b0\u03b2i\u3002<\/p>\n<p>\u2462\u91cd\u590d\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u76f4\u5230\u6ee1\u8db3\u6536\u655b\u6761\u4ef6\u3002<\/p>\n<ol>\n<li>\u5b50\u95ee\u9898\u7684\u6c42\u89e3\uff1a<\/li>\n<\/ol>\n<p>\u5728\u6bcf\u4e2a\u5b50\u95ee\u9898\u4e2d\uff0c\u901a\u8fc7\u6c42\u89e3\u6700\u5c0f\u5316\u76ee\u6807\u51fd\u6570\u5173\u4e8e\u03b2i\u7684\u4e00\u9636\u5bfc\u6570\u4e3a\u96f6\u7684\u65b9\u7a0b\u6765\u66f4\u65b0\u03b2i\u3002\u8fd9\u4e2a\u65b9\u7a0b\u53ef\u4ee5\u5199\u4e3a\uff1a2 * (\u03a3(xi * (yi &#8211; (\u03b20 + \u03b21&#215;1 + \u03b22&#215;2 + &#8230; + \u03b2nxn)))) + \u03bb * sign(\u03b2i) = 0\uff0c\u5176\u4e2dsign(\u03b2i)\u662f\u03b2i\u7684\u7b26\u53f7\u51fd\u6570\u3002<\/p>\n<ol>\n<li>Lasso\u7b97\u6cd5\u7684\u7279\u70b9\uff1a<\/li>\n<\/ol>\n<p>Lasso\u7b97\u6cd5\u7684\u7279\u70b9\u5728\u4e8e\u5b83\u5f15\u5165\u4e86L1\u6b63\u5219\u5316\u9879\uff0c\u4fc3\u4f7f\u6a21\u578b\u7cfb\u6570\u7a00\u758f\u5316\uff0c\u5b9e\u73b0\u7279\u5f81\u9009\u62e9\u7684\u6548\u679c\u3002Lasso\u53ef\u4ee5\u901a\u8fc7\u8c03\u8282\u6b63\u5219\u5316\u53c2\u6570\u03bb\u6765\u63a7\u5236\u7a00\u758f\u6027\u7a0b\u5ea6\uff0c\u8f83\u5927\u7684\u03bb\u4f1a\u5bfc\u81f4\u66f4\u591a\u7684\u7cfb\u6570\u88ab\u538b\u7f29\u4e3a\u96f6\u3002<\/p>\n<p>\u603b\u7ed3\u4e00\u4e0b\uff0cLasso\u7b97\u6cd5\u901a\u8fc7\u5728\u635f\u5931\u51fd\u6570\u4e2d\u5f15\u5165L1\u6b63\u5219\u5316\u9879\uff0c\u8feb\u4f7f\u6a21\u578b\u7cfb\u6570\u7a00\u758f\u5316\uff0c\u5b9e\u73b0\u7279\u5f81\u9009\u62e9\u548c\u6a21\u578b\u6b63\u5219\u5316\u7684\u6548\u679c\u3002\u5b83\u4f7f\u7528\u5750\u6807\u4e0b\u964d\u6cd5\u8fed\u4ee3\u4f18\u5316\uff0c\u901a\u8fc7\u89e3\u51b3\u5b50\u95ee\u9898\u6765\u66f4\u65b0\u6a21\u578b\u7cfb\u6570\u3002Lasso\u7b97\u6cd5\u5728\u673a\u5668\u5b66\u4e60\u4e2d\u88ab\u5e7f\u6cdb\u5e94\u7528\uff0c\u7279\u522b\u9002\u7528\u4e8e\u9ad8\u7ef4\u6570\u636e\u548c\u7279\u5f81\u9009\u62e9\u7684\u573a\u666f\uff0c\u5c24\u5176\u662f\u5728\u9009\u62e9\u7279\u5f81\u57fa\u56e0\u7528\u4e8e\u75be\u75c5\u8bca\u65ad\u65f6\u3002<\/p>\n<p><a id=\"post-25241-OLE_LINK2\"><\/a> R\u5305glmnet\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684Lasso\u548cElastic-Net\u6b63\u5219\u5316\u65b9\u6cd5\uff0c\u7528\u4e8e\u62df\u5408\u5e7f\u4e49\u7ebf\u6027\u6a21\u578b\u3002\u5b83\u652f\u6301\u7ebf\u6027\u56de\u5f52\u3001\u903b\u8f91\u56de\u5f52\u3001\u591a\u9879\u5f0f\u56de\u5f52\u3001\u6cca\u677e\u56de\u5f52\u3001Cox\u6a21\u578b\u7b49\u591a\u79cd\u6a21\u578b\u3002glmnet\u7684\u7b97\u6cd5\u57fa\u4e8e\u5faa\u73af\u5750\u6807\u4e0b\u964d\uff0c\u53ef\u4ee5\u5feb\u901f\u8ba1\u7b97\u6574\u4e2a\u6b63\u5219\u5316\u8def\u5f84\u3002\u6b64\u5916\uff0cglmnet\u8fd8\u652f\u6301\u81ea\u5b9a\u4e49\u7684GLM family\u5bf9\u8c61\u548crelax\u9009\u9879\u3002\u901a\u8fc7glmnet\uff0c\u53ef\u4ee5\u8fdb\u884c\u7279\u5f81\u9009\u62e9\u3001\u6a21\u578b\u6b63\u5219\u5316\u548c\u9884\u6d4b\u7b49\u4efb\u52a1\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528R\u5305<a id=\"post-25241-OLE_LINK5\"><\/a>glmnet\u8fdb\u884c\u7cd6\u5c3f\u75c5\u9884\u6d4b\u6a21\u578b\u7684\u8bad\u7ec3\u548c\u8bc4\u4f30\uff1a<\/p>\n<p>\u4ee3\u7801\u5177\u4f53\u5305\u62ec\uff1a<\/p>\n<p>Step1 \u5bfc\u5165\u6570\u636e\u96c6\u4ee5\u53ca\u6570\u636e\u9884\u5904\u7406<\/p>\n<p># \u8fd9\u91cc\u7684&#8221;inputdata.txt&#8221;\u662f\u81ea\u884c\u51c6\u5907\u7684\u672c\u5730\u6587\u4ef6\uff0c\u5c0f\u679c\u7ed9\u5927\u5bb6\u9644\u5728\u6700\u540e\u3002<\/p>\n<p># 1.\u5bfc\u5165\u6570\u636e\u96c6\u4ee5\u53ca\u6570\u636e\u9884\u5904\u7406<\/p>\n<p># \u5b89\u88c5\u548c\u52a0\u8f7d\u6240\u9700\u7684\u5e93<\/p>\n<p># install.packages(&#8220;glmnet&#8221;)<\/p>\n<p>library(glmnet)<\/p>\n<p># \u5bfc\u5165\u6570\u636e\u96c6<\/p>\n<p>data &lt;- read.table(file = &#8220;D:\/wanglab\/life\/ziyuan\/20230628\/inputdata.txt&#8221;,header = T) # \u66ff\u6362\u4e3a\u5b9e\u9645\u6570\u636e\u96c6\u6587\u4ef6\u7684\u8def\u5f84<\/p>\n<p>data[, 1:8] &lt;- scale(data[, 1:8])# \u6570\u636e\u6807\u51c6\u5316<\/p>\n<p>data$diabetes &lt;- as.factor(data$diabetes)# \u5c06\u76ee\u6807\u53d8\u91cf\u8f6c\u6362\u4e3a\u56e0\u5b50<\/p>\n<p># \u5212\u5206\u6570\u636e\u96c6\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6<\/p>\n<p>set.seed(123) # \u8bbe\u7f6e\u968f\u673a\u79cd\u5b50\uff0c\u4fdd\u8bc1\u7ed3\u679c\u53ef\u590d\u73b0<\/p>\n<p>indices &lt;- sample(1:nrow(data), nrow(data)*0.8) # 80%\u7684\u6570\u636e\u7528\u4e8e\u8bad\u7ec3\uff0c20%\u7684\u6570\u636e\u7528\u4e8e\u6d4b\u8bd5<\/p>\n<p>train_data &lt;- data[indices, ]<\/p>\n<p>test_data &lt;- data[-indices, ]<\/p>\n<p>Xtrain&lt;-as.matrix(trainingset[,1:8])<\/p>\n<p>Ytrain&lt;-as.matrix(trainingset[,9])<\/p>\n<p>Xtest&lt;-as.matrix(testingset[,1:8])<\/p>\n<p>Ytest&lt;-as.matrix(testingset[,9])<\/p>\n<p>Step2\u521b\u5efalasso\u56de\u5f52\u6a21\u578b<\/p>\n<p># 2.<a id=\"post-25241-OLE_LINK3\"><\/a>\u521b\u5efa\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b<\/p>\n<p># 2.\u521b\u5efalasso\u56de\u5f52\u6a21\u578b<\/p>\n<p>lsofit&lt;-glmnet(Xtrain,Ytrain,family=&#8221;binomial&#8221;,alpha=0.1)<\/p>\n<p>print(lsofit)##lasso\u56de\u5f52\u7cfb\u6570<\/p>\n<p>coef.apprx&lt;-coef(lsofit, s=0.017)<\/p>\n<p>coef.apprx<\/p>\n<p>plot(lsofit,xvar=&#8221;lambda&#8221;,label=TRUE)# \u753bLasso\u7b5b\u9009\u53d8\u91cf\u52a8\u6001\u8fc7\u7a0b\u56fe<\/p>\n<p><a id=\"post-25241-OLE_LINK4\"><\/a><strong>Lasso\u7b5b\u9009\u53d8\u91cf\u52a8\u6001\u8fc7\u7a0b\u56fe<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"556\" height=\"490\" class=\"wp-image-25242\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-1.png?resize=556%2C490\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-1.png?w=556 556w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-1.png?resize=300%2C264 300w\" sizes=\"(max-width: 556px) 100vw, 556px\" data-recalc-dims=\"1\" \/><\/p>\n<p>Step3 K\u6298\u4ea4\u53c9\u9a8c\u8bc1<\/p>\n<p># 3.K\u6298\u4ea4\u53c9\u9a8c\u8bc1<\/p>\n<p>set.seed(2022) #\u8bbe\u7f6e\u968f\u673a\u79cd\u5b50\uff0c\u4fdd\u8bc1K\u6298\u9a8c\u8bc1\u7684\u53ef\u91cd\u590d\u6027<\/p>\n<p>lsocv&lt;-cv.glmnet(Xtrain,Ytrain,family=&#8221;binomial&#8221;,nfolds=10)<\/p>\n<p>lsocv ##print(lsocv)<\/p>\n<p>lsocv$lambda.min<\/p>\n<p>lsocv$lambda.1se<\/p>\n<p>plot(lsocv) #\u7ed8\u5236\u4ea4\u53c9\u9a8c\u8bc1\u66f2\u7ebf<\/p>\n<p><strong>\u4ea4\u53c9\u9a8c\u8bc1\u66f2\u7ebf\u56fe<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"556\" height=\"490\" class=\"wp-image-25243\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-2.png?resize=556%2C490\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-2.png?w=556 556w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-2.png?resize=300%2C264 300w\" sizes=\"(max-width: 556px) 100vw, 556px\" data-recalc-dims=\"1\" \/><\/p>\n<p>coef(lsocv,s=&#8221;lambda.min&#8221;) #\u83b7\u53d6\u4f7f\u6a21\u578b\u504f\u5dee\u6700\u5c0f\u65f6\u03bb\u503c\u7684\u6a21\u578b\u7cfb\u6570<\/p>\n<p>coef(lsocv,s=&#8221;lambda.1se&#8221;) #\u83b7\u53d6\u4f7f\u6a21\u578b\u504f\u5dee\u6700\u5c0f\u65f6\u03bb\u503c+\u4e00\u4e2a\u6807\u51c6\u8bef\u65f6\u7684\u6a21\u578b\u7cfb\u6570<\/p>\n<p>cbind2(coef(lsocv,s=&#8221;lambda.min&#8221;),coef(lsocv,s=&#8221;lambda.1se&#8221;)) #\u5408\u5e76\u663e\u793a<\/p>\n<p>select_x &lt;- names(which(coef(lsocv,s=&#8221;lambda.1se&#8221;)[-1,] != 0))<\/p>\n<p>select_x\u5f97\u5230\u5bf9\u9884\u6d4b\u7ed3\u679c\u6709\u5f71\u54cd\u7684\u56e0\u7d20<\/p>\n<p>Step 4.\u7ed8\u5236AUC\u66f2\u7ebf\u8bc4\u4f30\u6a21\u578b<\/p>\n<p># 4.\u7ed8\u5236AUC\u66f2\u7ebf\u8bc4\u4f30\u6a21\u578b<\/p>\n<p>predictions &lt;- lsocv %&gt;% predict(as.matrix(test_data[, 1:8]))# \u9884\u6d4b\u6982\u7387<\/p>\n<p># \u8ba1\u7b97AUC<\/p>\n<p>library(pROC)<\/p>\n<p>roc_obj &lt;- roc(test_data$diabetes, predictions)<\/p>\n<p>auc_value &lt;- auc(roc_obj)<\/p>\n<p># \u7ed8\u5236AUC\u66f2\u7ebf<\/p>\n<p>plot(roc_obj, main = &#8220;ROC Curve&#8221;)<\/p>\n<p>text(0.5, 0.3, paste0(&#8220;AUC = &#8220;, round(auc_value, 3)), col = &#8220;red&#8221;, cex = 1.2)<\/p>\n<p><strong>AUC\u66f2\u7ebf\u56fe<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"556\" height=\"490\" class=\"wp-image-25244\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-3.png?resize=556%2C490\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-3.png?w=556 556w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-3.png?resize=300%2C264 300w\" sizes=\"(max-width: 556px) 100vw, 556px\" data-recalc-dims=\"1\" \/><\/p>\n<p>Step5.\u7ed8\u5236\u5217\u7ebf(Nomogram)\u56fe<\/p>\n<p># 5.\u7ed8\u5236\u5217\u7ebf(Nomogram)\u56fe<\/p>\n<p><a id=\"post-25241-OLE_LINK1\"><\/a> library(rms);library(Hmisc);library(lattice);library(survival);library(Formula);library(ggplot2);library(SparseM)<\/p>\n<p>NM&lt;-datadist(trainingset)<\/p>\n<p>options(datadist=&#8217;NM&#8217;)<\/p>\n<p>lgrfit&lt;-lrm(diabetes~pregnant+glucose+mass+pedigree+age,data=trainingset,x=T,y=T)<\/p>\n<p>Nomg&lt;-nomogram(lgrfit,fun=plogis,fun.at=c(.001,.01,.05,0.1,seq(.2,.8,by=.2),0.9,.95,.99,.999),lp=F,funlabel=&#8221;malignant Rate&#8221;)<\/p>\n<p>plot(Nomg)<\/p>\n<p><strong>\u5217\u7ebf\u56fe(Nomogram)\u56fe<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"640\" height=\"466\" class=\"wp-image-25245\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-4.png?resize=640%2C466\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-4.png?w=759 759w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-4.png?resize=300%2C219 300w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-4.png?resize=600%2C437 600w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/p>\n<p># 6.\u7ed8\u5236\u591a\u56e0\u7d20Cox\u56de\u5f52\u68ee\u6797\u56fe<\/p>\n<p># 6.\u7ed8\u5236\u591a\u56e0\u7d20Cox\u56de\u5f52\u68ee\u6797\u56fe<\/p>\n<p>library(survival)<\/p>\n<p>library(survminer)<\/p>\n<p>library(tidyverse)<\/p>\n<p>library(eoffice)<\/p>\n<p>library(forestplot)<\/p>\n<p>trainingset$diabetes &lt;- as.numeric(trainingset$diabetes)<\/p>\n<p>model &lt;- coxph(Surv(diabetes)~pregnant+glucose+mass+pedigree+age,<\/p>\n<p>data = trainingset[,c(&#8216;pregnant&#8217;,&#8217;glucose&#8217;,&#8217;mass&#8217;,&#8217;pedigree&#8217;,&#8217;age&#8217;,&#8221;diabetes&#8221;)] )<\/p>\n<p>ggforest(model = model,#cox\u56de\u5f52\u65b9\u7a0b<\/p>\n<p>data = trainingset[,c(&#8216;pregnant&#8217;,&#8217;glucose&#8217;,&#8217;mass&#8217;,&#8217;pedigree&#8217;,&#8217;age&#8217;,&#8221;diabetes&#8221;)],#\u6570\u636e\u96c6<\/p>\n<p>main = &#8220;\u7b80\u5355\u68ee\u6797\u56fe&#8221;)#\u6807\u9898<\/p>\n<p><strong>\u7ed8\u5236\u591a\u56e0\u7d20Cox\u56de\u5f52\u68ee\u6797\u56fe<\/strong> <img decoding=\"async\" loading=\"lazy\" width=\"640\" height=\"466\" class=\"wp-image-25246\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-5.png?resize=640%2C466\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-5.png?w=759 759w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-5.png?resize=300%2C219 300w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/word-image-25241-5.png?resize=600%2C437 600w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/p>\n<p>\u6ce8\uff1a<\/p>\n<p># \u8bf7\u786e\u4fdd\u5c06\u8def\u5f84&#8221;inputdata.txt&#8221;\u66ff\u6362\u4e3a\u5b9e\u9645\u6570\u636e\u96c6\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u5e76\u6839\u636e\u9700\u8981\u8c03\u6574\u6a21\u578b\u53c2\u6570\u548c\u5176\u4ed6\u914d\u7f6e\u3002<\/p>\n<p># \u5728\u7ed8\u5236AUC\u66f2\u7ebf\u4e4b\u524d\uff0c\u786e\u4fdd\u60a8\u7684\u6a21\u578b\u8f93\u51fa\u7684\u662f\u9884\u6d4b\u7684\u6982\u7387\u503c\uff0c\u800c\u4e0d\u662f\u7c7b\u522b\u6807\u7b7e\u3002<\/p>\n<p>\u5389\u5bb3\u5427\uff0c\u6211\u4eec\u8fd9\u4e48\u5feb\u5c31\u5b8c\u6210\u4e86\u4e00\u4e2a\u7528lasso\u7b97\u6cd5\u5efa\u7acb\u6a21\u578b\u5e76\u8bc4\u4f30\u3002\u5982\u679c\u7279\u5f81\u6bd4\u8f83\u591a\uff0c\u5c24\u5176\u662f\u4ee5\u57fa\u56e0\u4e3a\u7279\u5f81\u65f6lasso\u7b97\u6cd5\u80fd\u4ece\u6210\u5343\u4e0a\u4e07\u7684\u57fa\u56e0\u4e2d\u6311\u9009\u51fa\u5bf9\u9884\u6d4b\u8868\u73b0\u5f71\u54cd\u8f83\u5927\u7684\u90a3\u4e00\u90e8\u5206\uff0c\u751a\u81f3\u662f\u51e0\u4e2a\u57fa\u56e0\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u7279\u5f81\u503c\u8f83\u591a\uff0c\u53ef\u80fd\u9700\u8981\u5927\u91cf\u7684\u5185\u5b58\uff0c\u8017\u65f6\u6bd4\u8f83\u957f\u3002\u56e0\u6b64\uff0c\u5c0f\u679c\u5efa\u8bae\u4f7f\u7528\u6211\u4eec\u7684\u4e91\u751f\u4fe1\u5e73\u53f0\uff0c\u6211\u4eec\u7684\u5e73\u53f0\u63d0\u4f9b\u5f3a\u5927\u7684\u8ba1\u7b97\u8d44\u6e90\u548c\u6df1\u5ea6\u5b66\u4e60\u5de5\u5177\u3002\u60a8\u53ef\u4ee5\u8bbf\u95ee\u6211\u4eec\u7684\u4e91\u751f\u4fe1\u5e73\u53f0\uff0c\u94fe\u63a5\u4e3a\uff1ahttp:\/\/www.biocloudservice.com\/home.html\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lasso\uff08Least Absolute Shrinkage and Selection Operator\uff09\u7b97 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":""},"categories":[1],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/25241"}],"collection":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25241"}],"version-history":[{"count":1,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/25241\/revisions"}],"predecessor-version":[{"id":25247,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/25241\/revisions\/25247"}],"wp:attachment":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25241"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}