Inverse probability of treatment weighting (IPTW) and crr() or FGR() in R

36 Views Asked by At

I've been looking into how to weight a competing risk regression after IPTW but I'm afraid it doesn't support it. Any ideas? Now I'm looking in STATA...

library(riskRegression)

set.seed(123) # Para reproducibilidad

# Simulando datos
n <- 50
datos <- data.frame(
  ID = 1:n,
  tratamiento = sample(0:1, n, replace = TRUE),
  tiempo = rexp(n, rate = 0.1),
  evento = sample(0:2, n, replace = TRUE, prob = c(0.5, 0.3, 0.2)),
  covar1 = rnorm(n),
  covar2 = runif(n)
)

head(datos)

# Calculando la probabilidad de recibir tratamiento
ps_model <- glm(tratamiento ~ covar1 + covar2, family = binomial(), data = datos)

# Calculando los pesos IPTW
datos$pesos_iptw <- ifelse(datos$tratamiento == 1,
                           1/predict(ps_model, type = "response"),
                           1/(1 - predict(ps_model, type = "response")))

#FRG
############################################################
FGR(Hist(tiempo,evento)~tratamiento,data=datos, weights = datos$pesos_iptw)

0

There are 0 best solutions below