I am working on competing risk analysis in R thanks to a Fine & Gray regression analysis. Here is my code with death as the competing risk:
fg.model <- crr(ftime,fstatus,cov,failcode=1,cencode=0)
ftime is a numerical variable ranging from 1 to 180 days that indicates the period of follow-up of patients until their death (fstatus==1). If they are still alive until the end of the follow-up, this variable is equal to 180 days and their status is equal to 0. In summary, If a person dies after 30 days of follow-up, the variable ftime will therefore be equal to 30 days and the variable fstatus to 1 and if a person is still alive after the end of the follow-up (max 180 days) and did not die during it, the variable ftime will therefore be equal to 180 and the variable fstatus to 0. fstatus is also a numerical variable.
The parameter "cov" is a dataframe with two covariates (age and sex converted in factors). Failcode is equal to 1 as death is the competing event and cencode is equal to 0 as survivors as considered as censored.
I have the following error message:
# NAs introduced by coercion Error in crr(ftime,fstatus,cov,failcode=1, :
# NAs introduced by coercion NA/NaN/inf in foreign function call(arg4)
Since I have no missing data in my database, what can explain this error message and how can I solve it?
I already tried to use na.omit
, complete.case
, and other code to be sure that there is no missing data in my code. I also check the structure of the data but time and status are well numerical and cov converted in factors.
Here is a code reproducing my dataset and the error message:
# Set the sample size
n<- 8076
# CReate a variable for follow-up time
time<- c(rep(180,6533),sample(1:179,n-6533,replace = TRUE))
# Create a variable for status
status<-ifelse(time==180,0,1) # O= alive/censored
# 1 = death
# Create age
age<-sample(18:90,n,replace = TRUE)
# Create gender
sex<-sample(c("male","female"),n,replace = TRUE)
# Combine
df<-data.frame(time,status,age,sex)
# Create cov
cov<-subset(df,select = c("age","sex"))
cov$sex<-as.factor(cov$sex)
# Run Fine Gray model
library(cmprsk)
fg.mod <-crr(df$time,df$status,cov,failcode = 1,cencode = 0)