# Some artificial data
set.seed(123)
n <- 50
x <- runif(n, -2, 2) # Covariate values
y <- rweibull(n, shape = 0.5 * (x + 4)) # True lifetimes
c <- rexp(n) # Censoring values
p <- exp(2*x)/(1 + exp(2*x)) # Probability of being susceptible
u <- runif(n)
t <- ifelse(u < p, pmin(y, c), c) # Observed times
delta <- ifelse(u < p, ifelse(y < c, 1, 0), 0) # Uncensoring indicator
# Number of individuals (rows)
n <- 50
# Numbers of observations per individual (columns)
m <- 100
# Observation times (between 0 and 1)
x <- seq(0, 1, length.out = m)
# Auxiliar function to simulate the other functions by adding some noise
# Shift controls the horizontal displacement of the functions
sim_func <- function(x, shift, sd_noise) {
# positive-negative-negative waves
sin(2*pi*(x + shift))+sin(4*pi*(x + shift))-sin(6*pi*(x + shift))+rnorm(m, 0, sd_noise)
}
# Simulated functions
data_matrix <- matrix(NA, nrow=n, ncol=m)
for (i in 1:n) {
shift <- runif(1, -0.05, 0.05)
data_matrix[i, ] <- sim_func(x, shift, sd_noise = 0.03)
}
matplot(x, t(data_matrix), type = "l", lty = 1, ylab='f(x)')
# \donttest{
suppressWarnings(sicure.f(data_matrix, t, delta, 0.9))
# }
Run the code above in your browser using DataLab