Title: | Bayesian Spatial Survival Analysis with Parametric Proportional Hazards Models |
---|---|
Description: | Bayesian inference for parametric proportional hazards spatial survival models; flexible spatial survival models. See Benjamin M. Taylor, Barry S. Rowlingson (2017) <doi:10.18637/jss.v077.i04>. |
Authors: | Benjamin M. Taylor and Barry S. Rowlingson Additional contributions Ziyu Zheng |
Maintainer: | Benjamin M. Taylor <[email protected]> |
License: | GPL-3 |
Version: | 2.0-1 |
Built: | 2025-02-20 05:16:16 UTC |
Source: | https://github.com/cran/spatsurv |
An R package for spatially correlated parametric proportional hazards survial analysis.
spatsurv
spatsurv
An object of class logical
of length 1.
Package: | spatsurv |
Type: | Package |
Title: | Bayesian Spatial Survival Analysis with Parametric Proportional Hazards Models |
Version: | 2.0-1 |
Date: | 2023-10-18 |
Author: | Benjamin M. Taylor and Barry S. Rowlingson Additional contributions Ziyu Zheng |
Maintainer: | Benjamin M. Taylor <[email protected]> |
Description: | Bayesian inference for parametric proportional hazards spatial survival models; flexible spatial survival models. See Benjamin M. Taylor, Barry S. Rowlingson (2017) <doi:10.18637/jss.v077.i04>. |
License: | GPL-3 |
Imports: | survival, sp, spatstat.explore, spatstat.geom, spatstat.random, raster, iterators, fields, Matrix, stringr, sf, RColorBrewer, methods, lubridate |
Suggests: | rgl |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.3 |
NeedsCompilation: | no |
Packaged: | 2023-10-19 07:47:32 UTC; ben |
Depends: | R (>= 2.10) |
Date/Publication: | 2023-10-19 08:20:02 UTC |
Config/pak/sysreqs: | libgdal-dev gdal-bin libgeos-dev libicu-dev libssl-dev libproj-dev libsqlite3-dev libudunits2-dev |
Repository: | https://bentaylor1.r-universe.dev |
RemoteUrl: | https://github.com/cran/spatsurv |
RemoteRef: | HEAD |
RemoteSha: | 70dda73bf5917d704e869964c8280a02ccbf934f |
Index of help topics:
.onAttach .onAttach function B B function Bspline.construct Bspline.construct function BsplineHaz BsplineHaz function CSplot CSplot function Et_PP Et_PP function EvalCov EvalCov function ExponentialCovFct ExponentialCovFct function FFTgrid FFTgrid function GammaFromY_SPDE GammaFromY_SPDE function GammafromY GammafromY function Independent Independent function MCE MCE function NonSpatialLogLikelihood_or_gradient NonSpatialLogLikelihood_or_gradient function PsplineHaz PsplineHaz function QuadApprox QuadApprox function SPDE SPDE function SPDEprec SPDEprec function SpikedExponentialCovFct SpikedExponentialCovFct function Summarise Summarise function TwoWayHazAdditive TwoWayHazAdditive function YFromGamma_SPDE YFromGamma_SPDE function YfromGamma YfromGamma function allocate allocate function alpha alpha function baseHazST baseHazST function basehazard basehazard function basehazard.basehazardspec basehazard.basehazardspec function baselinehazard baselinehazard function baselinehazard_multiWay baselinehazard_multiWay function betapriorGauss betapriorGauss function blockDiag A function to boxplotRisk boxplotRisk function checkSurvivalData checkSurvivalData function circulant circulant function circulant.matrix circulant.matrix function circulant.numeric circulant.numeric function circulantij circulantij function covmodel covmodel function cumbasehazard cumbasehazard function cumbasehazard.basehazardspec cumbasehazard.basehazardspec function cumulativeBspline.construct cumulativeBspline.construct function density_PP density_PP function densityquantile densityquantile function densityquantile.basehazardspec densityquantile.basehazardspec function densityquantile_PP densityquantile_PP function derivindepGaussianprior derivindepGaussianprior function derivindepGaussianpriorST derivindepGaussianpriorST function derivpsplineprior derivpsplineprior function distinfo distinfo function distinfo.basehazardspec distinfo.basehazardspec function estimateY estimateY function etapriorGauss etapriorGauss function exponentialHaz exponentialHaz function fixParHaz fixParHaz function fixedpars fixedpars function fixmatrix fixmatrix function frailtylag1 frailtylag1 function fs London Fire Brigade property fstimes London Fire Brigade response times to dwelling fires, 2009 gamma2risk gamma2risk function gencens gencens function getBbasis getBbasis function getGrid getGrid function getOptCellwidth getOptCellwidth function getbb getbb function getcov getcov function getgrd getgrd function getleneta getleneta function getparranges getparranges function getsurvdata getsurvdata function gompertzHaz gompertzHaz function gradbasehazard gradbasehazard function gradbasehazard.basehazardspec gradbasehazard.basehazardspec function gradcumbasehazard gradcumbasehazard function gradcumbasehazard.basehazardspec gradcumbasehazard.basehazardspec function grid2spdf grid2spdf function grid2spix grid2spix function grid2spts grid2spts function gridY gridY function gridY_polygonal gridY_polygonal function guess_t guess_t function hasNext generic hasNext method hasNext.iter hasNext.iter function hazard_PP hazard_PP function hazardexceedance hazardexceedance function hazardpars hazardpars function hessbasehazard hessbasehazard function hessbasehazard.basehazardspec hessbasehazard.basehazardspec function hesscumbasehazard hesscumbasehazard function hesscumbasehazard.basehazardspec hesscumbasehazard.basehazardspec function imputationModel imputationModel function indepGaussianprior indepGaussianprior function indepGaussianpriorST indepGaussianpriorST function inference.control inference.control function insert insert function invtransformweibull invtransformweibull function is.burnin is this a burn-in iteration? is.retain do we retain this iteration? iteration iteration number logPosterior logPosterior function logPosterior_SPDE logPosterior_SPDE function logPosterior_gridded logPosterior_gridded function logPosterior_polygonal logPosterior_polygonal function loop.mcmc loop over an iterator makehamHaz makehamHaz function maxlikparamPHsurv maxlikparamPHsurv function mcmcLoop iterator for MCMC loops mcmcPriors mcmcPriors function mcmcProgressNone null progress monitor mcmcProgressPrint printing progress monitor mcmcProgressTextBar text bar progress monitor mcmcpars mcmcpars function midpts midpts function multiWayHaz multiWayHaz function neighLocs neighLocs function neighOrder neighOrder function nextStep next step of an MCMC chain omegapriorGauss omegapriorGauss function omegapriorGaussST omegapriorGaussST function optifix optifix function plot.FFTgrid plot.FFTgrid function plotsurv plotsurv function polyadd polyadd function polymult polymult function posteriorcov posteriorcov function predict.mcmcspatsurv predict.mcmcspatsurv function print.mcmc print.mcmc function print.mcmcspatsurv print.mcmcspatsurv function print.mlspatsurv print.mlspatsurv function print.textSummary print.textSummary function priorposterior priorposterior function proposalVariance proposalVariance function proposalVariance_SPDE proposalVariance_SPDE function proposalVariance_gridded proposalVariance_gridded function proposalVariance_polygonal proposalVariance_polygonal function psplineRWprior psplineRWprior function psplineprior psplineprior function quantile.mcmcspatsurv quantile.mcmcspatsurv function quantile.mlspatsurv quantile.mlspatsurv function randompars randompars function reconstruct.bs reconstruct.bs function reconstruct.bs.coxph reconstruct.bs.coxph function reconstruct.bs.mcmcspatsurv reconstruct.bs.mcmcspatsurv function resetLoop reset iterator residuals.mcmcspatsurv resuiduals.mcmcspatsurv function rootWeibullHaz rootWeibullHaz function setTxtProgressBar2 set the progress bar setupHazard setupHazard function setupPrecMatStruct setupPrecMatStruct function showGrid showGrid function simsurv simsurv function spatialpars spatialpars function spatsurv-package spatsurv spatsurvVignette spatsurvVignette function summary.mcmc summary.mcmc function summary.mcmcspatsurv summary.mcmcspatsurv function surv3d Spatial Survival Plot in 3D survival_PP survival_PP function survspat survspat function survspatNS survspatNS function textSummary textSummary function timevaryingPL timevaryingPL function tpowHaz tpowHaz function transformweibull transformweibull function txtProgressBar2 A text progress bar with label vcov.mcmcspatsurv vcov.mcmcspatsurv function vcov.mlspatsurv vcov.mlspatsurv function weibullHaz weibullHaz function
Dependencies
The package spatsurv
depends upon some other important contributions to CRAN in order to operate; their uses here are indicated:
survival, sp, spatstat, raster, iterators, RandomFields, fields, rgl, Matrix, stringr, RColorBrewer, geostatsp.
Citation
To cite use of spatsurv
, the user may refer to the following work:
Benjamin M. Taylor and Barry S. Rowlingson (2017).
spatsurv: An R Package for Bayesian Inference with Spatial Survival Models.
Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
references
X
Benjamin Taylor, Health and Medicine, Lancaster University, Barry Rowlingson, Health and Medicine, Lancaster University
A function to print a welcome message on loading package
.onAttach(libname, pkgname)
.onAttach(libname, pkgname)
libname |
libname argument |
pkgname |
pkgname argument |
...
A function to allocate coordinates to an observation whose spatial location is known to the regional level
allocate(poly, popden, survdat, pid, sid, n = 2, wid = 2000)
allocate(poly, popden, survdat, pid, sid, n = 2, wid = 2000)
poly |
a SpatialPolygonsDataFrame, on which the survival data exist in aggregate form |
popden |
a sub-polygon raster image of population density |
survdat |
data.frame containing the survival data |
pid |
name of the variable in the survival data that gives the region identifier in poly |
sid |
the name of the variable in poly to match the region identifier in survdat to |
n |
the number of different allocations to make. e.g. if n is 2 (the default) two candidate sets of locations are available. |
wid |
The default is 2000, interpreted in metres ie 2Km. size of buffer to add to window for raster cropping purposes: this ensures that for each polygon, the cropped raster covers it completely. |
matrices x and y, both of size (number of observations in survdat x n) giving n potential candidate locations of points in the columns of x and y.
A function used in calculating the coefficients of a B-spline curve
alpha(i, j, knots, knotidx)
alpha(i, j, knots, knotidx)
i |
index i |
j |
index j |
knots |
knot vector |
knotidx |
knot index |
a vector
A recursive function used in calculating the coefficients of a B-spline curve
B(x, i, j, knots)
B(x, i, j, knots)
x |
locations at which to evaluate the B-spline |
i |
index i |
j |
index j |
knots |
a knot vector |
a vector of polynomial coefficients
Generic function for computing the baseline hazard
basehazard(obj, ...)
basehazard(obj, ...)
obj |
an object |
... |
additional arguments – currently there are none, but this is for extensibility |
method basehazard
basehazard.basehazardspec, exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to retrieve the baseline hazard function
## S3 method for class 'basehazardspec' basehazard(obj, ...)
## S3 method for class 'basehazardspec' basehazard(obj, ...)
obj |
an object of class basehazardspec |
... |
additional arguments – currently there are none, but this is for extensibility |
a function returning the baseline hazard
exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to
baseHazST( bh1 = NULL, survobj, t0, nbreaks = 5, breakmethod = "quantile", MLinits = NULL )
baseHazST( bh1 = NULL, survobj, t0, nbreaks = 5, breakmethod = "quantile", MLinits = NULL )
bh1 |
X |
survobj |
X |
t0 |
X |
nbreaks |
X |
breakmethod |
X |
MLinits |
X |
...
A function to compute quantiles of the posterior baseline hazard or cumulative baseline hazard.
baselinehazard( x, t = NULL, n = 100, probs = c(0.025, 0.5, 0.975), cumulative = FALSE, plot = TRUE, bw = FALSE, ... )
baselinehazard( x, t = NULL, n = 100, probs = c(0.025, 0.5, 0.975), cumulative = FALSE, plot = TRUE, bw = FALSE, ... )
x |
an object inheriting class mcmcspatsurv |
t |
optional vector of times at which to compute the quantiles, Defult is NULL, in which case a uniformly spaced vector of length n from 0 to the maximum time is used |
n |
the number of points at which to compute the quantiles if t is NULL |
probs |
vector of probabilities |
cumulative |
logical, whether to return the baseline hazard (default i.e. FALSE) or cumulative baseline hazard |
plot |
whether to plot the result |
bw |
Logical. Plot in black/white/greyscale? Default is to produce a colour plot. Useful for producing plots for journals that do not accept colour plots. |
... |
additional arguments to be passed to plot |
the vector of times and quantiles of the baseline or cumulative baseline hazard at those times
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
A function to
baselinehazard_multiWay( x, probs = c(0.025, 0.5, 0.975), cumulative = FALSE, plot = TRUE, joint = FALSE, xlims = NULL, ylims = NULL, ... )
baselinehazard_multiWay( x, probs = c(0.025, 0.5, 0.975), cumulative = FALSE, plot = TRUE, joint = FALSE, xlims = NULL, ylims = NULL, ... )
x |
X |
probs |
X |
cumulative |
X |
plot |
X |
joint |
X |
xlims |
X |
ylims |
X |
... |
X |
...
A function to define Gaussian priors for beta. This function simply stores a vector of means and standard deviations to be passed to the main MCMC function, survspat.
betapriorGauss(mean, sd)
betapriorGauss(mean, sd)
mean |
the prior mean, a vector of length 1 or more. 1 implies a common mean. |
sd |
the prior standard deviation, a vector of length 1 or more. 1 implies a common standard deviation. |
an object of class "betapriorGauss"
survspat, betapriorGauss, omegapriorGauss, etapriorGauss, indepGaussianprior, derivindepGaussianprior
A function to
blockDiag(matlist)
blockDiag(matlist)
matlist |
X |
...
A function to
boxplotRisk(g2r)
boxplotRisk(g2r)
g2r |
X |
...
A function to construct a B-spline basis matrix for given data and basis coefficients. Used in evaluating the baseline hazard.
Bspline.construct(x, basis)
Bspline.construct(x, basis)
x |
a vector, the data |
basis |
an object created by the getBbasis function |
a basis matrix
A function to define a parametric proportional hazards model where the baseline hazard is modelled by a basis spline. This function returns an object inheriting class 'basehazardspec', list of functions 'distinfo', 'basehazard', 'gradbasehazard', 'hessbasehazard', 'cumbasehazard', 'gradcumbasehazard', 'hesscumbasehazard' and 'densityquantile'
BsplineHaz(times, knots = quantile(times), degree = 3, MLinits = NULL)
BsplineHaz(times, knots = quantile(times), degree = 3, MLinits = NULL)
times |
vector of survival times (both censored and uncensored) |
knots |
vector of knots in ascending order, must include minimum and maximum values of 'times' |
degree |
degree of the spline basis, default is 3 |
MLinits |
optional starting values for the non-spatial maximisation routine using optim. Note that we are working with the log of the parameters. Default is -10 for each parameter. |
The distinfo
function is used to provide basic distribution specific information to other spatsurv
functions. The user is required
to provide the following information in the returned list: npars
, the number of parameters in this distribution; parnames
,
the names of the parameters; trans
, the transformation scale on which the priors will be provided; itrans
, the inverse
transformation function that will be applied to the parameters before the hazard, and other functions are evaluated; jacobian
,
the derivative of the inverse transformation function with respect to each of the parameters; and hessian
, the second derivatives
of the inverse transformation function with respect to each of the parameters – note that currently the package spatsurv
only allows the use of functions where the parameters are transformed independently.
The basehazard
function is used to evaluate the baseline hazard function for the distribution of interest. It returns a
function that accepts as input a vector of times, t
and returns a vector.
The gradbasehazard
function is used to evaluate the gradient of the baseline hazard function with respect to the parameters,
this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hessbasehazard
function is used to evaluate the Hessian of the baseline hazard function. It returns a function that accepts
as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The cumbasehazard
function is used to evaluate the cumulative baseline hazard function for the distribution of interest.
It returns a function that accepts as input a vector of times, t
and returns a vector.
The gradcumbasehazard
function is used to evaluate the gradient of the cumulative baseline hazard function with respect
to the parameters, this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hesscumbasehazard
function is used to evaluate the Hessian of the cumulative baseline hazard function. It returns a
function that accepts as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The densityquantile
function is used to return quantiles of the density function. This is NOT REQUIRED for running the MCMC,
merely for us in post-processing with the predict
function where type
is 'densityquantile'. In the case of the Weibull
model for the baseline hazard, it can be shown that the q-th quantile is:
an object inheriting class 'basehazardspec'
exponentialHaz, gompertzHaz, makehamHaz, weibullHaz
A function to check whether the survival data to be passed to survspat is in the correct format
checkSurvivalData(s)
checkSurvivalData(s)
s |
an object of class Surv, from the survival package |
if there are any issues with data format, these are returned with the data an error message explaining any issues with the data
generic function for constructing circulant matrices
circulant(x, ...)
circulant(x, ...)
x |
an object |
... |
additional arguments |
method circulant
If x is a matrix whose columns are the bases of the sub-blocks of a block circulant matrix, then this function returns the block circulant matrix of interest.
## S3 method for class 'matrix' circulant(x, ...)
## S3 method for class 'matrix' circulant(x, ...)
x |
a matrix object |
... |
additional arguments |
If x is a matrix whose columns are the bases of the sub-blocks of a block circulant matrix, then this function returns the block circulant matrix of interest.
returns a circulant matrix with base x
## S3 method for class 'numeric' circulant(x, ...)
## S3 method for class 'numeric' circulant(x, ...)
x |
an numeric object |
... |
additional arguments |
a circulant matrix with base x
A function to return the "idx" i.e. c(i,j) element of a circulant matrix with base "base".
circulantij(idx, base)
circulantij(idx, base)
idx |
vector of length 2 th (i,j) (row,column) index to return |
base |
the base matrix of a circulant matrix |
the ij element of the full circulant
A function to define the spatial covariance model, see also ?CovarianceFct. Note that the parameters defined by the 'pars' argument are fixed, i.e. not estimated by the MCMC algorithm. To have spatsurv estimate these parameters, the user must construct a new covariance function to do so, stop("") see the spatsurv vignette.
covmodel(model, pars)
covmodel(model, pars)
model |
correlation type, a string see ?CovarianceFct |
pars |
vector of additional parameters for certain classes of covariance function (eg Matern), these must be supplied in the order given in ?CovarianceFct and are not estimated |
an object of class covmodel
A function to produce a diagnostic plot for model fit using the Cox-Snell residuals.
CSplot(mod, plot = TRUE, bw = FALSE, ...)
CSplot(mod, plot = TRUE, bw = FALSE, ...)
mod |
an object produced by the function survspat |
plot |
whether to plot the result, default is TRUE |
bw |
Logical. Plot in black/white/greyscale? Default is to produce a colour plot. Useful for producing plots for journals that do not accept colour plots. |
... |
other arguments to pass to plot |
the x and y values used in the plot
Generic function for computing the cumulative baseline hazard
cumbasehazard(obj, ...)
cumbasehazard(obj, ...)
obj |
an object |
... |
additional arguments – currently there are none, but this is for extensibility |
method cumbasehazard
cumbasehazard.basehazardspec, exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to retrieve the cumulative baseline hazard function
## S3 method for class 'basehazardspec' cumbasehazard(obj, ...)
## S3 method for class 'basehazardspec' cumbasehazard(obj, ...)
obj |
an object of class basehazardspec |
... |
additional arguments – currently there are none, but this is for extensibility |
a function returning the cumulative baseline hazard
exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to construct the integral of a B-spline curve given data and basis coefficients. Used in evaluating the cumulative baseline hazard.
cumulativeBspline.construct(x, basis)
cumulativeBspline.construct(x, basis)
x |
a vector, the data |
basis |
an object created by the getBbasis function |
an object that allows the integral of a given B-spline curve to be computed
A function to compute an individual's density function
density_PP(inputs)
density_PP(inputs)
inputs |
inputs for the function including the model matrix, frailties, fixed effects and the parameters of the baseline hazard derived from this model |
the density function for the individual
Generic function for computing quantiles of the density function for a given baseline hazard. This may not be analytically tractable.
densityquantile(obj, ...)
densityquantile(obj, ...)
obj |
an object |
... |
additional arguments – currently there are none, but this is for extensibility |
method densityquantile
densityquantile.basehazardspec, exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to compute quantiles of the density function
densityquantile_PP(inputs)
densityquantile_PP(inputs)
inputs |
inputs for the function including the model matrix, frailties, fixed effects and the parameters of the baseline hazard derived from this model |
quantiles of the density function for the individual
A function to retrieve the quantiles of the density function
## S3 method for class 'basehazardspec' densityquantile(obj, ...)
## S3 method for class 'basehazardspec' densityquantile(obj, ...)
obj |
an object of class basehazardspec |
... |
additional arguments – currently there are none, but this is for extensibility |
a function returning the density quantiles
exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function for evaluating the first and second derivatives of the log of an independent Gaussian prior
derivindepGaussianprior(beta = NULL, omega = NULL, eta = NULL, priors)
derivindepGaussianprior(beta = NULL, omega = NULL, eta = NULL, priors)
beta |
a vector, the parameter beta |
omega |
a vector, the parameter omega |
eta |
a vector, the parameter eta |
priors |
an object of class 'mcmcPrior', see ?mcmcPrior |
returns the first and second derivatives of the prior
survspat, betapriorGauss, omegapriorGauss, etapriorGauss, indepGaussianprior, derivindepGaussianprior
A function to
derivindepGaussianpriorST(beta = NULL, omega = NULL, eta = NULL, priors)
derivindepGaussianpriorST(beta = NULL, omega = NULL, eta = NULL, priors)
beta |
X |
omega |
X |
eta |
X |
priors |
X |
...
A function for evaluating the first and second derivatives of the log of an independent Gaussian prior
derivpsplineprior(beta = NULL, omega = NULL, eta = NULL, priors)
derivpsplineprior(beta = NULL, omega = NULL, eta = NULL, priors)
beta |
a vector, the parameter beta |
omega |
a vector, the parameter omega |
eta |
a vector, the parameter eta |
priors |
an object of class 'mcmcPrior', see ?mcmcPrior |
returns the first and second derivatives of the prior
survspat, betapriorGauss, omegapriorGauss, etapriorGauss, indepGaussianprior, derivindepGaussianprior
Generic function for returning information about the class of baseline hazard functions employed.
distinfo(obj, ...)
distinfo(obj, ...)
obj |
an object |
... |
additional argument – currently there are none, but this is for extensibility |
method distinfo
distinfo.basehazardspec, exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to retrive information on the baseline hazard distribution of choice
## S3 method for class 'basehazardspec' distinfo(obj, ...)
## S3 method for class 'basehazardspec' distinfo(obj, ...)
obj |
an object of class basehazardspec |
... |
additional arguments – currently there are none, but this is for extensibility |
a function returning information on the baseline hazard distribution of choice
exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to get an initial estimate of Y, to be used in calibrating the MCMC. Not for general use
estimateY(X, betahat, omegahat, surv, control)
estimateY(X, betahat, omegahat, surv, control)
X |
the design matrix containing covariate information |
betahat |
an estimate of beta |
omegahat |
an estimate of omega |
surv |
an object of class Surv |
control |
a list containg various control parameters for the MCMC and post-processing routines |
an estimate of Y, to be used in calibrating the MCMC
A function to compute an individual's approximate expected survival time using numerical integration. Note this appears to be unstable; the function is based on R's integrate function. Not intended for general use (yet!).
Et_PP(inputs)
Et_PP(inputs)
inputs |
inputs for the function including the model matrix, frailties, fixed effects and the parameters of the baseline hazard derived from this model |
the expected survival time for the individual, obtained by numerical integration of the density function.
A function to define Gaussian priors for eta. This function simply stores a vector of means and standard deviations to be passed to the main MCMC function, survspat.
etapriorGauss(mean, sd)
etapriorGauss(mean, sd)
mean |
the prior mean, a vector of length 1 or more. 1 implies a common mean. |
sd |
the prior standard deviation, a vector of length 1 or more. 1 implies a common standard deviation. |
an object of class "etapriorGauss"
survspat, betapriorGauss, omegapriorGauss, etapriorGauss, indepGaussianprior, derivindepGaussianprior
This function is used to evaluate the covariance function within the MCMC run. Not intended for general use.
EvalCov(cov.model, u, parameters)
EvalCov(cov.model, u, parameters)
cov.model |
an object of class covmodel |
u |
vector of distances |
parameters |
vector of parameters |
method EvalCov
A function to declare and also evaluate an exponential covariance function.
ExponentialCovFct()
ExponentialCovFct()
the exponential covariance function
SpikedExponentialCovFct, covmodel
A function to define a parametric proportional hazards model where the baseline hazard is taken from the exponential model. This function returns an object inheriting class 'basehazardspec', list of functions 'distinfo', 'basehazard', 'gradbasehazard', 'hessbasehazard', 'cumbasehazard', 'gradcumbasehazard', 'hesscumbasehazard' and 'densityquantile'
exponentialHaz()
exponentialHaz()
The distinfo
function is used to provide basic distribution specific information to other spatsurv
functions. The user is required
to provide the following information in the returned list: npars
, the number of parameters in this distribution; parnames
,
the names of the parameters; trans
, the transformation scale on which the priors will be provided; itrans
, the inverse
transformation function that will be applied to the parameters before the hazard, and other functions are evaluated; jacobian
,
the derivative of the inverse transformation function with respect to each of the parameters; and hessian
, the second derivatives
of the inverse transformation function with respect to each of the parameters – note that currently the package spatsurv
only allows the use of functions where the parameters are transformed independently.
The basehazard
function is used to evaluate the baseline hazard function for the distribution of interest. It returns a
function that accepts as input a vector of times, t
and returns a vector.
The gradbasehazard
function is used to evaluate the gradient of the baseline hazard function with respect to the parameters,
this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hessbasehazard
function is used to evaluate the Hessian of the baseline hazard function. It returns a function that accepts
as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The cumbasehazard
function is used to evaluate the cumulative baseline hazard function for the distribution of interest.
It returns a function that accepts as input a vector of times, t
and returns a vector.
The gradcumbasehazard
function is used to evaluate the gradient of the cumulative baseline hazard function with respect
to the parameters, this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hesscumbasehazard
function is used to evaluate the Hessian of the cumulative baseline hazard function. It returns a
function that accepts as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The densityquantile
function is used to return quantiles of the density function. This is NOT REQUIRED for running the MCMC,
merely for us in post-processing with the predict
function where type
is 'densityquantile'. In the case of the Weibull
model for the baseline hazard, it can be shown that the q-th quantile is:
an object inheriting class 'basehazardspec'
tpowHaz, gompertzHaz, makehamHaz, weibullHaz
A function to generate an FFT grid and associated quantities including cell dimensions, size of extended grid, centroids,
FFTgrid(spatialdata, cellwidth, ext, boundingbox = NULL)
FFTgrid(spatialdata, cellwidth, ext, boundingbox = NULL)
spatialdata |
a SpatialPixelsDataFrame object |
cellwidth |
width of computational cells |
ext |
multiplying constant: the size of the extended grid: ext*M by ext*N |
boundingbox |
optional bounding box over which to construct computational grid, supplied as an object on which the function 'bbox' returns the bounding box |
a list
A function to return the mcmc chains for the covariate effects
fixedpars(x)
fixedpars(x)
x |
an object of class mcmcspatsurv |
the beta mcmc chains
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
!! THIS FUNCTION IS NOT INTENDED FOR GENERAL USE !!
fixmatrix(mat)
fixmatrix(mat)
mat |
a matrix |
A function to fix up an estimated covariance matrix using a VERY ad-hoc method.
the fixed matrix
A function to
fixParHaz(bh, idx, fixval)
fixParHaz(bh, idx, fixval)
bh |
X |
idx |
X |
fixval |
X |
...
A function to produce a plot of, and return, the lag 1 (or higher, see argument 'lag') autocorrelation for each of the spatially correlated frailty chains
frailtylag1(object, plot = TRUE, lag = 1, ...)
frailtylag1(object, plot = TRUE, lag = 1, ...)
object |
an object inheriting class mcmcspatsurv |
plot |
logical whether to plot the result, default is TRUE |
lag |
the lag to plot, the default is 1 |
... |
other arguments to be passed to the plot function |
the lag 1 autocorrelation for each of the spatially correlated frailty chains
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
London Fire Brigade property
data(fs)
data(fs)
data.frame
https://data.london.gov.uk/
https://data.london.gov.uk/,https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/
fire <- data(fs)
fire <- data(fs)
London Fire Brigade response times to dwelling fires, 2009
data(fstimes)
data(fstimes)
data.frame
https://data.london.gov.uk/
https://data.london.gov.uk/,https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/
firetimes <- data(fstimes)
firetimes <- data(fstimes)
A function to
gamma2risk(mod)
gamma2risk(mod)
mod |
X |
...
A function to change Ys (spatially correlated noise) into Gammas (white noise). Used in the MALA algorithm.
GammafromY(Y, rootQeigs, mu)
GammafromY(Y, rootQeigs, mu)
Y |
Y matrix |
rootQeigs |
square root of the eigenvectors of the precision matrix |
mu |
parameter of the latent Gaussian field |
Gamma
A function to go from Y to Gamma
GammaFromY_SPDE(Y, U, mu)
GammaFromY_SPDE(Y, U, mu)
Y |
Y |
U |
upper Cholesky matrix |
mu |
the mean |
the value of Gamma for the given Y
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
Finn Lindgren, Havard Rue, Johan Lindstrom. An explicit link between Gaussian fields and Gaussian Markov random fields: the stochastic partial differential equation approach. Journal of the Royal Statistical Society: Series B 73(4)
A function to generate observed times given a vector of true survival times and a vector of censoring times. Used in the simulation of survival data.
gencens(survtimes, censtimes, type = "right")
gencens(survtimes, censtimes, type = "right")
survtimes |
a vector of survival times |
censtimes |
a vector of censoring times for left or right censored data, 2-column matrix of censoring times for interval censoring (number of rows equal to the number of observations). |
type |
the type of censoring to generate can be 'right' (default), 'left' or 'interval' |
an object of class 'Surv', the censoring indicator is equal to 1 if the event is uncensored and 0 otherwise for right/left censored data, or for interval censored data, the indicator is 0 uncensored, 1 right censored, 2 left censored, or 3 interval censored.
A function to get the bounding box of a Spatial object
getbb(obj)
getbb(obj)
obj |
a spatial object e.g. a SpatialPolygonsDataFrame, SpatialPolygons, etc ... anything with a bounding box that can be computed with bbox(obj) |
a SpatialPolygons object: the bounding box
A function returning the piecewise polynomial coefficients for a B-spline basis function i.e. the basis functions.
getBbasis(x, knots, degree, force = FALSE)
getBbasis(x, knots, degree, force = FALSE)
x |
a vector of data |
knots |
a vector of knots in ascending order. The first and last knots must be respectively the minimum and maximum of x. |
degree |
the degree of the spline |
force |
logical: skip check on knots? (not recommended!) |
the knots and the piecewise polynomial coefficients for a B-spline basis function i.e. the basis functions.
A function to return the covariance from a model based on the randomFields covariance functions. Not intended for general use.
getcov(u, sigma, phi, model, pars)
getcov(u, sigma, phi, model, pars)
u |
distance |
sigma |
variance parameter |
phi |
scale parameter |
model |
correlation type, see ?CovarianceFct |
pars |
vector of additional parameters for certain classes of covariance function (eg Matern), these must be supplied in the order given in ?CovarianceFct and are not estimated |
this is just a wrapper for CovarianceFct
A function to create a regular grid over an observation window in order to model the spatial randome effects as a Gaussian Markov random field.
getgrd(shape, cellwidth)
getgrd(shape, cellwidth)
shape |
an object of class SpatialPolygons or SpatialPolygonsDataFrame |
cellwidth |
a scalar, the width of the grid cells |
a SpatialPolygons object: the grid on which prediction of the spatial effects will occur
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
Finn Lindgren, Havard Rue, Johan Lindstrom. An explicit link between Gaussian fields and Gaussian Markov random fields: the stochastic partial differential equation approach. Journal of the Royal Statistical Society: Series B 73(4)
A function to extract and return the computational grid from a gridded analysis.
getGrid(mod, returnclass = "SpatialPolygonsDataFrame")
getGrid(mod, returnclass = "SpatialPolygonsDataFrame")
mod |
an object of class mcmcspatsurv, returned by the function survspat |
returnclass |
the class of object to return, default is a'SpatialPolygonsDataFrame'. Other options are 'raster', which returns a raster brick; or 'SpatialPixelsDataFrame' |
a SpatialPolygonsDataFrame in which Monte Carlo expectations can be stored and later plotted.
A function to compute the length of eta
getleneta(cov.model)
getleneta(cov.model)
cov.model |
a covariance model |
the length of eta
A function to compute an optimal cellwidth close to an initial suggestion. This maximises the efficiency of the MCMC algorithm when in the control argument of the function survspat, the option gridded is set to TRUE
getOptCellwidth(dat, cellwidth, ext = 2, plot = TRUE, boundingbox = NULL)
getOptCellwidth(dat, cellwidth, ext = 2, plot = TRUE, boundingbox = NULL)
dat |
any spatial data object whose bounding box can be computed using the function bbox. |
cellwidth |
an initial suggested cellwidth |
ext |
the extension parameter for the FFT transform, set to 2 by default |
plot |
whether to plot the grid and data to illustrate the optimal grid |
boundingbox |
optional bounding box over which to construct computational grid, supplied as an object on which the function 'bbox' returns the bounding box |
the optimum cell width
A function to extract parameter ranges for creating a grid on which to evaluate the log-posterior, used in calibrating the MCMC. This function is not intended for general use.
getparranges(priors, leneta, mult = 1.96)
getparranges(priors, leneta, mult = 1.96)
priors |
an object of class mcmcPriors |
leneta |
the length of eta passed to the function |
mult |
defaults to 1.96 so the grid formed will be mean plus/minus 1.96 times the standard deviation |
an appropriate range used to calibrate the MCMC: the mean of the prior for eta plus/minus 1.96 times the standard deviation
A function to return the survival data from an object of class mcmcspatsurv. This function is not intended for general use.
getsurvdata(x)
getsurvdata(x)
x |
an object of class mcmcspatsurv |
the survival data from an object of class mcmcspatsurv
A function to define a parametric proportional hazards model where the baseline hazard is taken from a Gompertz model. This function returns an object inheriting class 'basehazardspec', list of functions 'distinfo', 'basehazard', 'gradbasehazard', 'hessbasehazard', 'cumbasehazard', 'gradcumbasehazard', 'hesscumbasehazard' and 'densityquantile'
gompertzHaz()
gompertzHaz()
The distinfo
function is used to provide basic distribution specific information to other spatsurv
functions. The user is required
to provide the following information in the returned list: npars
, the number of parameters in this distribution; parnames
,
the names of the parameters; trans
, the transformation scale on which the priors will be provided; itrans
, the inverse
transformation function that will be applied to the parameters before the hazard, and other functions are evaluated; jacobian
,
the derivative of the inverse transformation function with respect to each of the parameters; and hessian
, the second derivatives
of the inverse transformation function with respect to each of the parameters – note that currently the package spatsurv
only allows the use of functions where the parameters are transformed independently.
The basehazard
function is used to evaluate the baseline hazard function for the distribution of interest. It returns a
function that accepts as input a vector of times, t
and returns a vector.
The gradbasehazard
function is used to evaluate the gradient of the baseline hazard function with respect to the parameters,
this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hessbasehazard
function is used to evaluate the Hessian of the baseline hazard function. It returns a function that accepts
as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The cumbasehazard
function is used to evaluate the cumulative baseline hazard function for the distribution of interest.
It returns a function that accepts as input a vector of times, t
and returns a vector.
The gradcumbasehazard
function is used to evaluate the gradient of the cumulative baseline hazard function with respect
to the parameters, this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hesscumbasehazard
function is used to evaluate the Hessian of the cumulative baseline hazard function. It returns a
function that accepts as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The densityquantile
function is used to return quantiles of the density function. This is NOT REQUIRED for running the MCMC,
merely for us in post-processing with the predict
function where type
is 'densityquantile'. In the case of the Weibull
model for the baseline hazard, it can be shown that the q-th quantile is:
an object inheriting class 'basehazardspec'
tpowHaz, exponentialHaz, makehamHaz, weibullHaz
Generic function for computing the gradient of the baseline hazard
gradbasehazard(obj, ...)
gradbasehazard(obj, ...)
obj |
an object |
... |
additional arguments – currently there are none, but this is for extensibility |
method gradbasehazard
gradbasehazard.basehazardspec, exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to retrieve the gradient of the baseline hazard function
## S3 method for class 'basehazardspec' gradbasehazard(obj, ...)
## S3 method for class 'basehazardspec' gradbasehazard(obj, ...)
obj |
an object of class basehazardspec |
... |
additional arguments – currently there are none, but this is for extensibility |
a function returning the gradient of the baseline hazard
exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
Generic function for computing the gradient of the cumulative baseline hazard
gradcumbasehazard(obj, ...)
gradcumbasehazard(obj, ...)
obj |
an object |
... |
additional arguments – currently there are none, but this is for extensibility |
method gradcumbasehazard
gradcumbasehazard.basehazardspec, exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to retrieve the gradient of the cumulative baseline hazard function
## S3 method for class 'basehazardspec' gradcumbasehazard(obj, ...)
## S3 method for class 'basehazardspec' gradcumbasehazard(obj, ...)
obj |
an object of class basehazardspec |
... |
additional arguments – currently there are none, but this is for extensibility |
a function returning the gradient of the cumulative baseline hazard
exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to convert a regular (x,y) grid of centroids into a SpatialPoints object
grid2spdf(xgrid, ygrid, proj4string = CRS(as.character(NA)))
grid2spdf(xgrid, ygrid, proj4string = CRS(as.character(NA)))
xgrid |
vector of x centroids (equally spaced) |
ygrid |
vector of x centroids (equally spaced) |
proj4string |
an optional proj4string, projection string for the grid, set using the function CRS |
a SpatialPolygonsDataFrame
A function to convert a regular (x,y) grid of centroids into a SpatialPixels object
grid2spix(xgrid, ygrid, proj4string = CRS(as.character(NA)))
grid2spix(xgrid, ygrid, proj4string = CRS(as.character(NA)))
xgrid |
vector of x centroids (equally spaced) |
ygrid |
vector of x centroids (equally spaced) |
proj4string |
an optional proj4string, projection string for the grid, set using the function CRS |
a SpatialPixels object
A function to convert a regular (x,y) grid of centroids into a SpatialPoints object
grid2spts(xgrid, ygrid, proj4string = CRS(as.character(NA)))
grid2spts(xgrid, ygrid, proj4string = CRS(as.character(NA)))
xgrid |
vector of x centroids (equally spaced) |
ygrid |
vector of x centroids (equally spaced) |
proj4string |
an optional proj4string, projection string for the grid, set using the function CRS |
a SpatialPoints object
A function to put estimated individual Y's onto a grid
gridY(Y, control)
gridY(Y, control)
Y |
estimate of Y |
control |
control parameters |
...
A function to put estimated individual Y's onto a grid
gridY_polygonal(Y, control)
gridY_polygonal(Y, control)
Y |
estimate of Y |
control |
control parameters |
...
A function to get an initial guess of the failure time t, to be used in calibrating the MCMC. Not for general use
guess_t(surv)
guess_t(surv)
surv |
an object of class Surv |
a guess at the failure times
test if an iterator has any more values to go
hasNext(obj)
hasNext(obj)
obj |
an iterator |
method for iter objects test if an iterator has any more values to go
## S3 method for class 'iter' hasNext(obj)
## S3 method for class 'iter' hasNext(obj)
obj |
an iterator |
A function to compute an individual's hazard function.
hazard_PP(inputs)
hazard_PP(inputs)
inputs |
inputs for the function including the model matrix, frailties, fixed effects and the parameters of the baseline hazard derived from this model |
the hazard function for the individual
A function to compute exceedance probabilities for the spatially correlated frailties.
hazardexceedance(threshold, direction = "upper")
hazardexceedance(threshold, direction = "upper")
threshold |
vector of thresholds |
direction |
default is "upper" which will calculate P(Y>threshold), alternative is "lower", which will calculate P(Y<threshold) |
a function that can be passed to the function MCE in order to compute the exceedance probabilities
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE,
A function to return the mcmc chains for the hazard function parameters
hazardpars(x)
hazardpars(x)
x |
an object of class mcmcspatsurv |
the omega mcmc chains
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
Generic function for computing the hessian of the baseline hazard
hessbasehazard(obj, ...)
hessbasehazard(obj, ...)
obj |
an object |
... |
additional arguments – currently there are none, but this is for extensibility |
method hessbasehazard
hessbasehazard.basehazardspec, exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to retrieve the Hessian of the baseline hazard function
## S3 method for class 'basehazardspec' hessbasehazard(obj, ...)
## S3 method for class 'basehazardspec' hessbasehazard(obj, ...)
obj |
an object of class basehazardspec |
... |
additional arguments – currently there are none, but this is for extensibility |
a function returning the Hessian of the baseline hazard
exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
Generic function for computing the Hessian of the cumulative baseline hazard
hesscumbasehazard(obj, ...)
hesscumbasehazard(obj, ...)
obj |
an object |
... |
additional arguments – currently there are none, but this is for extensibility |
method hesscumbasehazard
hesscumbasehazard.basehazardspec, exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to retrieve the hessian of the cumulative baseline hazard function
## S3 method for class 'basehazardspec' hesscumbasehazard(obj, ...)
## S3 method for class 'basehazardspec' hesscumbasehazard(obj, ...)
obj |
an object of class basehazardspec |
... |
additional arguments – currently there are none, but this is for extensibility |
a function returning the hessian of the cumulative baseline hazard
exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz
A function to
imputationModel(formula, offset, covariateData, priors)
imputationModel(formula, offset, covariateData, priors)
formula |
X |
offset |
X |
covariateData |
X |
priors |
X |
...
A function to declare and also evaluate an exponential covariance function.
Independent()
Independent()
the exponential covariance function
SpikedExponentialCovFct, covmodel
A function for evaluating the log of an independent Gaussian prior for a given set of parameter values.
indepGaussianprior(beta = NULL, omega = NULL, eta = NULL, priors)
indepGaussianprior(beta = NULL, omega = NULL, eta = NULL, priors)
beta |
parameter beta at which prior is to be evaluated |
omega |
parameter omega at which prior is to be evaluated |
eta |
parameter eta at which prior is to be evaluated |
priors |
an object of class mcmcPriors, see ?mcmcPriors |
the log of the prior evaluated at the given parameter values
survspat, betapriorGauss, omegapriorGauss, etapriorGauss, indepGaussianprior, derivindepGaussianprior
A function to
indepGaussianpriorST(beta = NULL, omega = NULL, eta = NULL, priors)
indepGaussianpriorST(beta = NULL, omega = NULL, eta = NULL, priors)
beta |
X |
omega |
X |
eta |
X |
priors |
X |
...
A function to control inferential settings. This function is used to set parameters for more advanced use of spatsurv.
inference.control( gridded = FALSE, cellwidth = NULL, ext = 2, imputation = NULL, optimcontrol = NULL, hessian = FALSE, plotcal = FALSE, timeonlyMCMC = FALSE, nugget = FALSE, savenugget = FALSE, split = 0.5, logUsigma_priormean = 0, logUsigma_priorsd = 0.5, nis = NULL, olinfo = NULL )
inference.control( gridded = FALSE, cellwidth = NULL, ext = 2, imputation = NULL, optimcontrol = NULL, hessian = FALSE, plotcal = FALSE, timeonlyMCMC = FALSE, nugget = FALSE, savenugget = FALSE, split = 0.5, logUsigma_priormean = 0, logUsigma_priorsd = 0.5, nis = NULL, olinfo = NULL )
gridded |
logical. Whether to perform compuation on a grid. Default is FALSE. |
cellwidth |
the width of computational cells to use |
ext |
integer the number of times to extend the computational grid by in order to perform compuitation. The default is 2. |
imputation |
for polygonal data, an optional model for inference at the sub-polygonal level, see function imputationModel |
optimcontrol |
a list of optional arguments to be passed to optim for non-spatial models |
hessian |
whether to return a numerical hessian. Set this to TRUE for non-spatial models. equal to the number of parameters of the baseline hazard |
plotcal |
logical, whether to produce plots of the MCMC calibration process, this is a technical option and should onyl be set to TRUE if poor mixing is evident (the printed h is low), then it is also useful to use a graphics device with multiple plotting windows. |
timeonlyMCMC |
logical, whether to only time the MCMC part of the algorithm, or whether to include in the reported running time the time taken to calibrate the method (default) |
nugget |
whether to include a nugget effect in the estimation. Note that only the mean and variance of the nugget effect is returned. |
savenugget |
whether to save the MCMC chain for the nugget effect |
split |
how to split the spatial and nugget proposal variance as a the proportion of variance assigned to the spatial effect apriori. Default is 0.5 |
logUsigma_priormean |
prior mean for log standard deviation of nugget effect |
logUsigma_priorsd |
prior sd for log standard deviation of nugget effect |
nis |
list of cell counts, each element being a matrix, with attributes "x" and "y" giving grid centroids in x and y directions. Used to impute locations of aggregated data:. |
olinfo |
to be supplied with nis, if continuous inference from aggregated data is required |
returns parameters to be used in the function survspat
A function to
insert(pars, idx, val)
insert(pars, idx, val)
pars |
X |
idx |
X |
val |
X |
...
A function to transform estimates of the (alpha, lambda) parameters of the weibull baseline hazard function, so they are commensurate with R's inbuilt density functions, (shape, scale).
invtransformweibull(x)
invtransformweibull(x)
x |
a vector of paramters |
the transformed parameters. For the weibull model, this transforms 'shape' 'scale' (see ?dweibull) to 'alpha' and 'lambda' for the MCMC
if this mcmc iteration is in the burn-in period, return TRUE
is.burnin(obj)
is.burnin(obj)
obj |
an mcmc iterator |
TRUE or FALSE
if this mcmc iteration is one not thinned out, this is true
is.retain(obj)
is.retain(obj)
obj |
an mcmc iterator |
TRUE or FALSE
within a loop, this is the iteration number we are currently doing.
iteration(obj)
iteration(obj)
obj |
an mcmc iterator |
get the iteration number
integer iteration number, starting from 1.
A function to evaluate the log-posterior of a spatial parametric proportional hazards model. Not intended for general use.
logPosterior( surv, X, beta, omega, eta, gamma, priors, cov.model, u, control, gradient = FALSE, hessian = FALSE )
logPosterior( surv, X, beta, omega, eta, gamma, priors, cov.model, u, control, gradient = FALSE, hessian = FALSE )
surv |
an object of class Surv |
X |
the design matrix, containing covariate information |
beta |
parameter beta |
omega |
parameter omega |
eta |
parameter eta |
gamma |
parameter gamma |
priors |
the priors, an object of class 'mcmcPriors' |
cov.model |
the spatial covariance model |
u |
vector of interpoint distances |
control |
a list containg various control parameters for the MCMC and post-processing routines |
gradient |
logical whether to evaluate the gradient |
hessian |
logical whether to evaluate the Hessian |
evaluates the log-posterior and the gradient and hessian, if required.
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
A function to evaluate the log-posterior of a spatial parametric proportional hazards model using gridded Y. Not intended for general use.
logPosterior_gridded( surv, X, beta, omega, eta, gamma, priors, cov.model, u, control, gradient = FALSE, hessian = FALSE )
logPosterior_gridded( surv, X, beta, omega, eta, gamma, priors, cov.model, u, control, gradient = FALSE, hessian = FALSE )
surv |
an object of class Surv |
X |
the design matrix, containing covariate information |
beta |
parameter beta |
omega |
parameter omega |
eta |
parameter eta |
gamma |
parameter gamma |
priors |
the priors, an object of class 'mcmcPriors' |
cov.model |
the spatial covariance model |
u |
vector of interpoint distances |
control |
a list containg various control parameters for the MCMC and post-processing routines |
gradient |
logical whether to evaluate the gradient |
hessian |
logical whether to evaluate the Hessian |
evaluates the log-posterior and the gradient and hessian, if required.
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
A function to evaluate the log-posterior of a spatial parametric proportional hazards model. Not intended for general use.
logPosterior_polygonal( surv, X, beta, omega, eta, gamma, priors, cov.model, u, control, gradient = FALSE, hessian = FALSE )
logPosterior_polygonal( surv, X, beta, omega, eta, gamma, priors, cov.model, u, control, gradient = FALSE, hessian = FALSE )
surv |
an object of class Surv |
X |
the design matrix, containing covariate information |
beta |
parameter beta |
omega |
parameter omega |
eta |
parameter eta |
gamma |
parameter gamma |
priors |
the priors, an object of class 'mcmcPriors' |
cov.model |
the spatial covariance model |
u |
vector of interpoint distances |
control |
a list containg various control parameters for the MCMC and post-processing routines |
gradient |
logical whether to evaluate the gradient |
hessian |
logical whether to evaluate the Hessian |
evaluates the log-posterior and the gradient and hessian, if required.
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
A function to evaluate the log-posterior of a spatial parametric proportional hazards model. Not intended for general use.
logPosterior_SPDE( surv, X, beta, omega, eta, gamma, priors, cov.model, u, control, gradient = FALSE, hessian = FALSE )
logPosterior_SPDE( surv, X, beta, omega, eta, gamma, priors, cov.model, u, control, gradient = FALSE, hessian = FALSE )
surv |
an object of class Surv |
X |
the design matrix, containing covariate information |
beta |
parameter beta |
omega |
parameter omega |
eta |
parameter eta |
gamma |
parameter gamma |
priors |
the priors, an object of class 'mcmcPriors' |
cov.model |
the spatial covariance model |
u |
vector of interpoint distances |
control |
a list containg various control parameters for the MCMC and post-processing routines |
gradient |
logical whether to evaluate the gradient |
hessian |
logical whether to evaluate the Hessian |
evaluates the log-posterior and the gradient and hessian, if required.
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
Finn Lindgren, Havard Rue, Johan Lindstrom. An explicit link between Gaussian fields and Gaussian Markov random fields: the stochastic partial differential equation approach. Journal of the Royal Statistical Society: Series B 73(4)
useful for testing progress bars
loop.mcmc(object, sleep = 1)
loop.mcmc(object, sleep = 1)
object |
an mcmc iterator |
sleep |
pause between iterations in seconds |
A function to define a parametric proportional hazards model where the baseline hazard is taken from the Gompertz-Makeham model. This function returns an object inheriting class 'basehazardspec', list of functions 'distinfo', 'basehazard', 'gradbasehazard', 'hessbasehazard', 'cumbasehazard', 'gradcumbasehazard', 'hesscumbasehazard' and 'densityquantile'
makehamHaz()
makehamHaz()
The distinfo
function is used to provide basic distribution specific information to other spatsurv
functions. The user is required
to provide the following information in the returned list: npars
, the number of parameters in this distribution; parnames
,
the names of the parameters; trans
, the transformation scale on which the priors will be provided; itrans
, the inverse
transformation function that will be applied to the parameters before the hazard, and other functions are evaluated; jacobian
,
the derivative of the inverse transformation function with respect to each of the parameters; and hessian
, the second derivatives
of the inverse transformation function with respect to each of the parameters – note that currently the package spatsurv
only allows the use of functions where the parameters are transformed independently.
The basehazard
function is used to evaluate the baseline hazard function for the distribution of interest. It returns a
function that accepts as input a vector of times, t
and returns a vector.
The gradbasehazard
function is used to evaluate the gradient of the baseline hazard function with respect to the parameters,
this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hessbasehazard
function is used to evaluate the Hessian of the baseline hazard function. It returns a function that accepts
as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The cumbasehazard
function is used to evaluate the cumulative baseline hazard function for the distribution of interest.
It returns a function that accepts as input a vector of times, t
and returns a vector.
The gradcumbasehazard
function is used to evaluate the gradient of the cumulative baseline hazard function with respect
to the parameters, this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hesscumbasehazard
function is used to evaluate the Hessian of the cumulative baseline hazard function. It returns a
function that accepts as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The densityquantile
function is used to return quantiles of the density function. This is NOT REQUIRED for running the MCMC,
merely for us in post-processing with the predict
function where type
is 'densityquantile'. In the case of the Weibull
model for the baseline hazard, it can be shown that the q-th quantile is:
an object inheriting class 'basehazardspec'
tpowHaz, exponentialHaz, gompertzHaz, weibullHaz
A function to get initial estimates of model parameters using maximum likelihood. Not intended for general purose use.
maxlikparamPHsurv(surv, X, control)
maxlikparamPHsurv(surv, X, control)
surv |
an object of class Surv |
X |
the design matrix, containing covariate information |
control |
a list containg various control parameters for the MCMC and post-processing routines |
initial estimates of the parameters
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
A function to compute Monte Carlo expectations from an object inheriting class mcmcspatsurv
MCE(object, fun)
MCE(object, fun)
object |
an object inheriting class mcmcspatsurv |
fun |
a function with arguments beta, omega, eta and Y |
the Monte Carlo mean of the function over the posterior.
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, hazardexceedance
control an MCMC loop with this iterator
mcmcLoop(N, burnin, thin, trim = TRUE, progressor = mcmcProgressPrint)
mcmcLoop(N, burnin, thin, trim = TRUE, progressor = mcmcProgressPrint)
N |
number of iterations |
burnin |
length of burn-in |
thin |
frequency of thinning |
trim |
whether to cut off iterations after the last retained iteration |
progressor |
a function that returns a progress object |
A function for setting MCMC options.
mcmcpars(nits, burn, thin, inits = NULL, adaptivescheme = NULL)
mcmcpars(nits, burn, thin, inits = NULL, adaptivescheme = NULL)
nits |
numer of iterations, |
burn |
length of burnin |
thin |
thinning parameter eg operated on chain every 'thin' iteration (eg store output or compute some posterior functional) |
inits |
NOT CURRENTLY IN USE |
adaptivescheme |
NOT CURRENTLY IN USE |
mcmc parameters
A function to define priors for the MCMC.
mcmcPriors( betaprior = NULL, omegaprior = NULL, etaprior = NULL, call = NULL, derivative = NULL )
mcmcPriors( betaprior = NULL, omegaprior = NULL, etaprior = NULL, call = NULL, derivative = NULL )
betaprior |
prior for beta, the covariate effects |
omegaprior |
prior for omega, the parameters of the baseline hazard |
etaprior |
prior for eta, the parameters of the latent field |
call |
function to evaluate the log-prior e.g. logindepGaussianprior |
derivative |
function to evaluate the first and second derivatives of the prior |
The package spatsurv
only provides functionality for the built-in Gaussian priors. However, the choice of prior is
extensible by the user by creating functions similar to the functions betapriorGauss
, omegapriorGauss
, etapriorGauss
,
indepGaussianprior
and derivindepGaussianprior
: the first three of which provide a mechanism for storing and retrieving the
parameters of the priors; the fourth, a function for evaluating the log of the prior for a given set of parameter values; and the fifth, a
function for evaluating the first and second derivatives of the log of the prior. It is assumed that parameters are a priori independent.
The user interested in using other priors is encouraged to look at the structure of the five functions mentioned above.
an object of class mcmcPriors
survspat, betapriorGauss, omegapriorGauss, etapriorGauss, indepGaussianprior, derivindepGaussianprior
a progress monitor that does nothing
mcmcProgressNone(mcmcloop)
mcmcProgressNone(mcmcloop)
mcmcloop |
an mcmc loop iterator |
a progress monitor
a progress monitor that prints each iteration
mcmcProgressPrint(mcmcloop)
mcmcProgressPrint(mcmcloop)
mcmcloop |
an mcmc loop iterator |
a progress monitor
a progress monitor that uses a text progress bar
mcmcProgressTextBar(mcmcloop)
mcmcProgressTextBar(mcmcloop)
mcmcloop |
an mcmc loop iterator |
a progress monitor
A function to compute the midpoints of a vector
midpts(x)
midpts(x)
x |
a vector |
the midpoints, a vector of length length(x)-1
A function to
multiWayHaz(bhlist, bhtime, bhfix, MLinits = NULL)
multiWayHaz(bhlist, bhtime, bhfix, MLinits = NULL)
bhlist |
X |
bhtime |
X |
bhfix |
X |
MLinits |
X |
...
A function used in the computation of neighbours on non-rectangular grids. Not intended for general use.
neighLocs(coord, cellwidth, order)
neighLocs(coord, cellwidth, order)
coord |
coordinate of interest |
cellwidth |
a scalar, the width of the grid cells |
order |
the order of the SPDE approximation: see Lindgren et al 2011 for details |
coordinates of centroids of neighbours
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
Finn Lindgren, Havard Rue, Johan Lindstrom. An explicit link between Gaussian fields and Gaussian Markov random fields: the stochastic partial differential equation approach. Journal of the Royal Statistical Society: Series B 73(4)
A function to compute the order of a set of neighbours. Not intended for general use.
neighOrder(neighlocs)
neighOrder(neighlocs)
neighlocs |
an object created by the function neighLocs |
the neighbour orders
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
Finn Lindgren, Havard Rue, Johan Lindstrom. An explicit link between Gaussian fields and Gaussian Markov random fields: the stochastic partial differential equation approach. Journal of the Royal Statistical Society: Series B 73(4)
just a wrapper for nextElem really.
nextStep(object)
nextStep(object)
object |
an mcmc loop object |
A function to evaluate the log-likelihood of a non-spatial parametric proportional hazards model. Not intended for general use.
NonSpatialLogLikelihood_or_gradient( surv, X, beta, omega, control, loglikelihood, gradient )
NonSpatialLogLikelihood_or_gradient( surv, X, beta, omega, control, loglikelihood, gradient )
surv |
an object of class Surv |
X |
the design matrix, containing covariate information |
beta |
parameter beta |
omega |
parameter omega |
control |
a list containg various control parameters for the MCMC and post-processing routines |
loglikelihood |
logical whether to evaluate the log-likelihood |
gradient |
logical whether to evaluate the gradient |
...
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
A function to define Gaussian priors for omega. This function simply stores a vector of means and standard deviations to be passed to the main MCMC function, survspat.
omegapriorGauss(mean, sd)
omegapriorGauss(mean, sd)
mean |
the prior mean, a vector of length 1 or more. 1 implies a common mean. |
sd |
the prior standard deviation, a vector of length 1 or more. 1 implies a common standard deviation. |
an object of class "omegapriorGauss"
survspat, betapriorGauss, omegapriorGauss, etapriorGauss, indepGaussianprior, derivindepGaussianprior
A function to
omegapriorGaussST(basehaz, fmean, fsd, taumean, tausd, thetamean, thetasd)
omegapriorGaussST(basehaz, fmean, fsd, taumean, tausd, thetamean, thetasd)
basehaz |
X |
fmean |
X |
fsd |
X |
taumean |
X |
tausd |
X |
thetamean |
X |
thetasd |
X |
...
optifix. Optimise with fixed parameters
optifix( par, fixed, fn, gr = NULL, ..., method = c("Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN"), lower = -Inf, upper = Inf, control = list(), hessian = FALSE )
optifix( par, fixed, fn, gr = NULL, ..., method = c("Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN"), lower = -Inf, upper = Inf, control = list(), hessian = FALSE )
par |
X |
fixed |
X |
fn |
X |
gr |
X |
... |
X |
method |
X |
lower |
X |
upper |
X |
control |
X |
hessian |
X |
its like optim, but with fixed parameters.
specify a second argument 'fixed', a vector of TRUE/FALSE values. If TRUE, the corresponding parameter in fn() is fixed. Otherwise its variable and optimised over.
The return thing is the return thing from optim() but with a couple of extra bits - a vector of all the parameters and a vector copy of the 'fixed' argument.
Written by Barry Rowlingson <[email protected]> October 2011
This file released under a CC By-SA license: http://creativecommons.org/licenses/by-sa/3.0/
and must retain the text: "Originally written by Barry Rowlingson" in comments.
...
A function to
## S3 method for class 'FFTgrid' plot(x, y = NULL, ...)
## S3 method for class 'FFTgrid' plot(x, y = NULL, ...)
x |
X |
y |
X |
... |
X |
...
A function to produce a 2-D plot of right censored spatial survival data.
plotsurv( spp, ss, maxcex = 1, transform = identity, background = NULL, eventpt = 19, eventcol = "red", censpt = "+", censcol = "black", xlim = NULL, ylim = NULL, xlab = NULL, ylab = NULL, add = FALSE, ... )
plotsurv( spp, ss, maxcex = 1, transform = identity, background = NULL, eventpt = 19, eventcol = "red", censpt = "+", censcol = "black", xlim = NULL, ylim = NULL, xlab = NULL, ylab = NULL, add = FALSE, ... )
spp |
A spatial points data frame |
ss |
A Surv object (with right-censoring) |
maxcex |
maximum size of dots default is equavalent to setting cex equal to 1 |
transform |
optional transformation to apply to the data, a function, for example 'sqrt' |
background |
a background object to plot default is null, which gives a blamk background note that if non-null, the parameters xlim and ylim will be derived from this object. |
eventpt |
The type of point to illustrate events, default is 19 (see ?pch) |
eventcol |
the colour of events, default is black |
censpt |
The type of point to illustrate events, default is "+" (see ?pch) |
censcol |
the colour of censored observations, default is red |
xlim |
optional x-limits of plot, default is to choose this automatically |
ylim |
optional y-limits of plot, default is to choose this automatically |
xlab |
label for x-axis |
ylab |
label for y-axis |
add |
logical, whether to add the survival plot on top of an existing plot, default is FALSE, which produces a plot in a new device |
... |
other arguments to pass to plot |
Plots the survival data non-censored observations appear as dots and censored observations as crosses. The size of the dot is proportional to the observed time.
A function to add two polynomials in the form of vectors of coefficients. The first element of the vector being the constant (order 0) term
polyadd(poly1, poly2)
polyadd(poly1, poly2)
poly1 |
a vector of coefficients for the first polynomial of length degree plus 1 |
poly2 |
a vector of coefficients for the second polynomial of length degree plus 1 |
the coefficients of the sum of poly1 and poly2
A function to multiply two polynomials in the form of vectors of coefficients. The first element of the vector being the constant (order 0) term
polymult(poly1, poly2)
polymult(poly1, poly2)
poly1 |
a vector of coefficients for the first polynomial of length degree plus 1 |
poly2 |
a vector of coefficients for the second polynomial of length degree plus 1 |
the coefficients of the product of poly1 and poly2
A function to produce a plot of the posterior covariance function with upper and lower quantiles.
posteriorcov( x, probs = c(0.025, 0.5, 0.975), rmax = NULL, n = 100, plot = TRUE, bw = FALSE, corr = FALSE, ... )
posteriorcov( x, probs = c(0.025, 0.5, 0.975), rmax = NULL, n = 100, plot = TRUE, bw = FALSE, corr = FALSE, ... )
x |
an object of class mcmcspatsurv |
probs |
vector of probabilities to be fed to quantile function |
rmax |
maximum distance in space to compute this distance up to |
n |
the number of points at which to evaluate the posterior covariance. |
plot |
whether to plot the result |
bw |
Logical. Plot in black/white/greyscale? Default is to produce a colour plot. Useful for producing plots for journals that do not accept colour plots. |
corr |
logical whether to return the correlation function, default is FALSE i.e. returns the covariance function |
... |
other arguments to be passed to matplot function |
produces a plot of the posterior spatial covariance function.
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, MCE, hazardexceedance
A function to produce predictions from MCMC output. These could include quantiles of the individual density, survival or hazard functions or quantiles of the density function (if available analytically).
## S3 method for class 'mcmcspatsurv' predict( object, type = "density", t = NULL, n = 110, indx = NULL, probs = c(0.025, 0.5, 0.975), plot = TRUE, pause = TRUE, bw = FALSE, ... )
## S3 method for class 'mcmcspatsurv' predict( object, type = "density", t = NULL, n = 110, indx = NULL, probs = c(0.025, 0.5, 0.975), plot = TRUE, pause = TRUE, bw = FALSE, ... )
object |
an object of class mcmcspatsurv |
type |
can be "density", "hazard", "survival" or "densityquantile". Default is "density". Note that "densityquantile" is not always analytically tractable for some choices of baseline hazard function. |
t |
optional vector of times at which to compute the quantiles, Defult is NULL, in which case a uniformly spaced vector of length n from 0 to the maximum time is used |
n |
the number of points at which to compute the quantiles if t is NULL |
indx |
the index number of a particular individual or vector of indices of individuals for which the quantiles should be produced |
probs |
vector of probabilities |
plot |
whether to plot the result |
pause |
logical whether to pause between plots, the default is TRUE |
bw |
Logical. Plot in black/white/greyscale? Default is to produce a colour plot. Useful for producing plots for journals that do not accept colour plots. |
... |
other arguments, not used here |
the required predictions
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, priorposterior, posteriorcov, MCE, hazardexceedance
print method print an mcmc iterator's details
## S3 method for class 'mcmc' print(x, ...)
## S3 method for class 'mcmc' print(x, ...)
x |
a mcmc iterator |
... |
other args |
A function to print summary tables from an MCMC run
## S3 method for class 'mcmcspatsurv' print(x, probs = c(0.5, 0.025, 0.975), digits = 3, scientific = -3, ...)
## S3 method for class 'mcmcspatsurv' print(x, probs = c(0.5, 0.025, 0.975), digits = 3, scientific = -3, ...)
x |
an object inheriting class mcmcspatsurv |
probs |
vector of quantiles to return |
digits |
see help file ?format |
scientific |
see help file ?format |
... |
additional arguments, not used here |
prints summary tables to the console
quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
A function to print summary tables from an MCMC run
## S3 method for class 'mlspatsurv' print(x, probs = c(0.5, 0.025, 0.975), digits = 3, scientific = -3, ...)
## S3 method for class 'mlspatsurv' print(x, probs = c(0.5, 0.025, 0.975), digits = 3, scientific = -3, ...)
x |
an object inheriting class mcmcspatsurv |
probs |
vector of quantiles to return |
digits |
see help file ?format |
scientific |
see help file ?format |
... |
additional arguments, not used here |
prints summary tables to the console
quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
A function to print summary tables from an MCMC run
## S3 method for class 'textSummary' print(x, ...)
## S3 method for class 'textSummary' print(x, ...)
x |
an object inheriting class textSummary |
... |
additional arguments, not used here |
prints a text summary of 'x' to the console
A function to produce plots of the prior (which shows as a red line) and posterior (showing as a histogram)
priorposterior( x, breaks = 30, ylab = "Density", main = "", pause = TRUE, bw = FALSE, ... )
priorposterior( x, breaks = 30, ylab = "Density", main = "", pause = TRUE, bw = FALSE, ... )
x |
an object inheriting class mcmcspatsurv |
breaks |
see ?hist |
ylab |
optional y label |
main |
optional title |
pause |
logical whether to pause between plots, the default is TRUE |
bw |
Logical. Plot in black/white/greyscale? Default is to produce a colour plot. Useful for producing plots for journals that do not accept colour plots. |
... |
other arguments passed to the hist function |
plots of the prior (red line) and posterior (histogram).
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, posteriorcov, MCE, hazardexceedance
A function to compute an approximate scaling matrix for the MCMC algorithm. Not intended for general use.
proposalVariance( X, surv, betahat, omegahat, Yhat, priors, cov.model, u, control )
proposalVariance( X, surv, betahat, omegahat, Yhat, priors, cov.model, u, control )
X |
the design matrix, containing covariate information |
surv |
an object of class Surv |
betahat |
an estimate of beta |
omegahat |
an estimate of omega |
Yhat |
an estimate of Y |
priors |
the priors |
cov.model |
the spatial covariance model |
u |
a vector of pairwise distances |
control |
a list containg various control parameters for the MCMC and post-processing routines |
an estimate of eta and also an approximate scaling matrix for the MCMC
A function to compute an approximate scaling matrix for the MCMC algorithm. Not intended for general use.
proposalVariance_gridded( X, surv, betahat, omegahat, Yhat, priors, cov.model, u, control )
proposalVariance_gridded( X, surv, betahat, omegahat, Yhat, priors, cov.model, u, control )
X |
the design matrix, containing covariate information |
surv |
an object of class Surv |
betahat |
an estimate of beta |
omegahat |
an estimate of omega |
Yhat |
an estimate of Y |
priors |
the priors |
cov.model |
the spatial covariance model |
u |
a vector of pairwise distances |
control |
a list containg various control parameters for the MCMC and post-processing routines |
an estimate of eta and also an approximate scaling matrix for the MCMC
A function to compute an approximate scaling matrix for the MCMC algorithm. Not intended for general use.
proposalVariance_polygonal( X, surv, betahat, omegahat, Yhat, priors, cov.model, u, control )
proposalVariance_polygonal( X, surv, betahat, omegahat, Yhat, priors, cov.model, u, control )
X |
the design matrix, containing covariate information |
surv |
an object of class Surv |
betahat |
an estimate of beta |
omegahat |
an estimate of omega |
Yhat |
an estimate of Y |
priors |
the priors |
cov.model |
the spatial covariance model |
u |
a vector of pairwise distances |
control |
a list containg various control parameters for the MCMC and post-processing routines |
an estimate of eta and also an approximate scaling matrix for the MCMC
A function to compute an approximate scaling matrix for the MCMC algorithm. Not intended for general use.
proposalVariance_SPDE( X, surv, betahat, omegahat, Yhat, priors, cov.model, u, control )
proposalVariance_SPDE( X, surv, betahat, omegahat, Yhat, priors, cov.model, u, control )
X |
the design matrix, containing covariate information |
surv |
an object of class Surv |
betahat |
an estimate of beta |
omegahat |
an estimate of omega |
Yhat |
an estimate of Y |
priors |
the priors |
cov.model |
the spatial covariance model |
u |
a vector of pairwise distances |
control |
a list containg various control parameters for the MCMC and post-processing routines |
an estimate of eta and also an approximate scaling matrix for the MCMC
A function to define a parametric proportional hazards model where the baseline hazard is modelled by a basis spline and where the coefficients of the model follow a partially imporper random walk prior. This function returns an object inheriting class 'basehazardspec', list of functions 'distinfo', 'basehazard', 'gradbasehazard', 'hessbasehazard', 'cumbasehazard', 'gradcumbasehazard', 'hesscumbasehazard' and 'densityquantile'
PsplineHaz(times, knots = quantile(times), degree = 3, MLinits = NULL)
PsplineHaz(times, knots = quantile(times), degree = 3, MLinits = NULL)
times |
vector of survival times (both censored and uncensored) |
knots |
vector of knots in ascending order, must include minimum and maximum values of 'times' |
degree |
degree of the spline basis, default is 3 |
MLinits |
optional starting values for the non-spatial maximisation routine using optim. Note that we are working with the log of the parameters. Default is -10 for each parameter. |
The distinfo
function is used to provide basic distribution specific information to other spatsurv
functions. The user is required
to provide the following information in the returned list: npars
, the number of parameters in this distribution; parnames
,
the names of the parameters; trans
, the transformation scale on which the priors will be provided; itrans
, the inverse
transformation function that will be applied to the parameters before the hazard, and other functions are evaluated; jacobian
,
the derivative of the inverse transformation function with respect to each of the parameters; and hessian
, the second derivatives
of the inverse transformation function with respect to each of the parameters – note that currently the package spatsurv
only allows the use of functions where the parameters are transformed independently.
The basehazard
function is used to evaluate the baseline hazard function for the distribution of interest. It returns a
function that accepts as input a vector of times, t
and returns a vector.
The gradbasehazard
function is used to evaluate the gradient of the baseline hazard function with respect to the parameters,
this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hessbasehazard
function is used to evaluate the Hessian of the baseline hazard function. It returns a function that accepts
as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The cumbasehazard
function is used to evaluate the cumulative baseline hazard function for the distribution of interest.
It returns a function that accepts as input a vector of times, t
and returns a vector.
The gradcumbasehazard
function is used to evaluate the gradient of the cumulative baseline hazard function with respect
to the parameters, this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hesscumbasehazard
function is used to evaluate the Hessian of the cumulative baseline hazard function. It returns a
function that accepts as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The densityquantile
function is used to return quantiles of the density function. This is NOT REQUIRED for running the MCMC,
merely for us in post-processing with the predict
function where type
is 'densityquantile'. In the case of the Weibull
model for the baseline hazard, it can be shown that the q-th quantile is:
an object inheriting class 'basehazardspec'
exponentialHaz, gompertzHaz, makehamHaz, weibullHaz
A function for evaluating the log of an independent Gaussian prior for a given set of parameter values.
psplineprior(beta = NULL, omega = NULL, eta = NULL, priors)
psplineprior(beta = NULL, omega = NULL, eta = NULL, priors)
beta |
parameter beta at which prior is to be evaluated |
omega |
parameter omega at which prior is to be evaluated |
eta |
parameter eta at which prior is to be evaluated |
priors |
an object of class mcmcPriors, see ?mcmcPriors |
the log of the prior evaluated at the given parameter values
survspat, betapriorGauss, omegapriorGauss, etapriorGauss, indepGaussianprior, derivindepGaussianprior
A function to define Gaussian priors for omega. This function simply stores a vector of means and standard deviations to be passed to the main MCMC function, survspat.
psplineRWprior(taumean, tausd, basehaz, order = 2)
psplineRWprior(taumean, tausd, basehaz, order = 2)
taumean |
the prior mean, a vector of length 1 or more. 1 implies a common mean. |
tausd |
the prior standard deviation, a vector of length 1 or more. 1 implies a common standard deviation. |
basehaz |
an object inheriting class "basehazardspec", specificlly, this function was used for such objects created by a call to the function PsplineHaz |
order |
the order of the random walk, default is 2 |
an object of class "omegapriorGauss"
survspat, betapriorGauss, omegapriorGauss, etapriorGauss, indepGaussianprior, derivindepGaussianprior
A function to compute the second derivative of a function (of several real variables) using a quadratic approximation on a grid of points defined by the list argRanges. Also returns the local maximum.
QuadApprox(fun, npts, argRanges, plot = FALSE, ...)
QuadApprox(fun, npts, argRanges, plot = FALSE, ...)
fun |
a function |
npts |
integer number of points in each direction |
argRanges |
a list of ranges on which to construct the grid for each parameter |
plot |
whether to plot the quadratic approximation of the posterior (for two-dimensional parameters only) |
... |
other arguments to be passed to fun |
a 2 by 2 matrix containing the curvature at the maximum and the (x,y) value at which the maximum occurs
A function to extract quantiles of the parameters from an mcmc run
## S3 method for class 'mcmcspatsurv' quantile(x, probs = c(0.025, 0.5, 0.975), ...)
## S3 method for class 'mcmcspatsurv' quantile(x, probs = c(0.025, 0.5, 0.975), ...)
x |
an object inheriting class mcmcspatsurv |
probs |
vector of probabilities |
... |
other arguments to be passed to the function, not used here |
quantiles of model parameters
print.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
A function to extract quantiles of the parameters from an mcmc run
## S3 method for class 'mlspatsurv' quantile(x, probs = c(0.025, 0.5, 0.975), ...)
## S3 method for class 'mlspatsurv' quantile(x, probs = c(0.025, 0.5, 0.975), ...)
x |
an object inheriting class mcmcspatsurv |
probs |
vector of probabilities |
... |
other arguments to be passed to the function, not used here |
quantiles of model parameters
print.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
A function to return the mcmc chains for the spatially correlated frailties
randompars(x)
randompars(x)
x |
an object of class mcmcspatsurv |
the Y mcmc chains
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
Generic function for reconstructing B-spline covariate effects. See ?reconstruct.bs.mcmcspatsurv and ?reconstruct.bs.coxph
reconstruct.bs(mod, ...)
reconstruct.bs(mod, ...)
mod |
an object |
... |
additional arguments |
method reconstruct.bs
When bs(varname) has been used in the formula of a coxph model, this function can be used to reconstruct the predicted relative risk of that parameter over time.
## S3 method for class 'coxph' reconstruct.bs( mod, varname, fun = NULL, probs = c(0.025, 0.975), bw = FALSE, xlab = NULL, ylab = NULL, plot = TRUE, ... )
## S3 method for class 'coxph' reconstruct.bs( mod, varname, fun = NULL, probs = c(0.025, 0.975), bw = FALSE, xlab = NULL, ylab = NULL, plot = TRUE, ... )
mod |
model output, created by function survspat |
varname |
name of the variable modelled by a B-spline |
fun |
optional function to feed in. Default is to plot relative risk against the covariate of interest. Useful choices include "identity" (but with no quotes), which plots the non-linear effect on the scale of the linear predictor. |
probs |
upper and lower quantiles for confidence regions to plot> The default is c(0.025,0.975). |
bw |
Logical. Plot in black/white/greyscale? Default is to produce a colour plot. Useful for producing plots for journals that do not accept colour plots. |
xlab |
label for x axis, there is a sensible default |
ylab |
label for y axis, there is a sensible default |
plot |
logical, whether to plot the effect of varname over time |
... |
other arguments to be passed to the plotting function. |
median, upper and lower confidence bands for the effect of varname over time; the funciton also produces a plot.
When bs(varname) has been used in the formula of a model, this function can be used to reconstruct the posterior relative risk of that parameter over time.
## S3 method for class 'mcmcspatsurv' reconstruct.bs( mod, varname, probs = c(0.025, 0.975), bw = FALSE, xlab = NULL, ylab = NULL, plot = TRUE, ... )
## S3 method for class 'mcmcspatsurv' reconstruct.bs( mod, varname, probs = c(0.025, 0.975), bw = FALSE, xlab = NULL, ylab = NULL, plot = TRUE, ... )
mod |
model output, created by function survspat |
varname |
name of the variable modelled by a B-spline |
probs |
upper and lower quantiles for confidence regions to plot> The default is c(0.025,0.975). |
bw |
Logical. Plot in black/white/greyscale? Default is to produce a colour plot. Useful for producing plots for journals that do not accept colour plots. |
xlab |
label for x axis, there is a sensible default |
ylab |
label for y axis, there is a sensible default |
plot |
logical, whether to plot the effect of varname over time |
... |
other arguments to be passed to the plotting function. |
median, upper and lower confidence bands for the effect of varname over time; the funciton also produces a plot.
call this to reset an iterator's state to the initial
resetLoop(obj)
resetLoop(obj)
obj |
an mcmc iterator |
A function to compute Cox-Snell / modeified Cox-Snell / Martingale or Deviance residuals
## S3 method for class 'mcmcspatsurv' residuals(object, type = "Cox-Snell", ...)
## S3 method for class 'mcmcspatsurv' residuals(object, type = "Cox-Snell", ...)
object |
an object produced by the function survspat |
type |
type of residuals to return. Possible choices are 'Cox-Snell', 'modified-Cox-Snell', 'Martingale' or 'deviance'. |
... |
other arguments (not used here) |
the residuals
A function to define a parametric proportional hazards model where the baseline hazard is taken from the Weibull model. This function returns an object inheriting class 'basehazardspec', list of functions 'distinfo', 'basehazard', 'gradbasehazard', 'hessbasehazard', 'cumbasehazard', 'gradcumbasehazard', 'hesscumbasehazard' and 'densityquantile'
rootWeibullHaz(MLinits = NULL)
rootWeibullHaz(MLinits = NULL)
MLinits |
initial values for optim, default is NULL |
The distinfo
function is used to provide basic distribution specific information to other spatsurv
functions. The user is required
to provide the following information in the returned list: npars
, the number of parameters in this distribution; parnames
,
the names of the parameters; trans
, the transformation scale on which the priors will be provided; itrans
, the inverse
transformation function that will be applied to the parameters before the hazard, and other functions are evaluated; jacobian
,
the derivative of the inverse transformation function with respect to each of the parameters; and hessian
, the second derivatives
of the inverse transformation function with respect to each of the parameters – note that currently the package spatsurv
only allows the use of functions where the parameters are transformed independently.
The basehazard
function is used to evaluate the baseline hazard function for the distribution of interest. It returns a
function that accepts as input a vector of times, t
and returns a vector.
The gradbasehazard
function is used to evaluate the gradient of the baseline hazard function with respect to the parameters,
this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hessbasehazard
function is used to evaluate the Hessian of the baseline hazard function. It returns a function that accepts
as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The cumbasehazard
function is used to evaluate the cumulative baseline hazard function for the distribution of interest.
It returns a function that accepts as input a vector of times, t
and returns a vector.
The gradcumbasehazard
function is used to evaluate the gradient of the cumulative baseline hazard function with respect
to the parameters, this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hesscumbasehazard
function is used to evaluate the Hessian of the cumulative baseline hazard function. It returns a
function that accepts as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The densityquantile
function is used to return quantiles of the density function. This is NOT REQUIRED for running the MCMC,
merely for us in post-processing with the predict
function where type
is 'densityquantile'. In the case of the Weibull
model for the baseline hazard, it can be shown that the q-th quantile is:
an object inheriting class 'basehazardspec'
tpowHaz, exponentialHaz, gompertzHaz, makehamHaz
update a text progress bar. See help(txtProgressBar) for more info.
setTxtProgressBar2(pb, value, title = NULL, label = NULL)
setTxtProgressBar2(pb, value, title = NULL, label = NULL)
pb |
text progress bar object |
value |
new value |
title |
ignored |
label |
text for end of progress bar |
A function to set up the baseline hazard, cumulative hazard and derivative functions for use in evaluating the log posterior. This fucntion is not intended for general use.
setupHazard(dist, pars, grad = FALSE, hess = FALSE)
setupHazard(dist, pars, grad = FALSE, hess = FALSE)
dist |
an object of class 'basehazardspec' |
pars |
parameters with which to create the functions necessary to evaluate the log posterior |
grad |
logical, whetether to create gradient functions for the baseline hazard and cumulative hazard |
hess |
logical, whetether to create hessian functions for the baseline hazard and cumulative hazard |
a list of functions used in evaluating the log posterior
A function to set up the computational grid and precision matrix structure for SPDE models.
setupPrecMatStruct(shape, cellwidth, no)
setupPrecMatStruct(shape, cellwidth, no)
shape |
an object of class SpatialPolygons or SpatialPolygonsDataFrame |
cellwidth |
a scalar, the width of the grid cells |
no |
the order of the SPDE approximation: see Lindgren et al 2011 for details |
the computational grid and a function for constructing the precision matrix
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
Finn Lindgren, Havard Rue, Johan Lindstrom. An explicit link between Gaussian fields and Gaussian Markov random fields: the stochastic partial differential equation approach. Journal of the Royal Statistical Society: Series B 73(4)
A function to show the grid that will be used for a given cellwidth
showGrid(dat, cellwidth, ext = 2, boundingbox = NULL)
showGrid(dat, cellwidth, ext = 2, boundingbox = NULL)
dat |
any spatial data object whose bounding box can be computed using the function bbox. |
cellwidth |
an initial suggested cellwidth |
ext |
the extension parameter for the FFT transform, set to 2 by default |
boundingbox |
optional bounding box over which to construct computational grid, supplied as an object on which the function 'bbox' returns the bounding box |
a plot showing the grid and the data. Ideally the data should only just fit inside the grid.
A function to simulate spatial parametric proportional hazards model. The function works by simulating candidate survival times using MCMC in parallel for each individual based on each individual's covariates and the common parameter effects, beta.
simsurv( X = cbind(age = runif(100, 5, 50), sex = rbinom(100, 1, 0.5), cancer = rbinom(100, 1, 0.2)), beta = c(0.0296, 0.0261, 0.035), omega = 1, dist = exponentialHaz(), coords = matrix(runif(2 * nrow(X)), nrow(X), 2), cov.parameters = c(1, 0.1), cov.model = ExponentialCovFct(), mcmc.control = mcmcpars(nits = 1e+05, burn = 10000, thin = 90), savechains = TRUE )
simsurv( X = cbind(age = runif(100, 5, 50), sex = rbinom(100, 1, 0.5), cancer = rbinom(100, 1, 0.2)), beta = c(0.0296, 0.0261, 0.035), omega = 1, dist = exponentialHaz(), coords = matrix(runif(2 * nrow(X)), nrow(X), 2), cov.parameters = c(1, 0.1), cov.model = ExponentialCovFct(), mcmc.control = mcmcpars(nits = 1e+05, burn = 10000, thin = 90), savechains = TRUE )
X |
a matrix of covariate information |
beta |
the parameter effects |
omega |
vector of parameters for the baseline hazard model |
dist |
the distribution choice: exp or weibull at present |
coords |
matrix with 2 columns giving the coordinates at which to simulate data |
cov.parameters |
a vector: the parameters for the covariance function |
cov.model |
an object of class covmodel, see ?covmodel |
mcmc.control |
mcmc control paramters, see ?mcmcpars |
savechains |
save all chains? runs faster if set to FALSE, but then you'll be unable to conduct convergence/mixing diagnostics |
in list element 'survtimes', a vector of simulated survival times (the last simulated value from the MCMC chains) in list element 'T' the MCMC chains
covmodel, survspat, tpowHaz, exponentialHaz, gompertzHaz, makehamHaz, weibullHaz
A function to return the mcmc chains for the spatial covariance function parameters
spatialpars(x)
spatialpars(x)
x |
an object of class mcmcspatsurv |
the eta mcmc chains
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
Display the introductory vignette for the spatsurv package.
spatsurvVignette()
spatsurvVignette()
displays the vignette by calling browseURL
A function to declare and evaluate an SPDE covariance function.
SPDE(ord)
SPDE(ord)
ord |
the order of the model to be used, currently an integer between 1 an 3. See Lindgren 2011 paper. |
an covariance function based on the SPDE model
A function to used in entering elements into the precision matrix of an SPDE model. Not intended for general use.
SPDEprec(a, ord)
SPDEprec(a, ord)
a |
parameter a, see Lindgren et al 2011. |
ord |
the order of the SPDE model, see Lindgren et al 2011. |
a function used for creating the precision matrix
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
Finn Lindgren, Havard Rue, Johan Lindstrom. An explicit link between Gaussian fields and Gaussian Markov random fields: the stochastic partial differential equation approach. Journal of the Royal Statistical Society: Series B 73(4)
A function to declare and also evaluate a spiked exponential covariance function. This is an exponential covariance function with a nugget.
SpikedExponentialCovFct()
SpikedExponentialCovFct()
the spiked exponential covariance function
A function to completely summarise the output of an object of class mcmcspatsurv.
Summarise( obj, digits = 3, scientific = -3, inclIntercept = FALSE, printmode = "LaTeX", displaymode = "console", ... )
Summarise( obj, digits = 3, scientific = -3, inclIntercept = FALSE, printmode = "LaTeX", displaymode = "console", ... )
obj |
an object produced by a call to lgcpPredictSpatialPlusPars, lgcpPredictAggregateSpatialPlusPars, lgcpPredictSpatioTemporalPlusPars orlgcpPredictMultitypeSpatialPlusPars |
digits |
see the option "digits" in ?format |
scientific |
see the option "scientific" in ?format |
inclIntercept |
logical: whether to summarise the intercept term, default is FALSE. |
printmode |
the format of the text to return, can be 'LaTeX' (the default) or 'text' for plain text. |
displaymode |
default is 'console' alternative is 'rstudio' |
... |
other arguments passed to the function "format" |
A text summary, that can be pasted into a LaTeX document and later edited.
summary of an mcmc iterator print out values of an iterator and reset it. DONT call this in a loop that uses this iterator - it will reset it. And break.
## S3 method for class 'mcmc' summary(object, ...)
## S3 method for class 'mcmc' summary(object, ...)
object |
an mcmc iterator |
... |
other args |
A function to return summary tables from an MCMC run
## S3 method for class 'mcmcspatsurv' summary(object, probs = c(0.5, 0.025, 0.975), ...)
## S3 method for class 'mcmcspatsurv' summary(object, probs = c(0.5, 0.025, 0.975), ...)
object |
an object inheriting class mcmcspatsurv |
probs |
vector of quantiles to return |
... |
additional arguments |
summary tables to the console
print.mcmcspatsurv, quantile.mcmcspatsurv, vcov.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
Do a 3d plot of spatial survival data
surv3d( spp, ss, lwd = 2, lcol = "black", lalpha = 1, pstyle = c("point", "text"), psize = c(20, 10), pcol = c("red", "black"), ptext = c("X", ""), palpha = 1, title = "Spatial Survival", basegrid = TRUE, baseplane = TRUE )
surv3d( spp, ss, lwd = 2, lcol = "black", lalpha = 1, pstyle = c("point", "text"), psize = c(20, 10), pcol = c("red", "black"), ptext = c("X", ""), palpha = 1, title = "Spatial Survival", basegrid = TRUE, baseplane = TRUE )
spp |
A spatial points data frame |
ss |
A Surv object (with right-censoring) |
lwd |
Line width for stems |
lcol |
Line colour for stems |
lalpha |
Opacity for stems |
pstyle |
Point style "point" or "text" |
psize |
Vector of length 2 for uncensored/censored points size |
pcol |
Vector of length 2 for uncensored/censored points colours |
ptext |
Vector of length 2 for uncensored/censored text characters |
palpha |
Opacity for points/text |
title |
Main title for plot |
basegrid |
add a grid at t=0 |
baseplane |
add a plane at t=0 |
Uses rgl graphics to make a spinny zoomy plot
nothing
Barry S Rowlingson
## Not run: require(sp) require(survival) d = data.frame( x=runif(40)*1.5, y = runif(40), age=as.integer(20+30*runif(40)), sex = sample(c("M","F"),40,TRUE) ) coordinates(d)=~x+y d$surv = Surv(as.integer(5+20*runif(40)),runif(40)>.9) clear3d();surv3d(d,d$surv,baseplane=TRUE,basegrid=TRUE) clear3d();surv3d(d,d$surv,baseplane=TRUE,basegrid=TRUE,pstyle="t",lalpha=0.5,lwd=3,palpha=1) ## End(Not run)
## Not run: require(sp) require(survival) d = data.frame( x=runif(40)*1.5, y = runif(40), age=as.integer(20+30*runif(40)), sex = sample(c("M","F"),40,TRUE) ) coordinates(d)=~x+y d$surv = Surv(as.integer(5+20*runif(40)),runif(40)>.9) clear3d();surv3d(d,d$surv,baseplane=TRUE,basegrid=TRUE) clear3d();surv3d(d,d$surv,baseplane=TRUE,basegrid=TRUE,pstyle="t",lalpha=0.5,lwd=3,palpha=1) ## End(Not run)
A function to compute an individual's survival function
survival_PP(inputs)
survival_PP(inputs)
inputs |
inputs for the function including the model matrix, frailties, fixed effects and the parameters of the baseline hazard derived from this model |
the survival function for the individual
A function to run a Bayesian analysis on censored spatial survial data assuming a proportional hazards model using an adaptive Metropolis-adjusted Langevin algorithm.
survspat( formula, data, dist, cov.model, mcmc.control, priors, shape = NULL, ids = list(shpid = NULL, dataid = NULL), control = inference.control(gridded = FALSE), boundingbox = NULL )
survspat( formula, data, dist, cov.model, mcmc.control, priors, shape = NULL, ids = list(shpid = NULL, dataid = NULL), control = inference.control(gridded = FALSE), boundingbox = NULL )
formula |
the model formula in a format compatible with the function flexsurvreg from the flexsurv package |
data |
a SpatialPointsDataFrame object containing the survival data as one of the columns OR for polygonal data a data.frame, in which case, the argument shape must also be supplied |
dist |
choice of distribution function for baseline hazard. Current options are: exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz |
cov.model |
an object of class covmodel, see ?covmodel ?ExponentialCovFct or ?SpikedExponentialCovFct |
mcmc.control |
mcmc control parameters, see ?mcmcpars |
priors |
an object of class Priors, see ?mcmcPriors |
shape |
when data is a data.frame, this can be a SpatialPolygonsDataFrame, or a SpatialPointsDataFrame, used to model spatial variation at the small region level. The regions are the polygons, or they represent the (possibly weighted) centroids of the polygons. |
ids |
named list entry shpid character string giving name of variable in shape to be matched to variable dataid in data. dataid is the second entry of the named list. |
control |
additional control parameters, see ?inference.control |
boundingbox |
optional bounding box over which to construct computational grid, supplied as an object on which the function 'bbox' returns the bounding box |
an object inheriting class 'mcmcspatsurv' for which there exist methods for printing, summarising and making inference from.
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
tpowHaz, exponentialHaz, gompertzHaz, makehamHaz, weibullHaz,
covmodel, ExponentialCovFct, SpikedExponentialCovFct
,
mcmcpars, mcmcPriors, inference.control
A function to perform maximun likelihood inference for non-spatial survival data.
survspatNS(formula, data, dist, control = inference.control())
survspatNS(formula, data, dist, control = inference.control())
formula |
the model formula in a format compatible with the function flexsurvreg from the flexsurv package |
data |
a SpatialPointsDataFrame object containing the survival data as one of the columns |
dist |
choice of distribution function for baseline hazard. Current options are: exponentialHaz, weibullHaz, gompertzHaz, makehamHaz, tpowHaz |
control |
additional control parameters, see ?inference.control |
an object inheriting class 'mcmcspatsurv' for which there exist methods for printing, summarising and making inference from.
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
tpowHaz, exponentialHaz, gompertzHaz, makehamHaz, weibullHaz,
covmodel, ExponentialCovFct, SpikedExponentialCovFct
,
mcmcpars, mcmcPriors, inference.control
A function to print a text description of the inferred paramerers beta and eta from a call to the function lgcpPredictSpatialPlusPars, lgcpPredictAggregateSpatialPlusPars, lgcpPredictSpatioTemporalPlusPars or lgcpPredictMultitypeSpatialPlusPars
textSummary( obj, digits = 3, scientific = -3, inclIntercept = FALSE, printmode = "LaTeX", ... )
textSummary( obj, digits = 3, scientific = -3, inclIntercept = FALSE, printmode = "LaTeX", ... )
obj |
an object produced by a call to lgcpPredictSpatialPlusPars, lgcpPredictAggregateSpatialPlusPars, lgcpPredictSpatioTemporalPlusPars orlgcpPredictMultitypeSpatialPlusPars |
digits |
see the option "digits" in ?format |
scientific |
see the option "scientific" in ?format |
inclIntercept |
logical: whether to summarise the intercept term, default is FALSE. |
printmode |
the format of the text to return, can be 'LaTeX' (the default) or 'text' for plain text. |
... |
other arguments passed to the function "format" |
A text summary, that can be pasted into a LaTeX document and later edited.
A function to
timevaryingPL( formula, t0, t, delta, dist, data, ties = "Efron", optimcontrol = NULL )
timevaryingPL( formula, t0, t, delta, dist, data, ties = "Efron", optimcontrol = NULL )
formula |
a formula of the form 'S ~ coef1 + coef2' etc the object S will be created |
t0 |
X |
t |
X |
delta |
censoring indicator a vector of 1 for an event and 0 for censoring |
dist |
X |
data |
X |
ties |
X default is Efron |
optimcontrol |
X |
...
A function to define a parametric proportional hazards model where the baseline hazard is taken from the 'powers of t' model. This function returns an object inheriting class 'basehazardspec', list of functions 'distinfo', 'basehazard', 'gradbasehazard', 'hessbasehazard', 'cumbasehazard', 'gradcumbasehazard', 'hesscumbasehazard' and 'densityquantile'
tpowHaz(powers)
tpowHaz(powers)
powers |
a vector of powers of t. These are powers are treated as fixed in estimation routines and it is assumed that the log cumulatice baseline hazard is a linear combination of these powers of t |
The distinfo
function is used to provide basic distribution specific information to other spatsurv
functions. The user is required
to provide the following information in the returned list: npars
, the number of parameters in this distribution; parnames
,
the names of the parameters; trans
, the transformation scale on which the priors will be provided; itrans
, the inverse
transformation function that will be applied to the parameters before the hazard, and other functions are evaluated; jacobian
,
the derivative of the inverse transformation function with respect to each of the parameters; and hessian
, the second derivatives
of the inverse transformation function with respect to each of the parameters – note that currently the package spatsurv
only allows the use of functions where the parameters are transformed independently.
The basehazard
function is used to evaluate the baseline hazard function for the distribution of interest. It returns a
function that accepts as input a vector of times, t
and returns a vector.
The gradbasehazard
function is used to evaluate the gradient of the baseline hazard function with respect to the parameters,
this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hessbasehazard
function is used to evaluate the Hessian of the baseline hazard function. It returns a function that accepts
as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The cumbasehazard
function is used to evaluate the cumulative baseline hazard function for the distribution of interest.
It returns a function that accepts as input a vector of times, t
and returns a vector.
The gradcumbasehazard
function is used to evaluate the gradient of the cumulative baseline hazard function with respect
to the parameters, this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hesscumbasehazard
function is used to evaluate the Hessian of the cumulative baseline hazard function. It returns a
function that accepts as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The densityquantile
function is used to return quantiles of the density function. This is NOT REQUIRED for running the MCMC,
merely for us in post-processing with the predict
function where type
is 'densityquantile'. In the case of the Weibull
model for the baseline hazard, it can be shown that the q-th quantile is:
an object inheriting class 'basehazardspec'
exponentialHaz, gompertzHaz, makehamHaz, weibullHaz
A function to back-transform estimates of the parameters of the weibull baseline hazard function, so they are commensurate with R's inbuilt density functions. Transforms from (shape, scale) to (alpha, lambda)
transformweibull(x)
transformweibull(x)
x |
a vector of paramters |
the transformed parameters. For the weibull model, this is the back-transform from 'alpha' and 'lambda' to 'shape' 'scale' (see ?dweibull).
A function to
TwoWayHazAdditive(bhlist, bhtime, bhfix, MLinits = NULL)
TwoWayHazAdditive(bhlist, bhtime, bhfix, MLinits = NULL)
bhlist |
X |
bhtime |
X |
bhfix |
X |
MLinits |
X |
...
This is the base txtProgressBar but with a little modification to implement the label parameter for style=3. For full info see txtProgressBar
txtProgressBar2( min = 0, max = 1, initial = 0, char = "=", width = NA, title = "", label = "", style = 1 )
txtProgressBar2( min = 0, max = 1, initial = 0, char = "=", width = NA, title = "", label = "", style = 1 )
min |
min value for bar |
max |
max value for bar |
initial |
initial value for bar |
char |
the character (or character string) to form the progress bar. |
width |
progress bar width |
title |
ignored |
label |
text to put at the end of the bar |
style |
bar style |
A function to return the variance covariance matrix of the parameters beta, omega and eta
## S3 method for class 'mcmcspatsurv' vcov(object, ...)
## S3 method for class 'mcmcspatsurv' vcov(object, ...)
object |
an object inheriting class mcmcspatsurv |
... |
other arguments, not used here |
the variance covariance matrix of the parameters beta, omega and eta
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
A function to return the variance covariance matrix of the parameters beta, omega and eta
## S3 method for class 'mlspatsurv' vcov(object, ...)
## S3 method for class 'mlspatsurv' vcov(object, ...)
object |
an object inheriting class mcmcspatsurv |
... |
other arguments, not used here |
the variance covariance matrix of the parameters beta, omega and eta
print.mcmcspatsurv, quantile.mcmcspatsurv, summary.mcmcspatsurv, frailtylag1, spatialpars, hazardpars, fixedpars, randompars, baselinehazard, predict.mcmcspatsurv, priorposterior, posteriorcov, MCE, hazardexceedance
A function to define a parametric proportional hazards model where the baseline hazard is taken from the Weibull model. This function returns an object inheriting class 'basehazardspec', list of functions 'distinfo', 'basehazard', 'gradbasehazard', 'hessbasehazard', 'cumbasehazard', 'gradcumbasehazard', 'hesscumbasehazard' and 'densityquantile'
weibullHaz(MLinits = NULL)
weibullHaz(MLinits = NULL)
MLinits |
initial values for optim, default is NULL |
The distinfo
function is used to provide basic distribution specific information to other spatsurv
functions. The user is required
to provide the following information in the returned list: npars
, the number of parameters in this distribution; parnames
,
the names of the parameters; trans
, the transformation scale on which the priors will be provided; itrans
, the inverse
transformation function that will be applied to the parameters before the hazard, and other functions are evaluated; jacobian
,
the derivative of the inverse transformation function with respect to each of the parameters; and hessian
, the second derivatives
of the inverse transformation function with respect to each of the parameters – note that currently the package spatsurv
only allows the use of functions where the parameters are transformed independently.
The basehazard
function is used to evaluate the baseline hazard function for the distribution of interest. It returns a
function that accepts as input a vector of times, t
and returns a vector.
The gradbasehazard
function is used to evaluate the gradient of the baseline hazard function with respect to the parameters,
this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hessbasehazard
function is used to evaluate the Hessian of the baseline hazard function. It returns a function that accepts
as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The cumbasehazard
function is used to evaluate the cumulative baseline hazard function for the distribution of interest.
It returns a function that accepts as input a vector of times, t
and returns a vector.
The gradcumbasehazard
function is used to evaluate the gradient of the cumulative baseline hazard function with respect
to the parameters, this typically returns a vector. It returns a function that accepts as input a vector of times, t
, and returns a matrix.
The hesscumbasehazard
function is used to evaluate the Hessian of the cumulative baseline hazard function. It returns a
function that accepts as input a vector of times, t
and returns a list of hessian matrices corresponding to each t
.
The densityquantile
function is used to return quantiles of the density function. This is NOT REQUIRED for running the MCMC,
merely for us in post-processing with the predict
function where type
is 'densityquantile'. In the case of the Weibull
model for the baseline hazard, it can be shown that the q-th quantile is:
an object inheriting class 'basehazardspec'
tpowHaz, exponentialHaz, gompertzHaz, makehamHaz
A function to change Gammas (white noise) into Ys (spatially correlated noise). Used in the MALA algorithm.
YfromGamma(Gamma, invrootQeigs, mu)
YfromGamma(Gamma, invrootQeigs, mu)
Gamma |
Gamma matrix |
invrootQeigs |
inverse square root of the eigenvectors of the precision matrix |
mu |
parameter of the latent Gaussian field |
Y
A function to go from Gamma to Y
YFromGamma_SPDE(gamma, U, mu)
YFromGamma_SPDE(gamma, U, mu)
gamma |
Gamma |
U |
upper Cholesky matrix |
mu |
the mean |
the value of Y for the given Gamma
Benjamin M. Taylor and Barry S. Rowlingson (2017). spatsurv: An R Package for Bayesian Inference with Spatial Survival Models. Journal of Statistical Software, 77(4), 1-32, doi:10.18637/jss.v077.i04.
Finn Lindgren, Havard Rue, Johan Lindstrom. An explicit link between Gaussian fields and Gaussian Markov random fields: the stochastic partial differential equation approach. Journal of the Royal Statistical Society: Series B 73(4)