R version 3.1.1 (2014-07-10) -- "Sock it to Me" Copyright (C) 2014 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin10.8.0 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [R.app GUI 1.65 (6784) x86_64-apple-darwin10.8.0] [History restored from /Users/KendraRitchie/.Rapp.history] Loading required package: splines starting httpd help server ... done > load(".RData") Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection In addition: Warning message: In readChar(con, 5L, useBytes = TRUE) : cannot open compressed file '.RData', probable reason 'No such file or directory' > getwd() [1] "/Users/KendraRitchie" > survival <- read.table("SurvivalExp1and2.csv", sep = ",", header = TRUE) Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'SurvivalExp1and2.csv': No such file or directory > getwd() [1] "/Users/KendraRitchie" > getwd() [1] "/Users/KendraRitchie/Desktop/Data/Survival" > survival <- read.table("SurvivalExp1and2.csv", sep = ",", header = TRUE) > survival id time group status 1 KR49 60 1 1 2 KR126 60 1 1 3 KR130 60 1 1 4 KR81 60 1 1 5 KR11 60 1 1 6 KR52 60 1 1 7 KR150 60 1 1 8 KR102 60 1 1 9 KR163 60 1 1 10 KR78 60 1 1 11 KR181 60 1 1 12 KR153 60 1 1 13 KR12 60 1 1 14 KR42 60 2 1 15 KR115 60 2 1 16 KR172 60 2 1 17 KR51 60 2 1 18 KR57 60 2 1 19 KR166 60 2 1 20 KR31 60 2 1 21 KR58 60 2 1 22 KR132 60 2 1 23 KR6 60 2 1 24 KR35 60 2 1 25 KR128 60 2 1 26 KR26 60 2 1 27 KR28 60 2 1 28 KR50 60 2 1 29 KR62 60 2 1 30 KR122 60 2 1 31 KR136 60 2 1 32 KR44 60 2 1 33 KR100 60 2 1 34 KR156 60 2 1 35 KR37 60 2 1 36 KR104 24 2 2 37 KR119 60 2 1 38 KR17 60 2 1 39 KR21 60 2 1 40 KR82 60 2 1 41 KR33 60 2 1 42 KR84 60 2 1 43 KR158 60 2 1 44 KR18 60 2 1 45 KR20 60 2 1 46 KR40 60 2 1 47 KR9 60 2 1 48 KR30 60 2 1 49 KR80 60 2 1 50 KR72 60 2 1 51 KR116 60 2 1 52 KR161 60 2 1 53 1 30 3 2 54 2 22 3 2 55 3 25 3 2 56 4 43 3 1 57 5 25 3 2 58 6 22 3 2 59 7 15 3 2 60 8 29 3 2 61 9 22 4 2 62 10 43 4 1 63 11 16 4 2 64 12 30 4 2 65 13 32 4 2 66 14 43 4 1 67 15 43 4 1 68 16 43 4 2 > survival$SurvObj <- with(survival, Surv(time, status == 2)) > head(survival) id time group status SurvObj 1 KR49 60 1 1 60+ 2 KR126 60 1 1 60+ 3 KR130 60 1 1 60+ 4 KR81 60 1 1 60+ 5 KR11 60 1 1 60+ 6 KR52 60 1 1 60+ > km.as.one <- survfit(SurvObj ~ 1, data = survival, conf.type = "log-log") > km.by.status <- survfit(SurvObj ~ status, data = survival, conf.type = "log-log") > km.as.one Call: survfit(formula = SurvObj ~ 1, data = survival, conf.type = "log-log") records n.max n.start events median 0.95LCL 0.95UCL 68 68 68 13 NA NA NA > summary(km.as.one) Call: survfit(formula = SurvObj ~ 1, data = survival, conf.type = "log-log") time n.risk n.event survival std.err lower 95% CI upper 95% CI 15 68 1 0.985 0.0146 0.900 0.998 16 67 1 0.971 0.0205 0.887 0.993 22 66 3 0.926 0.0317 0.832 0.969 24 63 1 0.912 0.0344 0.814 0.959 25 62 2 0.882 0.0391 0.778 0.939 29 60 1 0.868 0.0411 0.761 0.929 30 59 2 0.838 0.0447 0.727 0.907 32 57 1 0.824 0.0462 0.710 0.896 43 56 1 0.809 0.0477 0.694 0.884 > plot(km.as.one) > km.by.group <- survfit(SurvObj ~ group, data = survival, conf.type = "log-log") > plot(km.by.group) > survdiff(SurvObj ~ group, data = survival, rho = 0) Call: survdiff(formula = SurvObj ~ group, data = survival, rho = 0) N Observed Expected (O-E)^2/E (O-E)^2/V group=1 13 0 2.719 2.72 3.48 group=2 39 1 8.040 6.16 16.43 group=3 8 7 0.934 39.39 43.88 group=4 8 5 1.307 10.44 11.77 Chisq= 60.7 on 3 degrees of freedom, p= 4.13e-13 > plot(km.by.group, col=c(1,2,3,4)) > plot(km.by.group, lty=c(0,1,2,3)) > plot(km.by.group, lty=c(1,2,3,4)) > text(45, .075, 'test') > text() Error in as.graphicsAnnot(labels) : argument "x" is missing, with no default > legend(5, 0.1, lty=c(1,2,3,4)) Error in as.graphicsAnnot(legend) : argument "legend" is missing, with no default > legend(5, 0.1, title='Group', c(1,2,3,4), lty=c(1,2,3,4)) > legend(5, 0.4, title='Group', c(1,2,3,4), lty=c(1,2,3,4)) > > legend(5, 1, title='Group', c('lame','loser','Rsux','hi'), lty=c(1,2,3,4)) > > axis(side=1, at=seq(0,60,5)) > axis(side=2, at=seq(0,1,0.1)) > axis(side=2, at=seq(0,1,0.1), las=1) > > plot(km.by.group, lty=c(1,2,3,4), axis=NULL) > plot(km.by.group, lty=c(1,2,3,4), axes=FALSE) > axis(side=1, at=seq(0,60,5)) > axis(side=2, at=seq(0,1,0.1), las=1) > plot(km.by.group, lty=c(1,2,3,4)) > plot(km.by.group, lty=c(1,2,3,4), axes=FALSE) > plot(km.by.group, lty=c(1,2,3,4), axes=FALSE, frame.plot=T) > axis(side=1, at=seq(0,60,5)) > axis(side=2, at=seq(0,1,0.1), las=1) > legend(5, 0.5, c('1,2,3,4'), lty=c(1,2,4,3)) > > legend(5, 0.5, c('1','2','3','4'), lty=c(1,2,4,3)) > legend(5, 0.3, c('1','2','3','4'), lty=c(1,2,4,3)) > legend(5, 0.3, c('control,solitary','control, trio','focal, pair','focal,group'), lty=c(1,2,4,3)) > plot(km.by.group, lty=c(1,2,3,4), axes=FALSE, frame.plot=T) > > axis(side=1, at=seq(0,60,5)) Error: unexpected '>' in ">" > > axis(side=2, at=seq(0,1,0.1), las=1) Error: unexpected '>' in ">" > > > axis(side=1, at=seq(0,60,5)) > axis(side=2, at=seq(0,1,0.1), las=1) > legend(5, 0.2, c('control, solitary', 'control, trio', 'focal, pair', 'focal, group'), lty=c(1,2,4,3)) > plot(km.by.group, lty=c(1,2,3,4), axes=F, frame.plot=T, xlab='Days', ylab='Proportion Surviving') > axis(side=1, seq(0,60,5)) > axis(side=2, seq(0,1, 0.1), las=1) > legend(5, 0.2, c('control, solitary', 'control, trio', 'focal, pair', 'focal, group'), lty=c(1,2,4,3)) >