Predictions from a fit loaded out of a SAS OUTHAZ= dataset
Source: R/read-outhaz.R
predict.hzr_outhaz.RdRebuilds the multiphase model the OUTHAZ= dataset describes – which
phases are in it, their shapes, and the fitted parameter vector – and then
predicts exactly as predict.hazard() does.
Arguments
- object
An
hzr_outhazobject fromhzr_read_outhaz().- newdata
Data frame with a
timecolumn. Required.- type
One of
"hazard","survival"or"cumulative_hazard"; default"hazard", as inpredict.hazard().- decompose
Accepted only to keep this method's argument list identical to
predict.hazard()'s, so that a positional call means the same thing for both.TRUEis an error: anOUTHAZ=dataset names its phases but carries no per-phase decomposition, and silently returning the total prediction instead would answer a question that was not asked.- se.fit
Logical; add delta-method standard errors and confidence limits, as
predict.hazard()does.- level
Numeric confidence level in
(0, 1); default0.95. Only used whense.fit = TRUE.SAS draws narrower bands than this by default.
PROC HAZPREDtakes its width fromCLEVEL, whose default is0.68268948— documented in the macro source as "(1 sd)" — so itsT_ALPHAmultiplier is1to seven decimals (the literal is truncated) and the band is one standard error, 68.3%, not 95%. Reproducing a SAS figure at this function's default therefore yields a band about 1.96 times wider than the one being checked against, with no error and no warning on either side. Pass the SAS level explicitly to match:predict(fit, newdata, type = "survival", se.fit = TRUE, level = 2 * stats::pnorm(1) - 1, conf.type = "logit")The default is left at
0.95deliberately: it is the right R-side default, and silently adopting SAS's would make this method disagree with every other R modelling function.- conf.type
Transform for
type = "survival"confidence limits whense.fit = TRUE:"log-log"(default) or"logit", which reproduces SASPROC HAZPRED's survival limits. A real argument rather than part of...because a misspelling would otherwise be swallowed silently and return log-log limits that disagree with the SAS job being reproduced. As inpredict.hazard(), the value is checked only where it is used, so an ignored one does not make a point or hazard prediction fail.- ...
Must be empty. Anything landing here is an error rather than a silently ignored argument.
Value
What predict.hazard() returns for a fit with no covariates: a
numeric vector of predictions when se.fit = FALSE, and when
se.fit = TRUE a data frame with columns fit, se.fit, lower and
upper (the confidence limits at level). The decomposed long-format
return of predict.hazard() is not reachable here, because
decompose = TRUE is refused.
Details
newdata is required. An OUTHAZ= dataset holds a converged model and no
data, so there is no fitted time vector to fall back on; without newdata
the prediction would be over nothing.
What is reconstructed, and what is refused
A phase is in the model when its intercept row (E0, C0, L0) carries
_STATUS_ = 1, which is the test PROC HAZPRED itself applies. The early
phase becomes hzr_phase("cdf") and the late phase hzr_phase("g3"), with
the shape estimates read off the DELTA/THALF/NU/M and
TAU/GAMMA/ALPHA/ETA rows.
These cases error rather than return a number that looks like a
prediction: a dataset carrying covariates (their coefficients cannot be
matched to newdata columns from the file alone); a non-zero DELTA (the
early-phase time transformation is not implemented); and a G1FLAG that
disagrees with the signs of the M and NU estimates.
With se.fit = TRUE there are three more, because the stored covariance is
on SAS's estimation scale and has to be mapped onto this package's:
a fit constrained by
FIXMNU1, which tiesMto1/NU;a fit estimating
GAMMA,ALPHAorETAon one of PROC HAZARD's composite late-phase scales –log(GAMMA*ETA - 2)orlog(GAMMA*ETA/ALPHA - 2)rather thanlog()of the parameter. This is the ordinary unconstrained late phase, not an exotic case: withG3FLAG = 1and noFIXGE2/FIXGAE2,ETAandALPHAare always on a composite scale andGAMMAis wheneverETAis fixed. So an early + constant + late fit with any free late shape gets point predictions but no standard errors;a fit under
FIXGE2orFIXGAE2where a late parameter is derived from an estimated one (ETA = 2/GAMMA,GAMMA = 2/ETA,ALPHA = GAMMA*ETA/2). The derived parameter has no covariance row, so its contribution to the variance would be dropped without trace.
Examples
f <- system.file("extdata", "outhaz-fixture.rds", package = "TemporalHazard")
if (nzchar(f)) {
fit <- hzr_read_outhaz(f)
predict(fit, newdata = data.frame(time = c(1, 6, 12)), type = "survival")
}
#> [1] 0.9064419 0.7547405 0.6075586