From 9547b103414230a00d083c67069211d56b572149 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Wed, 23 Jan 2019 21:14:13 -0800 Subject: [PATCH] Documentation fixes --- docs/Project.toml | 1 + docs/make.jl | 2 +- docs/src/cox.md | 14 ++++++++++---- docs/src/index.md | 13 +++++++------ docs/src/km.md | 6 ++---- docs/src/na.md | 12 +++++------- src/estimator.jl | 12 ++---------- src/kaplanmeier.jl | 9 +++++++++ src/nelsonaalen.jl | 11 ++++++++++- 9 files changed, 47 insertions(+), 33 deletions(-) diff --git a/docs/Project.toml b/docs/Project.toml index a39a696..ed41b9f 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,5 +1,6 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" Survival = "8a913413-2070-5976-9d4c-2b364fdc2f7f" [compat] diff --git a/docs/make.jl b/docs/make.jl index b114d68..3e90ca0 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,4 +1,4 @@ -using Survival, Documenter +using Survival, Documenter, StatsBase makedocs( modules = [Survival], diff --git a/docs/src/cox.md b/docs/src/cox.md index 6a659d9..444d968 100644 --- a/docs/src/cox.md +++ b/docs/src/cox.md @@ -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 @@ -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. diff --git a/docs/src/index.md b/docs/src/index.md index 5510b3b..b6a6ed2 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -1,3 +1,8 @@ +```@meta +DocTestSetup = :(using Survival, StatsBase) +CurrentModule = Survival +``` + # Survival.jl This package provides types and methods for performing @@ -5,12 +10,8 @@ This package provides types and methods for performing ## 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 diff --git a/docs/src/km.md b/docs/src/km.md index 3fbbaa4..01f31dc 100644 --- a/docs/src/km.md +++ b/docs/src/km.md @@ -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 diff --git a/docs/src/na.md b/docs/src/na.md index e0de83d..f0cc2d9 100644 --- a/docs/src/na.md +++ b/docs/src/na.md @@ -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}} @@ -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. \ No newline at end of file + Journal of Quality Technology 1, 27–52. diff --git a/src/estimator.jl b/src/estimator.jl index 868a9b1..101c8fe 100644 --- a/src/estimator.jl +++ b/src/estimator.jl @@ -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")) @@ -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 \ No newline at end of file +end diff --git a/src/kaplanmeier.jl b/src/kaplanmeier.jl index 5e6b713..932e7b3 100644 --- a/src/kaplanmeier.jl +++ b/src/kaplanmeier.jl @@ -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) diff --git a/src/nelsonaalen.jl b/src/nelsonaalen.jl index 0e8920d..b4223d1 100644 --- a/src/nelsonaalen.jl +++ b/src/nelsonaalen.jl @@ -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 \ No newline at end of file +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)