On s’intéresse à la durée de survie des patients à partir du moment du diagnostic ou du début du traitement ARV.
Variables possibles :
\(time\) : temps jusqu’à l’événement (décès ou censure)
\(status\) : événement observé (1 = décès, 0 = censuré)
Covariables : âge, sexe, CD4 au diagnostic, traitement ARV, comorbidités, etc.
Méthodes :
Kaplan-Meier : courbes de survie par groupe (ex. sexe, stade CDC)
Cox proportional hazards : évalue l’effet des covariables sur le risque de décès
Modèles paramétriques : si la distribution du temps de survie est connue ou supposée (Weibull, Exponentielle)
library(survival)
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
set.seed(123)
# --- 1. Simulation de donnees ---
n_patients <- 300
age <- round(rnorm(n_patients, 40, 10))
CD4 <- round(rnorm(n_patients, 350, 150))
CD4[CD4 < 1] <- 1
sexe <- sample(c("Homme","Femme"), n_patients, replace=TRUE)
ARV <- sample(c("Oui","Non"), n_patients, replace=TRUE, prob=c(0.7,0.3))
baseline_hazard <- 0.05
rate <- baseline_hazard * ifelse(ARV=="Oui",0.6,1.2) * (CD4/350)^(-0.5)
time <- rexp(n_patients, rate=rate)
status <- rbinom(n_patients, 1, 0.8)
data <- data.frame(time=time, status=status, ARV=ARV, CD4=CD4, age=age, sexe=sexe)
head(data)
## time status ARV CD4 age sexe
## 1 22.614185 1 Non 243 34 Homme
## 2 9.486542 1 Non 237 38 Femme
## 3 46.738263 1 Oui 209 56 Femme
## 4 83.264102 1 Oui 192 41 Homme
## 5 12.124507 1 Oui 284 41 Homme
## 6 1.316155 0 Oui 400 57 Homme
# --- 2. Kaplan-Meier avec base R ---
km_fit <- survfit(Surv(time, status) ~ ARV, data=data)
# Courbe Kaplan-Meier
plot(km_fit, col=c("green","red"), lwd=2, xlab="Temps (mois)", ylab="Probabilite de survie",
main="Kaplan-Meier - Patients VIH")
legend("topright", legend=c("ARV Oui","ARV Non"), col=c("green","red"), lwd=2)
# --- 3. Cox multivarie ---
cox_fit <- coxph(Surv(time, status) ~ ARV + CD4 + age + sexe, data=data)
summary(cox_fit)
## Call:
## coxph(formula = Surv(time, status) ~ ARV + CD4 + age + sexe,
## data = data)
##
## n= 300, number of events= 247
##
## coef exp(coef) se(coef) z Pr(>|z|)
## ARVOui -0.7881762 0.4546733 0.1446909 -5.447 5.11e-08 ***
## CD4 -0.0018457 0.9981560 0.0004914 -3.756 0.000173 ***
## age -0.0105443 0.9895111 0.0069982 -1.507 0.131886
## sexeHomme -0.0916841 0.9123933 0.1294138 -0.708 0.478662
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## ARVOui 0.4547 2.199 0.3424 0.6038
## CD4 0.9982 1.002 0.9972 0.9991
## age 0.9895 1.011 0.9760 1.0032
## sexeHomme 0.9124 1.096 0.7080 1.1758
##
## Concordance= 0.617 (se = 0.018 )
## Likelihood ratio test= 41.49 on 4 df, p=2e-08
## Wald test = 42.8 on 4 df, p=1e-08
## Score (logrank) test = 44.45 on 4 df, p=5e-09
# --- 4. Visualisation Hazard Ratios ---
hr <- exp(coef(cox_fit))
hr_conf <- exp(confint(cox_fit))
hr_df <- data.frame(
covariables = names(hr),
HR = hr,
CI_lower = hr_conf[,1],
CI_upper = hr_conf[,2]
)
ggplot(hr_df, aes(x=covariables, y=HR)) +
geom_point(size=3) +
geom_errorbar(aes(ymin=CI_lower, ymax=CI_upper), width=0.2) +
geom_hline(yintercept=1, linetype="dashed", color="red") +
labs(title="Hazard Ratios - Patients VIH", y="Hazard Ratio", x="Covariables") +
theme_minimal()