Stat 141 Nov 3 Two-sample(treatment/control)inference: t-test, nonparametric alternatives (Mann-Whiney, Duckworth) SW Ch 7. ---------------------------------------------------------------------------------- > #2-sample example 7.7 table 7.5 ancy.dat (con't 11/1) $ancy Min. 1st Qu. Median Mean 3rd Qu. Max. sd 5.80 7.40 11.00 11.01 13.00 19.50 4.72 $control Min. 1st Qu. Median Mean 3rd Qu. Max. sd 9.60 12.40 16.60 15.91 19.93 21.20 4.78 > t.test(height~group) Welch Two Sample t-test data: height by group t = -1.9939, df = 12.783, p-value = 0.06795 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -10.2146719 0.4182434 sample estimates: mean in group ancy mean in group control 11.01429 15.91250 > # p-value .068 consistent with CI 95% including 0, CI for ancy-control > #recreates by hand calc in SW 228-229, df Welch df SW eq 7.1 > qt(.975, 12.8) [1] 2.163805 > # matches SW p.229 "t-multiplier" in CI or critical value for test statistic > #for the old-fashioned "pooled" solution, original 2-sample t > t.test(height~group, var.equal = TRUE) Two Sample t-test data: height by group t = -1.9919, df = 13, p-value = 0.06781 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -10.2106670 0.4142385 sample estimates: mean in group ancy mean in group control 11.01429 15.91250 > # see also hypothesis tests SW pp.238-9, p-values 237-8, TypeI,II errors 252-4 > # directional hypoth ex, feeding lambs niacin (you don't want it even if MD says) > # SW lamb data (ex7.20,7.22) not available, so go to rats sniffing glue tuolene ex 7.9-7.11 etc; mtb analysis p. 262 > glue = read.table(file="D:\\stat141\\toluene.dat", header = T) > tapply(NE.conc, group, sort) $control $Toluene [1] 385 387 412 502 535 [1] 431 523 543 549 564 635 > t.test(NE.conc ~group, alt = "less") Welch Two Sample t-test data: NE.conc by group t = -2.3447, df = 8.451, p-value = 0.02272 alternative hypothesis: true difference in means is less than 0 95 percent confidence interval: -Inf -20.52321 sample estimates: mean in group control mean in group Toluene 444.2000 540.8333 > # matches Minitab on SW p.262, modulo sign > # t-test assumptions; tissue inflamation exp.281, log-transform then parametric t-test ------------------------------------------------------------------------------------ Nonparametric Alternatives: Can you (should you) do arithmetic on the data? > #Wilcoxon-Mann-Whitney SW sec 7.11 p.288 # soil respiration 7.17 p.289 > soil = read.table(file="D:\\stat141\\soil.dat", header = T) > tapply(co2,group,sort) $gap $growth [1] 6 13 14 15 16 18 22 29 [1] 17 20 22 64 170 190 315 > # do duckworth c=9, reject? ( >= 7 -> .05, >= 10 -> .01); reject with p-value close to .01 > wilcox.test(co2~group) Wilcoxon rank sum test with continuity correction data: co2 by group W = 6.5, p-value = 0.01500 alternative hypothesis: true mu is not equal to 0 Warning message: cannot compute exact p-value with ties in: wilcox.test.default(x = c(13, 16, 15, 18, 14, 6, 29, 22), y = c(17, > # compare: SW contortions pp.290-292; R-wilcox easier, Duckworth even easier and agrees. ---------------------------------------------------------------------------------------- > # Brogan-Kutner liver data--repeated measures analysis of variance > bkdat = read.table(file="D:\\stat141\\brogkutrow.dat", header = T) > # c4 method (1 = selective, 2=nonselective); c2 pre (urea synthesis); c3 post > attach(bkdat) > imp = post - pre > tapply(imp,method,sort) $"1" [1] -6 -6 -5 -3 -3 -3 12 20 $"2" [1] -24 -18 -18 -18 -18 -15 -14 -11 -8 -7 -6 -4 4 > t.test(imp~method) Welch Two Sample t-test data: imp by method t = 3.1743, df = 12.271, p-value = 0.007806 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 4.044203 21.609643 sample estimates: mean in group 1 mean in group 2 0.75000 -12.07692 > # improvement diifers by methods--treatment by occasions interaction > # t-test for equal var assumption equiv to repeated measures > # in repeated measures analysis of variance 3.37^2 is F-statistic F(1,19) > t.test(imp~method, var.equal = TRUE) Two Sample t-test data: imp by method t = 3.3709, df = 19, p-value = 0.003209 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 4.862645 20.791201 sample estimates: mean in group 1 mean in group 2 0.75000 -12.07692 pre,post description > tapply(pre, method, summary) $"1" Min. 1st Qu. Median Mean 3rd Qu. Max. 35.00 39.75 44.00 46.38 51.25 66.00 $"2" Min. 1st Qu. Median Mean 3rd Qu. Max. 32.00 36.00 42.00 43.54 50.00 63.00 > tapply(post, method, summary) $"1" Min. 1st Qu. Median Mean 3rd Qu. Max. 35.00 41.25 47.00 47.13 54.25 60.00 $"2" Min. 1st Qu. Median Mean 3rd Qu. Max. 14.00 18.00 32.00 31.46 36.00 67.00 > # Duckworth BK improvement c = 10 + 2 = 12, p < .01