Skip to content

Commit

Permalink
Documentation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Jan 24, 2019
1 parent c519a8e commit 9547b10
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 33 deletions.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Survival = "8a913413-2070-5976-9d4c-2b364fdc2f7f"

[compat]
Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Survival, Documenter
using Survival, Documenter, StatsBase

makedocs(
modules = [Survival],
Expand Down
14 changes: 10 additions & 4 deletions docs/src/cox.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Cox Proportional Hazards Model

The [Cox proportional hazards model](https://en.wikipedia.org/wiki/Proportional_hazards_model) is a semiparametric regression used to fit survival models without knowing the distribution. It is based on the assumption that different covariates affect the hazard function multiplicatively:
The [Cox proportional hazards model](https://en.wikipedia.org/wiki/Proportional_hazards_model)
is a semiparametric regression model used to fit survival models without knowing the
distribution. It is based on the assumption that covariates affect the hazard function
multiplicatively. That is,

```math
\lambda(t|X_i) = \lambda_0(t)\exp(X_i\cdot\beta)
\lambda(t | X_i) = \lambda_0(t) \exp(X_i \cdot \beta)
```

where ``\lambda(t|X_i)`` is the estimated hazard for sample ``i``, ``\lambda_0`` is the baseline hazard, ``X_i`` the vector of covariates for sample ``i`` and ``\beta`` are the coefficients of the regression.
where ``\lambda(t|X_i)`` is the estimated hazard for sample ``i``, ``\lambda_0`` is the
baseline hazard, ``X_i`` is the vector of covariates for sample ``i``, and ``\beta`` is
the vector of coefficients in the model.

## API

Expand All @@ -16,4 +21,5 @@ StatsBase.fit(::Type{CoxModel}, M::AbstractMatrix, y::AbstractVector; kwargs...)

## References

* Cox, D. R. (1972). *Regression models and life tables (with discussion)*. Journal of the Royal Statistical Society, Series B, 34:187–220.
* Cox, D. R. (1972). *Regression models and life tables (with discussion)*.
Journal of the Royal Statistical Society, Series B, 34:187–220.
13 changes: 7 additions & 6 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
```@meta
DocTestSetup = :(using Survival, StatsBase)
CurrentModule = Survival
```

# Survival.jl

This package provides types and methods for performing
[survival analysis](https://en.wikipedia.org/wiki/Survival_analysis) in Julia.

## Installation

The package is not yet registered in Julia's package registry, and so it must
be installed using

```julia
Pkg.clone("https://github.com/ararslan/Survival.jl.git")
```
The package is not yet registered in Julia's General package registry, and so it must
be installed using `Pkg.add("https://github.com/ararslan/Survival.jl")`.

## Contents

Expand Down
6 changes: 2 additions & 4 deletions docs/src/km.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ using Greenwood's formula:

```@docs
Survival.KaplanMeier
StatsBase.fit(::Type{S},
times::AbstractVector{T},
status::AbstractVector{<:Integer}) where {S<:NonparametricEstimator, T}
StatsBase.confint(km::KaplanMeier, α::Float64=0.05)
StatsBase.fit(::Type{KaplanMeier}, ::Any, ::Any)
StatsBase.confint(::KaplanMeier, ::Float64)
```

## References
Expand Down
12 changes: 5 additions & 7 deletions docs/src/na.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ where ``d_i`` is the number of observed events at time ``t_i`` and ``n_i`` is th
number of subjects at risk for the event just before time ``t_i``.

The pointwise standard error of the log of the survivor function can be computed
directly as the standard error or a Bernoulli random variable with `d_i` successes
from `n_i` samples:
directly as the standard error or a Bernoulli random variable with ``d_i`` successes
from ``n_i`` samples:

```math
\text{SE}(\hat{H}(t)) = \sqrt{\sum_{i: t_i < t} \frac{d_i(n_i-d_i)}{n_i^3}}
Expand All @@ -24,13 +24,11 @@ from `n_i` samples:

```@docs
Survival.NelsonAalen
StatsBase.fit(::Type{S},
times::AbstractVector{T},
status::AbstractVector{<:Integer}) where {S<:NonparametricEstimator, T}
StatsBase.confint(na::NelsonAalen, α::Float64=0.05)
StatsBase.fit(::Type{NelsonAalen}, ::Any, ::Any)
StatsBase.confint(::NelsonAalen, ::Float64)
```

## References

* Nelson, W. (1969). *Hazard plotting for incomplete failure data*.
Journal of Quality Technology 1, 27–52.
Journal of Quality Technology 1, 27–52.
12 changes: 2 additions & 10 deletions src/estimator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,9 @@ function _estimator(::Type{S}, tte::AbstractVector{T}, status::BitVector) where
return S{T}(times, nevents, ncensor, natrisk, estimator, stderr)
end

"""
fit(::Type{S}, times, status) where S<:NonparametricEstimator
Given a vector of times to events and a corresponding vector of indicators that
dictate whether each time is an observed event or is right censored, compute the
model of type `S`. Return an object of type `S`: [`KaplanMeier`](@ref) and
[`NelsonAalen`](@ref) are supported so far.
"""
function StatsBase.fit(::Type{S},
times::AbstractVector{T},
status::AbstractVector{<:Integer}) where {S<:NonparametricEstimator, T}
status::AbstractVector{<:Integer}) where {S<:NonparametricEstimator,T}
nobs = length(times)
if length(status) != nobs
throw(DimensionMismatch("there must be as many event statuses as times"))
Expand All @@ -88,4 +80,4 @@ function StatsBase.fit(::Type{S}, ets::AbstractVector{<:EventTime}) where S<:Non
# make this method the One True Method™ so that folks are encouraged to
# use EventTimes instead of raw values.
return fit(S, map(t->t.time, x), BitVector(map(t->t.status, x)))
end
end
9 changes: 9 additions & 0 deletions src/kaplanmeier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ function StatsBase.confint(km::KaplanMeier, α::Float64=0.05)
exp(-exp(l - a)), exp(-exp(l + a))
end
end

"""
fit(KaplanMeier, times, status) -> KaplanMeier
Given a vector of times to events and a corresponding vector of indicators that
dictate whether each time is an observed event or is right censored, compute the
Kaplan-Meier estimate of the survivor function.
"""
StatsBase.fit(::Type{KaplanMeier}, times, status)
11 changes: 10 additions & 1 deletion src/nelsonaalen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@ function StatsBase.confint(na::NelsonAalen, α::Float64=0.05)
return map(na.chaz, na.stderr) do srv, se
srv - q * se, srv + q * se
end
end
end

"""
fit(NelsonAalen, times, status) -> NelsonAalen
Given a vector of times to events and a corresponding vector of indicators that
dictate whether each time is an observed event or is right censored, compute the
Nelson-Aalen estimate of the cumulative hazard rate function.
"""
StatsBase.fit(::Type{NelsonAalen}, times, status)

0 comments on commit 9547b10

Please sign in to comment.