Reputation: 155
The question is about the output structure of survdiff() function form the 'survival' library. Namely, I have a data frame containing survival data
> dat
ID Time Treatment Gender Censored
1 E002 2.7597536 IND F 0
2 E003 4.2710472 Control M 0
3 E005 1.4784394 IND F 0
4 E006 6.8993840 Control F 1
5 E008 9.5934292 IND M 0
6 E009 2.9897331 Control F 0
7 E014 1.3470226 IND F 1
8 E016 2.1683778 Control F 1
9 E018 2.7597536 IND F 1
10 E022 1.3798768 IND F 0
11 E023 0.7227926 IND M 1
12 E024 5.5195072 IND F 0
13 E025 2.4640657 Control F 0
14 E028 7.4579055 Control M 1
15 E029 5.5195072 Control F 1
16 E030 2.7926078 IND M 0
17 E031 4.9938398 Control F 0
18 E032 2.7268994 IND M 0
19 E033 0.1642710 IND M 1
20 E034 4.1396304 Control F 0
and a model
> diff = survdiff(Surv(Time, Censored) ~ Treatment+Gender, data = dat)
> diff
Call:
survdiff(formula = Surv(Time, Censored) ~ Treatment + Gender,
data = dat)
N Observed Expected (O-E)^2/E (O-E)^2/V
Treatment=Control, Gender=M 2 1 1.65 0.255876 0.360905
Treatment=Control, Gender=F 7 3 2.72 0.027970 0.046119
Treatment=IND, Gender=M 5 2 2.03 0.000365 0.000519
Treatment=IND, Gender=F 6 2 1.60 0.100494 0.139041
Chisq= 0.5 on 3 degrees of freedom, p= 0.924
I'm wondering what's the field of the output object that contains the values from the very right column (O-E)^2/V? I'd like to use them further but can't obtain them neither from diff$obs, diff$exp, diff$var nor from their combinations.
Your help's gonna be much appreciated.
Upvotes: 1
Views: 1938
Reputation: 1026
You can find that out in a simple way. When you just run the line "diff", you actually invoke print.survdiff(diff)
. You can download the package source for the survival package here, then open the archive file and in the R folder you will find a file containing this function, print.survdiff.S (you can open it with Notepad++ / Sublime / anything that can read R syntax).
As far as I can see, the last column comes from the line
((otmp-etmp)^2)/ diag(x$var)
And otmp
and etmp
are obtained form the object with
if (is.matrix(x$obs)){
otmp <- apply(x$obs,1,sum)
etmp <- apply(x$exp,1,sum)
}
else {
otmp <- x$obs
etmp <- x$exp
}
So you could obtain the same by running this code with diff
instead of x
(although I would advise you not to call your object diff, as that is a base function in R).
Upvotes: 1