README

The duration package supports fitting statistical models for event time data (also known as "survival analysis") in Go. Currently, Cox proportional hazards regression, Kaplan-Meier estimates of the marginal survival function, and estimation of the cumulative incidence function are supported.

The Godoc package documentation is here.

See the examples directory for illustrations of how the package can be used.

Documentation

Overview

Package duration supports various methods for statistical analysis of duration data (survival analysis).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Concordance

type Concordance struct {
	// contains filtered or unexported fields
}

Concordance calculates the survival concordance of Uno et al. (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3079915).

func NewConcordance

func NewConcordance(time, status, score []float64) *Concordance

NewConcordance creates a new Concordance value with the given parameters.

func (*Concordance) Concordance

func (c *Concordance) Concordance(trunc float64) float64

Concordance returns the concordance statistic, using the given truncation parameter.

func (*Concordance) Done

func (c *Concordance) Done() *Concordance

Done signals that the Concordance value has been built and now can be fit.

func (*Concordance) NumPair

func (c *Concordance) NumPair(npair int) *Concordance

NumPair sets the number of pairs of observations sampled at random to estimate the concordance.

type CumincRight

type CumincRight struct {

	// Times at which events occur, sorted.
	Times []float64

	// The number of occurrences of events of each type at each
	// time in Times.
	Events [][]float64

	// Number of events of any type at each time in Times
	EventsAll []float64

	// Risk set size at each time in times
	NRisk []float64

	// The estimated all-cause survival function
	ProbsAll []float64

	// The cause specific cumulative incidence rates.  Probs[k]
	// contains the rates for the events with Status==k+1
	// (Status==0 indicates censoring, cumulative incidences are
	// not estimated for the censored subjects).
	Probs [][]float64

	// The standard errors of the values in Probs
	ProbsSE [][]float64
	// contains filtered or unexported fields
}

CumincRight estimates the cumulative incidence functions for duration data with competing risks.

func NewCumincRight

func NewCumincRight(data dstream.Dstream, timevar, statusvar string) *CumincRight

NewCumincRight creates a CumincRight value that can be used to estimate the cumulative incidence function from the given data.

func (*CumincRight) Done

func (ci *CumincRight) Done() *CumincRight

Done completes construction and computes all results.

func (*CumincRight) Entry

func (ci *CumincRight) Entry(entryvar string) *CumincRight

Entry specifies a variable that provides entry times.

func (*CumincRight) Weights

func (ci *CumincRight) Weights(weightvar string) *CumincRight

Weights specifies a variable that povides case weights.

type PHParameter

type PHParameter struct {
	// contains filtered or unexported fields
}

PHParameter contains a parameter value for a proportional hazards regression model.

func (*PHParameter) Clone

func (p *PHParameter) Clone() statmodel.Parameter

Clone returns a deep copy of the parameter value.

func (*PHParameter) GetCoeff

func (p *PHParameter) GetCoeff() []float64

GetCoeff returns the array of model coefficients from a parameter value.

func (*PHParameter) SetCoeff

func (p *PHParameter) SetCoeff(x []float64)

SetCoeff sets the array of model coefficients for a parameter value.

type PHReg

type PHReg struct {
	// contains filtered or unexported fields
}

PHReg describes a proportional hazards regression model for right censored data.

func NewPHReg

func NewPHReg(data statmodel.Dataset, time, status string, predictors []string, config *PHRegConfig) (*PHReg, error)

NewPHReg returns a PHReg value that can be used to fit a proportional hazards regression model.

func (*PHReg) BaselineCumHaz

func (ph *PHReg) BaselineCumHaz(stratum int, params []float64) ([]float64, []float64)

BaselineCumHaz returns the Nelson-Aalen estimator of the baseline cumulative hazard function for the given stratum.

func (*PHReg) Dataset

func (ph *PHReg) Dataset() [][]statmodel.Dtype

Dataset returns the data columns that are used to fit the model.

func (*PHReg) Fit

func (ph *PHReg) Fit() (*PHResults, error)

Fit fits the model to the data.

func (*PHReg) Focus

func (ph *PHReg) Focus(pos int, coeff []float64, offset []float64) statmodel.RegFitter

Focus returns a new PHReg instance with a single variable, which is variable j in the original model. The effects of the remaining covariates are captured through the offset.

func (*PHReg) Hessian

func (ph *PHReg) Hessian(params statmodel.Parameter, ht statmodel.HessType, hess []float64)

Hessian computes the Hessian matrix for the model evaluated at the given parameter setting. The Hessian type parameter is not used here.

func (*PHReg) LogLike

func (ph *PHReg) LogLike(param statmodel.Parameter, exact bool) float64

LogLike returns the log-likelihood at the given parameter value. The 'exact' parameter is ignored here.

func (*PHReg) NumObs

func (ph *PHReg) NumObs() int

NumObs returns the number of observations in the data set.

func (*PHReg) NumParams

func (ph *PHReg) NumParams() int

NumParams returns the number of model parameters (regression coefficients).

func (*PHReg) Score

func (ph *PHReg) Score(params statmodel.Parameter, score []float64)

Score computes the score vector for the proportional hazards regression model at the given parameter setting.

func (*PHReg) Xpos

func (ph *PHReg) Xpos() []int

Xpos return the positions of the covariates in the model's dstream.

type PHRegConfig

type PHRegConfig struct {

	// A logger to which logging information is wreitten
	Log *log.Logger

	// Start contains starting values for the regression parameter estimates
	Start []float64

	// WeightVar is the name of the variable for frequency-weighting the cases, if an empty
	// string, all weights are equal to 1.
	WeightVar string

	// OffsetVar is the name of a variable that defines an offset.
	OffsetVar string

	// StrataVar is the name of a variable that defines strata.
	StrataVar string

	// EntryVar is the name of a variable that defines entry (left truncation) times.
	EntryVar string

	L1Penalty map[string]float64
	L2Penalty map[string]float64

	// OptMethod is the Gonum optimization used to fit the model.
	OptMethod optimize.Method

	// OptSettings configures the Gonum optimization routine.
	OptSettings *optimize.Settings
}

PHRegConfig defines configuration parameters for a proportional hazards regression..

func DefaultPHRegConfig

func DefaultPHRegConfig() *PHRegConfig

DefaultPHRegConfig returns a default configuration struct for a proportional hazards regression.

type PHResults

type PHResults struct {
	statmodel.BaseResults
}

PHResults describes the results of a proportional hazards model..

func (*PHResults) Summary

func (rslt *PHResults) Summary() *PHSummary

Summary displays a summary table of the model results.

type PHSummary

type PHSummary struct {
	// contains filtered or unexported fields
}

PHSummary summarizes a fitted proportional hazards regression model.

func (*PHSummary) String

func (phs *PHSummary) String() string

String returns a string representation of a summary table for the model.

type SurvfuncRight

type SurvfuncRight struct {
	// contains filtered or unexported fields
}

SurvfuncRight uses the method of Kaplan and Meier to estimate the survival distribution based on (possibly) right censored data. The caller must set Data and TimeVar before calling the Fit method. StatusVar, WeightVar, and EntryVar are optional fields.

func NewSurvfuncRight

func NewSurvfuncRight(data dstream.Dstream, timevar, statusvar string) *SurvfuncRight

NewSurvfuncRight creates a new value for fitting a survival function.

func (*SurvfuncRight) Done

func (sf *SurvfuncRight) Done() *SurvfuncRight

Done indicates that the survival function has been configured and can now be fit.

func (*SurvfuncRight) Entry

func (sf *SurvfuncRight) Entry(entry string) *SurvfuncRight

Entry specifies the name of an entry time variable.

func (*SurvfuncRight) NumRisk

func (sf *SurvfuncRight) NumRisk() []float64

NumRisk returns the number of people at risk at each time point where the survival function changes.

func (*SurvfuncRight) SurvProb

func (sf *SurvfuncRight) SurvProb() []float64

SurvProb returns the estimated survival probabilities at the points where the survival function changes.

func (*SurvfuncRight) SurvProbSE

func (sf *SurvfuncRight) SurvProbSE() []float64

SurvProbSE returns the standard errors of the estimated survival probabilities at the points where the survival function changes.

func (*SurvfuncRight) Time

func (sf *SurvfuncRight) Time() []float64

Time returns the times at which the survival function changes.

func (*SurvfuncRight) Weight

func (sf *SurvfuncRight) Weight(weight string) *SurvfuncRight

Weight specifies the name of a case weight variable.

type SurvfuncRightPlotter

type SurvfuncRightPlotter struct {
	// contains filtered or unexported fields
}

SurvfuncRightPlotter is used to plot a survival function.

func NewSurvfuncRightPlotter

func NewSurvfuncRightPlotter() *SurvfuncRightPlotter

NewSurvfuncRightPlotter returns a default SurvfuncRightPlotter.

func (*SurvfuncRightPlotter) Add

Add plots a given survival function to the plot.

func (*SurvfuncRightPlotter) GetPlotStruct

func (sp *SurvfuncRightPlotter) GetPlotStruct() *plot.Plot

GetPlotStruct returns the plotting structure for this plot.

func (*SurvfuncRightPlotter) Height

Height sets the height of the survival function plot.

func (*SurvfuncRightPlotter) Plot

Plot constructs the plot.

func (*SurvfuncRightPlotter) Save

func (sp *SurvfuncRightPlotter) Save(fname string)

Save writes the plot to the given file.

func (*SurvfuncRightPlotter) Width

Width sets the width of the survival function plot.

Directories

Path Synopsis