lm vs lmer - stanford university
TRANSCRIPT
lm vslmer
R version 2.10.1 (2009-12-14) > library(survival)> #AML data described in Miller p.36; see survival package for description> #aml data in the survival package as leukemia which I renamed aml for typing> data(aml) Warning message: In data(aml) : data set 'aml' not found> data(leukemia) > leukemia time status x time status x 1 9 1 Maintained 12 5 1 Nonmaintained 2 13 1 Maintained 13 5 1 Nonmaintained 3 13 0 Maintained 14 8 1 Nonmaintained 4 18 1 Maintained 15 8 1 Nonmaintained 5 23 1 Maintained 16 12 1 Nonmaintained 6 28 0 Maintained 17 16 0 Nonmaintained 7 31 1 Maintained 18 23 1 Nonmaintained 8 34 1 Maintained 19 27 1 Nonmaintained 9 45 0 Maintained 20 30 1 Nonmaintained 10 48 1 Maintained 21 33 1 Nonmaintained 11 161 0 Maintained 22 43 1 Nonmaintained 23 45 1 Nonmaintained > aml = leukemia > attach(aml)> ?survfit > #fit a Kaplan-Meier and plot it (see plot)> fit = survfit(Surv(time, status) ~ x, data = aml)> plot(fit, lty = 2:3)> legend(100, .8, c("Maintained", "Nonmaintained"), lty = 2:3)> summary(fit)Call: survfit(formula = Surv(time, status) ~ x, data = aml) x=Maintained time n.risk n.event survival std.err lower 95% CI upper 95% CI 9 11 1 0.909 0.0867 0.7541 1.000 13 10 1 0.818 0.1163 0.6192 1.000 18 8 1 0.716 0.1397 0.4884 1.000 23 7 1 0.614 0.1526 0.3769 0.999 31 5 1 0.491 0.1642 0.2549 0.946 34 4 1 0.368 0.1627 0.1549 0.875 48 2 1 0.184 0.1535 0.0359 0.944 x=Nonmaintained time n.risk n.event survival std.err lower 95% CI upper 95% CI 5 12 2 0.8333 0.1076 0.6470 1.000 8 10 2 0.6667 0.1361 0.4468 0.995 12 8 1 0.5833 0.1423 0.3616 0.941 23 6 1 0.4861 0.1481 0.2675 0.883 27 5 1 0.3889 0.1470 0.1854 0.816 30 4 1 0.2917 0.1387 0.1148 0.741 33 3 1 0.1944 0.1219 0.0569 0.664 43 2 1 0.0972 0.0919 0.0153 0.620 45 1 1 0.0000 NaN NA NA
> survfit(Surv(time, status) ~ x, data = aml) #another quick comparisonCall: survfit(formula = Surv(time, status) ~ x, data = aml) records n.max n.start events median 0.95LCL 0.95UCLx=Maintained 11 11 11 7 31 18 NAx=Nonmaintained 12 12 12 11 23 8 NA
> survdiff(Surv(time, status) ~ x, data = aml)Call: survdiff(formula = Surv(time, status) ~ x, data = aml) N Observed Expected (O-E)^2/E (O-E)^2/Vx=Maintained 11 7 10.69 1.27 3.40x=Nonmaintained 12 11 7.31 1.86 3.40 Chisq= 3.4 on 1 degrees of freedom, p= 0.0653
> coxaml = coxph(Surv(time, status) ~ x, data = aml) #or do cox regression with treatment as predicto> summary(coxaml)Call: coxph(formula = Surv(time, status) ~ x, data = aml) n= 23 coef exp(coef) se(coef) z Pr(>|z|) xNonmaintained 0.9155 2.4981 0.5119 1.788 0.0737 .---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
exp(coef) exp(-coef) lower .95 upper .95xNonmaintained 2.498 0.4003 0.9159 6.813
Rsquare= 0.137 (max possible= 0.976 )Likelihood ratio test= 3.38 on 1 df, p=0.06581Wald test = 3.2 on 1 df, p=0.07371Score (logrank) test = 3.42 on 1 df, p=0.06454 Do bootstrap also
R version 2.14.1 (2011-12-22) > library(survival) > data(leukemia)> aml = leukemia #rename for typing ease > #status = 0 are right-censored observations time status x time status x 1 9 1 Maintained 12 5 1 Nonmaintained 2 13 1 Maintained 13 5 1 Nonmaintained 3 13 0 Maintained 14 8 1 Nonmaintained 4 18 1 Maintained 15 8 1 Nonmaintained 5 23 1 Maintained 16 12 1 Nonmaintained 6 28 0 Maintained 17 16 0 Nonmaintained 7 31 1 Maintained 18 23 1 Nonmaintained 8 34 1 Maintained 19 27 1 Nonmaintained 9 45 0 Maintained 20 30 1 Nonmaintained 10 48 1 Maintained 21 33 1 Nonmaintained 11 161 0 Maintained 22 43 1 Nonmaintained 23 45 1 Nonmaintained > kmfit = survfit(Surv(time, status) ~ x, data = aml) > #fit a Kaplan-Meier and plot it > kmfit Call: survfit(formula = Surv(time, status) ~ x, data = aml) records n.max n.start events median 0.95LCL 0.95UCLx=Maintained 11 11 11 7 31 18 NAx=Nonmaintained 12 12 12 11 23 8 NA#get confidence intervals (non-simultaneous, std.err from summary(kmfit))> plot(kmfit, conf.int=TRUE) #ugly, with this small events # see ?survfit#tried another plot, about the same as before (taken from Stevenson)> # do ?plot.survfit for details, also Stevenson examples
> # log-rank test: equality of survival curves, Kalbfliesh-Prentice sec 1.5> #exact version of log-rank test (for equality of survival curves)> install.packages("coin") > library(coin)> #log-rank test for equality of survival curves (asymptotic)> survdiff(Surv(time, status) ~ x, data = aml)Call: survdiff(formula = Surv(time, status) ~ x, data = aml) N Observed Expected (O-E)^2/E (O-E)^2/Vx=Maintained 11 7 10.69 1.27 3.4x=Nonmaintained 12 11 7.31 1.86 3.4 Chisq= 3.4 on 1 degrees of freedom, p= 0.0653 > #from package coin, permutation test ('exact') see HSAUR p.205> surv_test(Surv(time, status) ~ x, data = aml, distribution = "exact") Exact Logrank Testdata: Surv(time, status) by x (Maintained, Nonmaintained) Z = -1.8345, p-value = 0.06469alternative hypothesis: two.sided > surv_test(Surv(time, status) ~ x, data = aml, distribution = approximate(B = 10000)) Approximative Logrank Testdata: Surv(time, status) by x (Maintained, Nonmaintained) Z = -1.8345, p-value = 0.0647alternative hypothesis: two.sided > # for larger problems, resampling approximation may be useful> #can also stratify, K-B sec 1.5.1, HSAUR 11.3.1 Gliomabootstrap CI (if you have taken the bootstrap course, just go to package 'boot')> install.packages("Hmisc") #Frank Harrel's miscellaneous> ?bootkm > ?survfitKM> attach(aml)# bootstrap replications for median survival each group seperately, B=1000> amlM = bootkm(Surv(time,status)[x == 'Maintained'] , q = 0.5, B=1000)> amlnotM = bootkm(Surv(time,status)[x == 'Nonmaintained'] , q = 0.5, B=1000)> describe(amlM - amlnotM)amlM - amlnotM n missing unique Mean .05 .10 .25 .50 .75 .90 .95 1000 0 36 Inf -7 -4 4 11 23 36 40 lowest : -30 -25 -20 -17 -14, highest: 29 36 40 43 Inf # get a (crude) percentile CI, boot.ci would do much better > #includes 0!> quantile(amlM - amlnotM, c(.025,.975), na.rm = TRUE) 2.5% 97.5% -10 Inf > quantile(amlM - amlnotM, c(.05,.95), na.rm = TRUE) # or 90% interval 5% 95% -7 40 > median(amlM) > median(amlnotM) [1] 31 [1] 23 # or try lower quartile of survival times> amlM25 = bootkm(Surv(time,status)[x == 'Maintained'] , q = 0.25, B=1000)> amlnotM25 = bootkm(Surv(time,status)[x == 'Nonmaintained'] , q = 0.25, B=1000)> quantile(amlM25 - amlnotM25, c(.05,.95), na.rm = TRUE) 5% 95% -9 Inf