Well, after a little research I found the answer to my question, so here is the code that allows the simulation:
simulation <- function(n,lambda,changepoint, surv.df=TRUE) {
# Define the covariate, restrictions and parameters.
X <- rbinom(n,prob=1/3,size=1)
E <- rexp(n,1)
EL <- rexp(n,lambda)
# Define the piecewise function.
Y <- ifelse(X==0,E,
ifelse(E<=changepoint,E,changepoint+EL))
## Construction of the data frame.
if (surv.df) data.frame(Y,X) else cbind(Y,X)
}
Now, if we would like to do m Monte Carlo replicas of this dataframe:
m = "number of replicas"
survive.df <- replicate(m, simulation(n = 100 ,lambda = 1,changepoint = 1), simplify=FALSE)
To view an i dataset:
survive.df[[i]]
Shape a Cox Proportional Hazards Model with the i dataset:
coxph(Surv(Y)~X , data=survive.df[[i]]) # Model.
cox.zph(coxph(Surv(Y)~X , data=survive.df[[i]])) # Schoenfield residuals.
Any suggestions?
cox.zph
function in order to compute Schoenfield residuals, but my main question resides on how to express this statement more formally in a mathematical way (although I'm not sure if it's already enough), and additionally, how to translate it in R code, because I don't know which object / function I can applycox.zph
. Many thanks for your consideration. $\endgroup$coxph
andcox.zph
functions. $\endgroup$survival
andrms
packagecox.zph
function when using"identity"
as the transformation in plotting directly estimates $\beta(t)$. To put such an estimate into action would require a model to be fitted, such as a Cox model with time-dependent covariates, or a parametric version of same. $\endgroup$