jamesbang

V1

2023/05/02阅读：18主题：雁栖湖

# 🤣 Nomogram | 盘点一下绘制列线图的几个R包！~（二）

## 2用到的包

``rm(list = ls())library(tidyverse)library(survival)library(rms)library(nomogramEx)library(hdnom)library(survey)library(SvyNom)``

## 3nomogramEx包

`nomogramEx`包，可以从一个`nomogram`中提取多项式方程，用来计算每个变量的点数和总点数对应的生存概率。😎

### 3.1 生成示例数据

``n <-1000age <- rnorm(n,50,10)sex <- factor(sample(c('female','male'),n,T))sex <- as.numeric(sex)ddist <- datadist(age,sex)options(datadist='ddist')cens <- 15*runif(n)time <- -log(runif(n))/0.02*exp(.04*(age-50)+.8*(sex=='Female'))death <- ifelse(time <= cens,1,0)time <- pmin(time,cens)units(time)="month"``

### 3.2 构建模型

``f <- cph(formula(Surv(time,death)~sex+age),x=T,y=T,surv=T,time.inc=3)surv <- Survival(f)``

### 3.3 绘制列线图

``nomo <- nomogram(f, fun=list(function(x) surv(3,x),function(x) surv(6,x)),                 lp=T,                  funlabel=c("3-Month Survival Prob","6-Month Survival Prob"))plot(nomo)``

### 3.4 提取公式

``nomogramEx(nomo=nomo,np=2,digit=9) ``

## 4hdnom包

`hdnom包`功能非常强大，我们以后再介绍它的具体用法吧，今天就只介绍一下绘制`列先图`的函数咯。😎.

### 4.1 示例数据

``data("smart")x <- as.matrix(smart[, -c(1, 2)])time <- smart\$TEVENTevent <- smart\$EVENTy <- survival::Surv(time, event)DT::datatable(smart)``

### 4.2 建模

``suppressMessages(library("doParallel"))registerDoParallel(detectCores())fit <- fit_aenet(x, y, nfolds = 10, rule = "lambda.1se", seed = c(5, 7), parallel = T)names(fit)``

### 4.3 可视化

``model <- fit\$modelalpha <- fit\$alphalambda <- fit\$lambdaadapen <- fit\$pen_factornom <- as_nomogram(  fit, x, time, event,  pred.at = 365 * 2,  funlabel = "2-Year Overall Survival Probability")plot(nom)``

## 5SvyNomv包

### 5.1 示例数据

``set.seed(1234)data("noNA", package = "SvyNom")dstr2 <- svydesign(id = ~1, strata = ~group, prob = ~inv_weight,   fpc = ~ssize, data = noNA)dd <- datadist(noNA)options(datadist = "dd")ss3 <- c(0.05, 0.2, 0.4, 0.6, 0.7, 0.8, 0.9, 0.95, 0.99)``

### 5.2 可视化

``mynom <- svycox.nomogram(.design = dstr2, .model =   Surv(survival, surv_cens) ~ ECOG + liver_only + Alb + Hb + Age +   Differentiation + Gt_1_m1site + lymph_only, .data = noNA, pred.at = 24,   fun.lab = "Prob of 2 Yr OS")plot(mynom\$nomog)``

📍 往期精彩

##### jamesbang
V1

wx🔍: Grassssss 卷起来了