2

I'm attempting to make a competing risk survival model using the crr function (cmprsk) in R and through preliminary analysis, I want to transform two of my continuous variables with a restricted cubic spline transformation. Does anyone know of a way to do this akin to the rcs function in the rms package?

Emma
  • 33
  • 5

1 Answers1

1

You can use the splines package when generating your model.matrix

For example. where cov3 and cov4 are your continuous variables that you would like to transform:

covariates <- model.matrix(~cov1 + cov2 + bs(cov3, ...) + ns(cov4, ...), data = df)[,-1]

model <- with(df, crr(ftime, fstatus, covariates, failcode = 1, cencode = 0))

... can include the various options available to the bs (B-spline) or ns (natural cubic spline) functions.

Jon
  • 70
  • 9