I am analysing a set of lifespan data based on a population of animals (C. elegans) and I'm not sure if I have the data set up incorrectly or I'm using the Surv function incorrectly.
I have a table with the number of days since the start and the number of animals alive on each day. I am not tracking individual animals, but the total number. I've tried having the number that died instead but that didn't change the error message I'm getting.
The data I'm using:
data = matrix (c(0,143,2,28,3,126,4,103,6,102,7,100,8,88,9,70,10,51,11,44,13,27,15,10,17,4,18,3,20,2,22,2,24,0), ncol=2, byrow = TRUE)
colnames(data) <- c("Day", "Survival")
The code I have at the moment:
data <- data %>%
Surv (time = as.numeric("Day"), event = as.numeric("Survival"))
Note: I am using as.numeric
because I am importing a CSV file and the column is marked as <dbl>
The full error message I get:
Error in Surv(., time = as.numeric("Day"), event = as.numeric("Survival")) :
Start and stop are different lengths
In addition: Warning message:
In Surv(., time = as.numeric("Day"), event = as.numeric("Survival")) :
NAs introduced by coercion
Any advice is appreciated. Thank you.