Hi, When I run the survfit function, I want to get the restricted mean value and the standard error also. I found out using the "print" function to do so, as shown below, print(km.fit,print.rmean=TRUE) Call: survfit(formula = Surv(diff, status) ~ 1, type = "kaplan-meier") records n.max n.start events *rmean *se(rmean) median 200.000 200.000 200.000 129.000 0.145 0.237 1.158 0.95LCL 0.95UCL 0.450 1.730 * restricted mean with upper limit = 2.97 The questions is, is there any way to extract these values from the print command? Thanks a lot. Xueke
--- begin inclusion-- Hi, When I run the survfit function, I want to get the restricted mean value and the standard error also. I found out using the "print" function to do so, as shown below, .... The questions is, is there any way to extract these values from the print command? ----- end inclusion --- Use sfit <- summary(fit). Then sfit$table contains the data the the print method produces. No, there isn't a way to extract them from the print command; the standard in S/R is for all print commands to return the object passed to them, without embellisment. Terry Therneau
Here is a worked example. Can you point out to me where in temp rmean is stored? Thanks. Tom> library(survival) > library(ISwR) > > dat.s <- Surv(melanom$days,melanom$status==1) > fit <- survfit(dat.s~1) > plot(fit) > summary(fit)Call: survfit(formula = dat.s ~ 1) time n.risk n.event survival std.err lower 95% CI upper 95% CI 185 201 1 0.995 0.00496 0.985 1.000 204 200 1 0.990 0.00700 0.976 1.000 210 199 1 0.985 0.00855 0.968 1.000 232 198 1 0.980 0.00985 0.961 1.000 279 196 1 0.975 0.01100 0.954 0.997 295 195 1 0.970 0.01202 0.947 0.994 386 193 1 0.965 0.01297 0.940 0.991 426 192 1 0.960 0.01384 0.933 0.988 469 191 1 0.955 0.01465 0.927 0.984 529 189 1 0.950 0.01542 0.920 0.981 621 188 1 0.945 0.01615 0.914 0.977 629 187 1 0.940 0.01683 0.907 0.973 659 186 1 0.935 0.01748 0.901 0.970 667 185 1 0.930 0.01811 0.895 0.966 718 184 1 0.925 0.01870 0.889 0.962 752 183 1 0.920 0.01927 0.883 0.958 779 182 1 0.915 0.01981 0.877 0.954 793 181 1 0.910 0.02034 0.871 0.950 817 180 1 0.904 0.02084 0.865 0.946 833 178 1 0.899 0.02134 0.859 0.942 858 177 1 0.894 0.02181 0.853 0.938 869 176 1 0.889 0.02227 0.847 0.934 872 175 1 0.884 0.02272 0.841 0.930 967 174 1 0.879 0.02315 0.835 0.926 977 173 1 0.874 0.02357 0.829 0.921 982 172 1 0.869 0.02397 0.823 0.917 1041 171 1 0.864 0.02436 0.817 0.913 1055 170 1 0.859 0.02474 0.812 0.909 1062 169 1 0.854 0.02511 0.806 0.904 1075 168 1 0.849 0.02547 0.800 0.900 1156 167 1 0.844 0.02582 0.794 0.896 1228 166 1 0.838 0.02616 0.789 0.891 1252 165 1 0.833 0.02649 0.783 0.887 1271 164 1 0.828 0.02681 0.777 0.883 1312 163 1 0.823 0.02713 0.772 0.878 1435 161 1 0.818 0.02744 0.766 0.874 1506 159 1 0.813 0.02774 0.760 0.869 1516 155 1 0.808 0.02805 0.755 0.865 1548 152 1 0.802 0.02837 0.749 0.860 1560 150 1 0.797 0.02868 0.743 0.855 1584 148 1 0.792 0.02899 0.737 0.851 1621 146 1 0.786 0.02929 0.731 0.846 1667 137 1 0.780 0.02963 0.725 0.841 1690 134 1 0.775 0.02998 0.718 0.836 1726 131 1 0.769 0.03033 0.712 0.831 1933 110 1 0.762 0.03085 0.704 0.825 2061 95 1 0.754 0.03155 0.694 0.818 2062 94 1 0.746 0.03221 0.685 0.812 2103 90 1 0.737 0.03290 0.676 0.805 2108 88 1 0.729 0.03358 0.666 0.798 2256 80 1 0.720 0.03438 0.656 0.791 2388 75 1 0.710 0.03523 0.645 0.783 2467 69 1 0.700 0.03619 0.633 0.775 2565 63 1 0.689 0.03729 0.620 0.766 2782 57 1 0.677 0.03854 0.605 0.757 3042 52 1 0.664 0.03994 0.590 0.747 3338 35 1 0.645 0.04307 0.566 0.735> > print(fit, print.rmean=TRUE)Call: survfit(formula = dat.s ~ 1) records n.max n.start events *rmean *se(rmean) median 205 205 205 57 4125 161 NA 0.95LCL 0.95UCL NA NA * restricted mean with upper limit = 5565> > temp <- summary(fit) > str(temp)List of 12 $ surv : num [1:57] 0.995 0.99 0.985 0.98 0.975 ... $ time : num [1:57] 185 204 210 232 279 295 386 426 469 529 ... $ n.risk : num [1:57] 201 200 199 198 196 195 193 192 191 189 ... $ n.event : num [1:57] 1 1 1 1 1 1 1 1 1 1 ... $ conf.int: num 0.95 $ type : chr "right" $ table : Named num [1:7] 205 205 205 57 NA NA NA ..- attr(*, "names")= chr [1:7] "records" "n.max" "n.start" "events" ... $ n.censor: num [1:57] 0 0 0 1 0 0 0 0 0 0 ... $ std.err : num [1:57] 0.00496 0.007 0.00855 0.00985 0.011 ... $ lower : num [1:57] 0.985 0.976 0.968 0.961 0.954 ... $ upper : num [1:57] 1 1 1 1 0.997 ... $ call : language survfit(formula = dat.s ~ 1) - attr(*, "class")= chr "summary.survfit" -- View this message in context: http://r.789695.n4.nabble.com/simple-save-question-tp3429148p3663170.html Sent from the R help mailing list archive at Nabble.com.
On Jul 12, 2011, at 2:31 PM, Tom La Bone wrote:> > Here is a worked example. Can you point out to me where in temp > rmean is > stored? Thanks.It is not. You need to read the ?print.survfit page: Value x, with the invisible flag set to prevent printing. (The default for all print functions in R is to return the object passed to them; print.survfit follows the pattern. If you want to capture these printed results for further processing, see the table component of summary.survfit.) -- David.> > Tom > > >> library(survival) >> library(ISwR) >> >> dat.s <- Surv(melanom$days,melanom$status==1) >> fit <- survfit(dat.s~1) >> plot(fit) >> summary(fit) > Call: survfit(formula = dat.s ~ 1) > > time n.risk n.event survival std.err lower 95% CI upper 95% CI > 185 201 1 0.995 0.00496 0.985 1.000 > 204 200 1 0.990 0.00700 0.976 1.000 > 210 199 1 0.985 0.00855 0.968 1.000 > 232 198 1 0.980 0.00985 0.961 1.000 > 279 196 1 0.975 0.01100 0.954 0.997 > 295 195 1 0.970 0.01202 0.947 0.994 > 386 193 1 0.965 0.01297 0.940 0.991 > 426 192 1 0.960 0.01384 0.933 0.988 > 469 191 1 0.955 0.01465 0.927 0.984 > 529 189 1 0.950 0.01542 0.920 0.981 > 621 188 1 0.945 0.01615 0.914 0.977 > 629 187 1 0.940 0.01683 0.907 0.973 > 659 186 1 0.935 0.01748 0.901 0.970 > 667 185 1 0.930 0.01811 0.895 0.966 > 718 184 1 0.925 0.01870 0.889 0.962 > 752 183 1 0.920 0.01927 0.883 0.958 > 779 182 1 0.915 0.01981 0.877 0.954 > 793 181 1 0.910 0.02034 0.871 0.950 > 817 180 1 0.904 0.02084 0.865 0.946 > 833 178 1 0.899 0.02134 0.859 0.942 > 858 177 1 0.894 0.02181 0.853 0.938 > 869 176 1 0.889 0.02227 0.847 0.934 > 872 175 1 0.884 0.02272 0.841 0.930 > 967 174 1 0.879 0.02315 0.835 0.926 > 977 173 1 0.874 0.02357 0.829 0.921 > 982 172 1 0.869 0.02397 0.823 0.917 > 1041 171 1 0.864 0.02436 0.817 0.913 > 1055 170 1 0.859 0.02474 0.812 0.909 > 1062 169 1 0.854 0.02511 0.806 0.904 > 1075 168 1 0.849 0.02547 0.800 0.900 > 1156 167 1 0.844 0.02582 0.794 0.896 > 1228 166 1 0.838 0.02616 0.789 0.891 > 1252 165 1 0.833 0.02649 0.783 0.887 > 1271 164 1 0.828 0.02681 0.777 0.883 > 1312 163 1 0.823 0.02713 0.772 0.878 > 1435 161 1 0.818 0.02744 0.766 0.874 > 1506 159 1 0.813 0.02774 0.760 0.869 > 1516 155 1 0.808 0.02805 0.755 0.865 > 1548 152 1 0.802 0.02837 0.749 0.860 > 1560 150 1 0.797 0.02868 0.743 0.855 > 1584 148 1 0.792 0.02899 0.737 0.851 > 1621 146 1 0.786 0.02929 0.731 0.846 > 1667 137 1 0.780 0.02963 0.725 0.841 > 1690 134 1 0.775 0.02998 0.718 0.836 > 1726 131 1 0.769 0.03033 0.712 0.831 > 1933 110 1 0.762 0.03085 0.704 0.825 > 2061 95 1 0.754 0.03155 0.694 0.818 > 2062 94 1 0.746 0.03221 0.685 0.812 > 2103 90 1 0.737 0.03290 0.676 0.805 > 2108 88 1 0.729 0.03358 0.666 0.798 > 2256 80 1 0.720 0.03438 0.656 0.791 > 2388 75 1 0.710 0.03523 0.645 0.783 > 2467 69 1 0.700 0.03619 0.633 0.775 > 2565 63 1 0.689 0.03729 0.620 0.766 > 2782 57 1 0.677 0.03854 0.605 0.757 > 3042 52 1 0.664 0.03994 0.590 0.747 > 3338 35 1 0.645 0.04307 0.566 0.735 >> >> print(fit, print.rmean=TRUE) > Call: survfit(formula = dat.s ~ 1) > > records n.max n.start events *rmean *se(rmean) > median > 205 205 205 57 4125 > 161 NA > 0.95LCL 0.95UCL > NA NA > * restricted mean with upper limit = 5565 >> >> temp <- summary(fit) >> str(temp) > List of 12 > $ surv : num [1:57] 0.995 0.99 0.985 0.98 0.975 ... > $ time : num [1:57] 185 204 210 232 279 295 386 426 469 529 ... > $ n.risk : num [1:57] 201 200 199 198 196 195 193 192 191 189 ... > $ n.event : num [1:57] 1 1 1 1 1 1 1 1 1 1 ... > $ conf.int: num 0.95 > $ type : chr "right" > $ table : Named num [1:7] 205 205 205 57 NA NA NA > ..- attr(*, "names")= chr [1:7] "records" "n.max" "n.start" > "events" ... > $ n.censor: num [1:57] 0 0 0 1 0 0 0 0 0 0 ... > $ std.err : num [1:57] 0.00496 0.007 0.00855 0.00985 0.011 ... > $ lower : num [1:57] 0.985 0.976 0.968 0.961 0.954 ... > $ upper : num [1:57] 1 1 1 1 0.997 ... > $ call : language survfit(formula = dat.s ~ 1) > - attr(*, "class")= chr "summary.survfit" > > > -- > View this message in context: http://r.789695.n4.nabble.com/simple-save-question-tp3429148p3663170.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT
Thank you for the reply Dr. Winsemius. Can you take your answer a step further and, in the context of the simple, reproducible example, illustrate how it is done? I would appreciate it. Tom -- View this message in context: http://r.789695.n4.nabble.com/simple-save-question-tp3429148p3663645.html Sent from the R help mailing list archive at Nabble.com.
On Jul 13, 2011, at 7:34 AM, Tom La Bone wrote:> > Well, that took a bit of detective work!It was a lot more work to do it "my way" than doing it the "right way", which would have been to read the help page more carefully.> Thanks. I am still not doing > something right here in my efforts to implement the "easy way". Can > you > point out my error? >> >> library(survival) >> library(ISwR) >> dat.s <- Surv(melanom$days,melanom$status==1) >> fit <- survfit(dat.s~1) >> print(fit, print.rmean=TRUE) > Call: survfit(formula = dat.s ~ 1) > > records n.max n.start events *rmean *se(rmean) > median > 205 205 205 57 4125 > 161 NA > 0.95LCL 0.95UCL > NA NA > * restricted mean with upper limit = 5565 >> sfit <- summary(fit) >> sfit$table[ ,5] > Error in sfit$table[, 5] : incorrect number of dimensionsIn your case, you only have one row and R drops the superfluous dimension so : > sfit$table[5] *rmean 4124.8> > > -- > View this message in context: http://r.789695.n4.nabble.com/simple-save-question-tp3429148p3664808.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT
No cigar. This is what I get and my session info. Any suggestions?> > library(survival) > library(ISwR) > dat.s <- Surv(melanom$days,melanom$status==1) > fit <- survfit(dat.s~1) > print(fit, print.rmean=TRUE)Call: survfit(formula = dat.s ~ 1) records n.max n.start events *rmean *se(rmean) median 205 205 205 57 4125 161 NA 0.95LCL 0.95UCL NA NA * restricted mean with upper limit = 5565> sfit <- summary(fit) > sfit$table[5]median NA> sessionInfo()R version 2.13.1 (2011-07-08) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] splines stats graphics grDevices utils datasets methods [8] base other attached packages: [1] ISwR_2.0-5 survival_2.36-9 rj_0.5.5-4 loaded via a namespace (and not attached): [1] tools_2.13.1 -- View this message in context: http://r.789695.n4.nabble.com/simple-save-question-tp3429148p3665289.html Sent from the R help mailing list archive at Nabble.com.