---
title: "Reproducing Source Papers with MultiFrailty"
author: "Shikhar Tyagi, Arvind Pandey, Bhupendra Singh, Vrijesh Tripathi"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Reproducing Source Papers with MultiFrailty}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(MultiFrailty)
library(survival)
```

# Overview

This vignette illustrates fitting the shared frailty models proposed in:

1. **Pandey, Hanagal, & Tyagi (2022)**: *Shared Frailty Models Based on Cancer Data*, IJSRE.
2. **Pandey & Tyagi (2021)**: *Comparison of Multiplicative Frailty Models Under Weibull Baseline Distribution*, Lobachevskii J. Math.

# Example Fit on Lung Cancer Data

```{r, eval = TRUE}
library(MultiFrailty)
library(survival)

# Prepare lung cancer dataset
data(lung, package = "survival")
lung_clean <- na.omit(lung[, c("time", "status", "age", "sex")])
lung_clean$status <- ifelse(lung_clean$status == 2, 1, 0)
lung_clean$sex <- ifelse(lung_clean$sex == 1, 0, 1)

# Fit Inverse Gaussian (IG) frailty model with Weibull baseline
fit_ig <- multifrailty(Surv(time, status) ~ age + sex, data = lung_clean,
                       baseline = "weibull", frailty = "ig")
summary(fit_ig)

# Fit Generalized Lindley Type 1 (GL1) frailty model
fit_gl1 <- multifrailty(Surv(time, status) ~ age + sex, data = lung_clean,
                        baseline = "weibull", frailty = "gl1")
summary(fit_gl1)

# Compare candidate models
comp <- compare_models(fit_ig, fit_gl1)
print(comp)
```
