View source: R/predict.unsurv.R
| predict.unsurv | R Documentation |
Assigns new survival-probability curves to clusters using the medoids from a
fitted unsurv object. New curves are preprocessed using the same
weighting, optional monotonic enforcement, smoothing, and standardization
parameters as the fitted model.
## S3 method for class 'unsurv'
predict(object, newdata, clamp = TRUE, ...)
object |
An object of class |
newdata |
Numeric matrix of survival probabilities with shape
|
clamp |
Logical; if |
... |
Unused. Included for compatibility with the generic. |
Cluster assignment is performed by computing distances between the new curves
and the stored medoid curves in the weighted feature space defined during
fitting. The distance metric ("L1" or "L2") and any
standardization parameters are reused from the fitted model.
An integer vector of cluster labels of length nrow(newdata),
taking values in 1, ..., object$K.
if (requireNamespace("cluster", quietly = TRUE)) {
set.seed(1)
n <- 60; Q <- 40
times <- seq(0, 5, length.out = Q)
grp <- sample(1:2, n, TRUE)
rates <- c(0.2, 0.6)
S <- sapply(times, function(t) exp(-rates[grp] * t))
S <- S + matrix(stats::rnorm(n * Q, 0, 0.02), nrow = n)
fit <- unsurv(S, times, K = 2)
# predict cluster membership for first 5 curves
predict(fit, S[1:5, ])
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.