五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

限制性立方樣條 RCS

2022-12-19 19:13 作者:請(qǐng)叫我小雞崽  | 我要投稿

限制性立方樣條 RCS

# *?1.生成數(shù)據(jù) ------------------------------------------------------------

## 加載所需要的包

library(ggplot2)

#install.packages('rms')

library(rms)??



## 生成數(shù)據(jù)

n <- 1000

set.seed(731)

age <- 50 + 12*rnorm(n)

label(age) <- "age"

sex <- factor(sample(c("Male","Female"),n, rep=T,prob = c(6,4)))

cens <- 15*runif(n)

h <- 0.02*exp(0.04*(age-50) + 0.8*(sex == "Female"))

time <- -log(runif(n))/h

label(time) <- "Follow-up Time"

death <- ifelse(time <= cens,1,0)

time <- pmin(time,cens)

units(time) <- "Year"

data <- data.frame(age,sex,time, death)


head(data )


# * 2.做回歸、擬合曲線 ------------------------------------------------------------

# 對(duì)數(shù)據(jù)進(jìn)行打包,整理

dd <- datadist(data) #為后續(xù)程序設(shè)定數(shù)據(jù)環(huán)境

options(datadist='dd') #為后續(xù)程序設(shè)定數(shù)據(jù)環(huán)境

# 擬合模型


fit<- cph(Surv(time,death) ~ rcs(age,4) + sex,data=data)?# 節(jié)點(diǎn)數(shù)設(shè)為4

# 非線性檢驗(yàn)

# P<0.05為存在非線性關(guān)系

anova(fit)


# 查看HR預(yù)測(cè)表

# 看一下預(yù)測(cè)的HR所對(duì)因的age

HR<-Predict(fit, age,fun=exp,ref.zero = TRUE)

head(HR)


# * 3.繪圖 ------------------------------------------------------------

## 繪圖

### 無(wú)分組

ggplot()+

?geom_line(data=HR, aes(age,yhat),

??????linetype="solid",size=1,alpha = 0.7,colour="#0070b9")+

?geom_ribbon(data=HR,?

???????aes(age,ymin = lower, ymax = upper),

???????alpha = 0.1,fill="#0070b9")+

?theme_classic()+

?geom_hline(yintercept=1, linetype=2,size=1)+

?geom_vline(xintercept=48.89330,size=1,color = '#d40e8c')+ #查表HR=1對(duì)應(yīng)的age

?labs(title = "Stroke Risk", x="Age", y="HR (95%CI)")



### 性別分組

HR1 <- Predict(fit, age, sex=c('Male','Female'),

????????fun=exp,type="predictions",

????????ref.zero=TRUE,conf.int = 0.95,digits=2)

HR1

ggplot()+

?geom_line(data=HR1, aes(age,yhat, color = sex),

??????linetype="solid",size=1,alpha = 0.7)+

?geom_ribbon(data=HR1,?

???????aes(age,ymin = lower, ymax = upper,fill = sex),

???????alpha = 0.1)+

?scale_color_manual(values = c('#0070b9','#d40e8c'))+

?scale_fill_manual(values = c('#0070b9','#d40e8c'))+

?theme_classic()+

?geom_hline(yintercept=1, linetype=2,size=1)+

?labs(title = "RCS", x="Age", y="HR (95%CI)")


# * 4.線性回歸或邏輯回歸 ------------------------------------------------------------

### 線性回歸

ggplot(data=data, aes(x = age, y = time)) +?

?geom_point() +

?stat_smooth(method =?lm, formula =?y ~ rcs(x,4))

### 邏輯回歸

fit3 <- lrm(death ~rcs(age,4)+sex, data =?data)

OR <- Predict(fit3,age, fun=exp, ref.zero = T)

ggplot(OR)

限制性立方樣條 RCS的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
江永县| 温宿县| 庐江县| 浮梁县| 莱阳市| 泌阳县| 锡林浩特市| 白山市| 开原市| 湖州市| 旌德县| 吉林市| 阿克| 武功县| 临猗县| 金山区| 永济市| 凭祥市| 丰城市| 涞水县| 安西县| 大邑县| 承德县| 宣汉县| 会昌县| 吉木萨尔县| 广饶县| 岳池县| 裕民县| 焦作市| 四平市| 玉山县| 唐山市| 竹溪县| 长寿区| 呼伦贝尔市| 乐亭县| 江陵县| 桂东县| 翁源县| 清原|