`new(PwExp, rate = c(1, 2), time = c(0, 2, 4))` threw an error with unexpected message.
Expected match: "'time' and 'rate' must be the same length."
Actual message: "object 'PwExp' not found"

module <- Rcpp::Module('distributions', PACKAGE = "hesim")
pwexp <- new(PwExp, rate = rate, time = time)
r2 <- rpwexp(1, rate = rate, time = time)
paste0("hesim does not currently support sampling from a piecewise ",
"exponential distribution truncated from above.")
r <- replicate(10, pwexp$trandom(7, Inf))
r <- replicate(10, pwexp$trandom(max(time) + 1, Inf))
# An error is thrown if time and rate are not the same length
"'time' and 'rate' must be the same length."
wei <- new(Weibull, shape = sh, scale = sc)
flexsurv::hweibull(4, shape = sh, scale = sc))
flexsurv::Hweibull(4, shape = sh, scale = sc))
r2 <- rweibull(1, shape = sh, scale = sc)
wei <- new(WeibullPH, shape = a, scale = m)
flexsurv::dweibullPH(4, shape = a, scale = m))
flexsurv::pweibullPH(4, shape = a, scale = m))
flexsurv::qweibullPH(.7, shape = a, scale = m))
flexsurv::hweibullPH(2, shape = a, scale = m))
flexsurv::HweibullPH(2, shape = a, scale = m))
r2 <- rweibullPH(1, shape = a, scale = m)
wei <- new(WeibullNma, a0 = a0, a1 = a1)
gamma <- new(Gamma, shape = sh, rate = r)
flexsurv::hgamma(4, shape = sh, rate = r))
flexsurv::Hgamma(4, shape = sh, rate = r))
r <- replicate(10, gamma$trandom(0, 11))
lnorm <- new(Lognormal, meanlog = m, sdlog = s)
flexsurv::hlnorm(4, meanlog = m, sdlog = s))
flexsurv::Hlnorm(4, meanlog = m, sdlog = s))
r <- replicate(10, lnorm$trandom(10, 21))
gomp <- new(Gompertz, shape = sh, rate = r)
flexsurv::dgompertz(2, shape = sh, rate = r))
flexsurv::pgompertz(1.5, shape = sh, rate = r))
flexsurv::qgompertz(.21, shape = sh, rate = r))
flexsurv::hgompertz(4, shape = sh, rate = r))
flexsurv::Hgompertz(4, shape = sh, rate = r))
r2 <- flexsurv::rgompertz(1, shape = sh, rate = r)
llogis <- new(LogLogistic, shape = sh, scale = sc)
flexsurv::dllogis(2, shape = sh, scale = sc))
flexsurv::pllogis(2, shape = sh, scale = sc))
flexsurv::qllogis(.34, shape = sh, scale = sc))
flexsurv::hllogis(6, shape = sh, scale = sc))
flexsurv::Hllogis(6, shape = sh, scale = sc))
r2 <- flexsurv::rllogis(1, shape = sh, scale = sc)
r <- replicate(10, llogis$trandom(2, 9))
gengamma <- new(GeneralizedGamma, mu = m, sigma = s, Q = q)
flexsurv::dgengamma(2, mu = m, sigma = s, Q = q))
flexsurv::pgengamma(3, mu = m, sigma = s, Q = q))
flexsurv::qgengamma(.3, mu = m, sigma = s, Q = q))
flexsurv::qgengamma(.8, mu = m, sigma = s, Q = q))
} else{ # flexsurv does not seem to be correct with Q = 0.
flexsurv::hgengamma(1.8, mu = m, sigma = s, Q = q))
flexsurv::Hgengamma(1.2, mu = m, sigma = s, Q = q))
r2 <- flexsurv::rgengamma(1, mu = m, sigma = s, Q = q)
r <- replicate(10, gengamma$trandom(2, 9))
test_gengamma(m = 5, s = 2, q = 0) # Q = 0
R_linear_predict <- function(t, gamma, knots, timescale){
knot.min <- knots[1];  knot.max <- knots[length(knots)]
lambda.j <- (knot.max - knots[j])/(knot.max - knot.min)
basis[j + 1] <- basis_cube(t.scaled - knots[j]) -
lambda.j * basis_cube(t.scaled - knot.min) -
(1 - lambda.j) * basis_cube(t.scaled - knot.max)
test_survspline1 <- function(gamma, knots, timescale){
spline <- new(SurvSpline, gamma = gamma, knots = knots,
scale = "log_hazard", timescale = timescale,
exp(R_linear_predict(t, gamma = gamma, knots = knots,
expect_equal(spline$quantile(spline$cdf(.55)), .55, tolerance = .001, scale = 1)
r <- replicate(10, spline$trandom(2, 2.5))
test_survspline1(gamma = g, knots = k, timescale = "identity")
test_survspline1(gamma = g, knots = k, timescale = "log")
# scale is log cummulative hazard, log odds, or normal
spl_fit <- flexsurvspline(Surv(recyrs, censrec) ~ 1,
data = bc, k = 1, timescale = timescale,
scale = hesim_scale, timescale = timescale,
cumhaz_method = "quad", step = -1, random_method = "invcdf")
expect_equal(flexsurv::dsurvspline(5, gamma = gamma, knots = knots,
scale = flexsurv_scale, timescale = timescale),
expect_equal(flexsurv::psurvspline(5, gamma = gamma, knots = knots,
expect_equal(flexsurv::qsurvspline(.8, gamma = gamma, knots = knots,
expect_equal(flexsurv::hsurvspline(3, gamma = gamma, knots = knots,
expect_equal(flexsurv::Hsurvspline(3, gamma = gamma, knots = knots,
r1 <- rsurvspline(1, gamma = gamma, knots = knots,
scale = flexsurv_scale, timescale = timescale)
expect_equal(r1, r2, tolerance = .001, scale = 1)
r <- replicate(10, spline$trandom(2, 5))
test_survspline2(flexsurv_scale = "hazard", timescale = "log")
test_survspline2(flexsurv_scale = "hazard", timescale = "identity")
test_survspline2(flexsurv_scale = "odds", timescale = "log")
test_survspline2(flexsurv_scale = "odds", timescale = "identity")
test_survspline2(flexsurv_scale = "normal", timescale = "log")
test_survspline2(flexsurv_scale = "normal", timescale = "identity",
return(exp(c(gamma %*% t(cbind(1, bfp(t, powers))))))
c(gamma %*% t(cbind(1, bfp(t, powers))))
fp <- new(FracPoly, gamma = gamma, powers = powers,
### Using numeric quantile when max_x_ is infinity
### Using discrete cumulative hazard otherwise
expect_error(fp$random(), NA) # See manual tests for correctness
# Equivalence of fractional polynomial and gompertz
fp <- new(FracPoly, gamma = c(log(rate), shape), powers = 1,
flexsurv::hgompertz(5, shape = shape, rate = rate))
flexsurv::pgompertz(2, shape = shape, rate = rate))
# Equivalence of fractional polynomial and weibull
fp <- new(FracPoly, gamma = c(a0, a1), powers = 0,
expect_equal(pm$trandom(1, Inf), est + 1)
expect_equal(pm$trandom(5, Inf), est + 5)
samp1 <- replicate(n, hesim:::C_test_rtruncnorm(mu, sigma, lower, upper))
samp3 <- truncnorm::rtruncnorm(n, lower, upper, mu, sigma)

"hesim does not currently support sampling from a piecewise "
"exponential distribution truncated from above."
# flexsurv does not seem to be correct with Q = 0.