General Semiparametric Shared Frailty Model

Simulates and fits semiparametric shared frailty models under a wide range of frailty distributions using a consistent and asymptotically-normal estimator. Currently supports: gamma, power variance function, log-normal, and inverse Gaussian frailty models.

Travis-CI Build Status CRAN Downloads


frailtySurv is an R package for simulating and fitting semiparametric shared frailty models.


For the latest stable version, install from CRAN:


The development version can be installed from github using devtools.



The following code shows how to generate data and fit the model.

#> Welcome to frailtySurv v1.3.3
dat <- genfrail(N=200, K=2, beta=c(log(2),log(3)), 
                frailty="gamma", theta=2,
                Lambda_0=function(t, tau=4.6, C=0.01) (C*t)^tau)
fit <- fitfrail(Surv(time, status) ~ Z1 + Z2 + cluster(family), 
                dat=dat, frailty="gamma")
#> Call: fitfrail(formula = Surv(time, status) ~ Z1 + Z2 + cluster(family), 
#>     dat = dat, frailty = "gamma")
#>      Covariate     Coefficient
#>             Z1           0.654
#>             Z2           1.006
#> Frailty distribution   gamma(1.802), VAR of frailty variates = 1.802
#> Log-likelihood         -1575.752
#> Converged (method)     10 iterations, 3.24 secs (maximized log-likelihood)

Parameter traces are given by

plot(fit, type="trace")

The estimated cumulative baseline hazard is given by

plot(fit, type="cumhaz")

The results can be compared to other estimation techniques.

coxph(Surv(time, status) ~ Z1 + Z2 + frailty.gamma(family), data=dat)
#> Call:
#> coxph(formula = Surv(time, status) ~ Z1 + Z2 + frailty.gamma(family), 
#>     data = dat)
#>                           coef se(coef)      se2    Chisq  DF       p
#> Z1                      0.6651   0.0941   0.0852  49.9190   1 1.6e-12
#> Z2                      1.0282   0.1046   0.0941  96.5685   1 < 2e-16
#> frailty.gamma(family)                            475.6283 150 < 2e-16
#> Iterations: 7 outer, 58 Newton-Raphson
#>      Variance of random effect= 1.88   I-likelihood = -1319.6 
#> Degrees of freedom for terms=   0.8   0.8 149.7 
#> Likelihood ratio test=576  on 151 df, p=<2e-16  n= 400
frailtyPenal(Surv(time, status) ~ Z1 + Z2 + cluster(family), data=dat, n.knots=10, kappa=2)
#> Be patient. The program is computing ... 
#> The program took 0.22 seconds
#> Call:
#> frailtyPenal(formula = Surv(time, status) ~ Z1 + Z2 + cluster(family), 
#>     data = dat, n.knots = 10, kappa = 2)
#>   Shared Gamma Frailty model parameter estimates  
#>   using a Penalized Likelihood on the hazard function 
#>       coef exp(coef) SE coef (H) SE coef (HIH)       z          p
#> Z1 0.67236   1.95885   0.0994732     0.0994732 6.75921 1.3875e-11
#> Z2 1.04884   2.85433   0.1191210     0.1191210 8.80481 0.0000e+00
#>     Frailty parameter, Theta: 1.92378 (SE (H): 0.319435 ) p = 8.5895e-10 
#>       penalized marginal log-likelihood = -1378.15
#>       Convergence criteria: 
#>       parameters = 0.000362 likelihood = 0.000201 gradient = 2.44e-08 
#>       LCV = the approximate likelihood cross-validation criterion
#>             in the semi parametrical case     = 3.48287 
#>       n= 400
#>       n events= 256  n groups= 200
#>       number of iterations:  13 
#>       Exact number of knots used:  10 
#>       Value of the smoothing parameter:  2, DoF:  11.96

Clone and build

You can clone the repository and build the project from source using RStudio. To create a project in RStudio from this repository, you must have both RStudio and git installed.

  • In RStudio, go to File -> New Project -> Version Control -> Git
  • Name the project (eg. frailtySurv), choose location, and specify the Repository URL as

More information about RStudio and git

Also see the chapter in the R packages book

Build everything

To load the package (simulate installing and loading with library(frailty)):


or shortuct: Ctrl+Shift+L

Use this command to build a source package (binary = FALSE by default)


Other usefull commands and shortcuts:

  • Build and reload everything: Ctrl+Shift+B
  • Check the package, devtools::check(): Ctrl+Shift+E
  • Run all tests, devtools::test(): Ctrl+Shift+T

Build vignettes

Build the vignettes with the command:


Compiled vignettes will reside in inst/doc. In particular, see frailtySurv.pdf

git pull

Use RStudio to pull the latest code if you've already cloned the repository. In the "git" pane, look for the Pull button. You can also view the commit history from there and see the diff between modified files, if any.



Version 1.3.6 (April 2019)

  • Added a call to set.seed before each example in genfrail

Version 1.3.5 (August 2018)

  • Added citation to JSS article

Version 1.3.4 (June 2018)

Bug fixes

  • Changed default genfrail control params to constants instead derived from .Machine
  • Added tryCatch to simfrail to avoid failing completely and generate a warning

Version 1.3.3 (June 2018)

Bug fixes

  • Fixed rifcond error
  • Fixed missing figures in online docs

Version 1.3.2 (February 2017)

Bug fixes

  • Renamed "hazard" "cumhaz" in plot/summary functions to avoid confusion with the baseline hazard rate.
  • Fixed typos in fitfrail.control docs.
  • Fixed a bug in lognormal 2nd derivative, resulting in biased estimates using fitmethod="score".
  • Added checks for object and param matching in plot/summary functions

Version 1.3.1 (December 2016)

New features

  • Added numeric integration control parameters to genfrail (see genfrail.control)

Bug fixes

  • Removed unnecssary imports

Version 1.3 (June 2016)

New features

  • Added init.beta and init.theta control parameters for parameter initialization
  • Added censor.time parameter to genfrail for user-defined censorship times
  • Added option to specify Lambda.times when plotting residuals

Bug fixes

  • Made both loglik and score fit methods use the same convergence control parameters
  • Improved loglik parameter estimation and convergence
  • Fixed the labels of residuals boxplot x-axis
  • Fixed clang warning with static casts

Version 1.2.2 (September 2015)

Bug fixes

  • Fixed ambiguous C++ calls to pow

Version 1.2.1 (September 2015)

Bug fixes

  • Resolved undefined global vars
  • Added Lambda.all to the fitted model object for estimated cumulative baseline hazard at all observed times
  • Minor changes to man pages

Version 1.2.0 (September 2015)

New features

  • Renamed package to frailtySurv
  • Added uniform censorship to genfrail

Version 1.1.1 (September 2015)

Bug fixes

  • Fixed bug in summary.fitfrail
  • Fixed censor.param parameter in genfrail

Version 1.1.0 (September 2015)

New features

  • Control parameters for numerical integration (int.iter, int.reltol, int.abstol)
  • Added summary.fitfrail for summarizing the survival curve
  • Added parameter to fitfrail to compute the SE of parameter estimates

Bug fixes

  • Renamed Lambda.time to Lambda.times (not backwards compatible)
  • Improved print.fitfrail
  • Remove missing observations
  • Improved print.summary.genfrail
  • Added sanity checks to frailty distribution params
  • Fixed parallel support on Windows (runs in serial with a warning for now)

Version 1.0.0 (August 2015)

Initial release

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


1.3.6 by Vinnie Monaco, a year ago

Report a bug at

Browse source code at

Authors: Vinnie Monaco [aut, cre] , Malka Gorfine [aut] , Li Hsu [aut]

Documentation:   PDF Manual  

Task views:

LGPL-2 license

Imports stats, nleqslv, reshape2, ggplot2, numDeriv

Depends on survival

Suggests knitr, parallel, gridExtra

Linking to Rcpp

See at CRAN