I found myself repeating an analysis I don't fully understand.
chisq_data <- data.frame(rx = c(rep(1, 7), rep(2,7)) ,Vital.Status = rep(1, 14) ,EFS = (c(150, 260, 110, 111, 550, 1, 1, 1,140 , 60, 1, 70, 1, 1)) )
I then want to know whether survival of the two groups defined in the
rx column as
2 is different. I use the
survdiff(Surv(chisq_data$EFS, chisq_data$Vital.Status) ~ rx, data = chisq_data)
And get this output:
Call: survdiff(formula = Surv(chisq_data$EFS, chisq_data$Vital.Status) ~ rx, data = chisq_data) N Observed Expected (O-E)^2/E (O-E)^2/V rx=1 7 7 9.72 0.762 4.01 rx=2 7 7 4.28 1.733 4.01 Chisq= 4 on 1 degrees of freedom, p= 0.05
I think I understand what the
p= 0.04 means. It tests the hypothesis that my groups
2 come from the same population/distribution. What I don't understand is where do these
Expected values come from (and in fact the other values, but it's the
Expected column that I would mostly like to understand). What do they mean?
Because chi-square test is used, and it works on categorical data, I would also like to know how the 'categories' for this test are created.
In the end, I would like to do power analysis using this dataset as my preliminary dataset. How many more samples do I need to get
p<0.001? I am not sure how to go about it, either, but I feel understanding this first step is necessary to know what to do next.
Following @EdM's answer, I have some follow up/clarifying questions.
@EdM now addresses all what I wrote below in his edited response. What I write below is incorrect because I calculated cumulative number of events rather than number at each time point - see the answer below for a correct data. I am leaving this here as it might be helpful to some to see where my thinking was incorrect
If I understood the answer correctly, the number of events in each of three groups (all,
rx2) is calculated at each time point. It would produce a table as follows:
EFS prob_dead_all prob_dead_r1 prob_dead_r2 1 1 0.4285714 0.5714286 0.2857143 2 60 0.5000000 0.7142857 0.2857143 3 70 0.5714286 0.8571429 0.2857143 4 110 0.6428571 0.8571429 0.4285714 5 111 0.7142857 0.8571429 0.5714286 6 140 0.7857143 1.0000000 0.5714286 7 150 0.8571429 1.0000000 0.7142857 8 260 0.9285714 1.0000000 0.8571429 9 550 1.0000000 1.0000000 1.0000000
EFS - time points
prob_dead_all - proportion of events that have occurred by each timepoint for the whole dataset. For example, at timepoint
1, 6 out of 14 people die, and therefore the number is
6/14 = 0.4285714
prob_dead_r1 - proportion of events that occurred by each timepoint in the
rx1 group. For example, at timepoint
1, 4 out of 7 people die, and therefore the number is
4/7 = 0.5714286
prob_dead_r2 - proportion of events that occurred by each timepoint in the
rx2 group. For example, at timepoint
1, 2 out of 7 people die, and therefore the number is
2/7 = 0.2857143
Expected values (shown in the output of the
survdiff()) for each of two groups,
rx2, are calculated at the sum of columns
prob_dead_r2, respectively. However, when I sum up these columns, I see similar, but not identical, results to the
> colSums(chisq_data2 %>% select(-EFS)) prob_dead_all prob_dead_r2 prob_dead_r1 6.428571 5.000000 7.857143