---
title: "Fast Regression for the Accelerated Failure Time (AFT) Model"
author: "Yijian Huang (yhuang5@emory.edu)"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Fast Regression for the Accelerated Failure Time (AFT) Model}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

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

Package `fastAFT` performs fast censored linear regression for the accelerated
failure time (AFT) model of Huang (2013).

## Installation
`fastAFT` is available on CRAN:
```{r install, eval=FALSE, message=FALSE, warning=FALSE}
install.packages("fastAFT")
```

## Fast censored linear regression
This procedure is illustrated with the Mayo primary biliary cholangitis dataset
as given in package `survival`.
```{r faft, eval=TRUE, message=FALSE, warning=FALSE}
## Mayo PBC data
library(survival)
pbc_analy <- as.matrix(na.omit(pbc[,c("time","status","age","edema","bili","albumin","protime")]))
# log transformation for time, bili, albumin, and protime
pbc_analy[,c(1,5:7)] <- log(pbc_analy[,c(1,5:7)])
colnames(pbc_analy)[c(1,5:7)] <- paste("log",colnames(pbc_analy)[c(1,5:7)])
# convert status to censoring indicator
pbc_analy[,2] <- pbc_analy[,2]>1

## Fast censored linear regression
# Gehan weight
library(fastAFT)
fit.g <- faft(pbc_analy[,1],pbc_analy[,2],pbc_analy[,-c(1,2)],weight="Gehan")
fit.g
# logrank weight
fit.l <- faft(pbc_analy[,1],pbc_analy[,2],pbc_analy[,-c(1,2)],weight="logrank")
fit.l
```

## References
Huang, Y. (2013) Fast censored linear regression. _Scandinavian Journal of Statistics_ 40, 789--806.