Skip to content

Instantly share code, notes, and snippets.

@MarcusWalz
MarcusWalz / tidy_survfit.R
Last active July 29, 2016 16:58
Survival Plot with ggplot
require(ggplot2)
require(dplyR)
# Convert Survfit object to tidy data frame. survival = TRUE means at x = 0 y = 1 (descending upon event)
# and FALSE means x = 0 y = 0 (ascending)
tidy_km = function( survfit, strata_names = NULL, survival = FALSE) {
#
tidy_single_strata = function ( strata ) {
print(strata$surv)
data_frame(
@MarcusWalz
MarcusWalz / Probability of Entry
Last active November 18, 2015 13:12
Western States 100 Lottery Simulator
entrants tickets expected_winners prob
1 1981 1981 64.98780 0.03280555
2 890 1780 57.54135 0.06465320
3 390 1560 48.80195 0.12513321
4 189 1512 44.29210 0.23434974
5 79 1264 32.71075 0.41406013
6 33 1056 21.66605 0.65654697
sums 3562 9153 270.00000 1.52754879