Stat141 Oct 31 '06 2-group comparisons--further examples Research design: Experiments vs non-experiments, cause and effect, what vs why? Research design: Sample size calculations: how big n? ----------------------------------------------------------------- > # 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 Further nonparametric exs, Kolmogorov-Smirnov test comparing two empirical distributions or data against a specified standard help(ks.test) ks.test package:stats R Documentation Kolmogorov-Smirnov Tests Description: Performs one or two sample Kolmogorov-Smirnov tests. Exs: Verzani (SAT data example p. 269-270). PLOS cell random ex from 10/26 From R-docs do their examples: > x = rnorm(50); y = runif(30) # both mean 0 symmetric dists > ks.test(x,y) # Do x and y come from the same distribution? Two-sample Kolmogorov-Smirnov test data: x and y D = 0.6133, p-value = 4.25e-07 alternative hypothesis: two.sided ------------------------------------------------------------------------------------ Research Design: Experiments vs Observational (non-experimental) Studies Some exs in cause and effect determinations portacavel shunt (Gilbert, Light, Mosteller) prayer and surgery soda pop and cancer TV and ADHD (prior) TV violence and agression, reciprocal effects studies Exs of experiments (from in the news): Dodder vine, smoke alarms ------------------------------------- Research Design Power and sample size, Power calculations via power.t.test (see web page references) Sample size calculations for Confidence Intervals easier (on overheads) Large vs small effects SW p.274 mu1 = 69.1, mu2 = 64.1, => delta = 5, sigma = 2.5 => effect size = 2 > power.t.test(delta = 5, sd = 2.5, n=11) #find power given other parameters Two-sample t test power calculation n = 11 delta = 5 sd = 2.5 sig.level = 0.05 power = 0.9937072 alternative = two.sided NOTE: n is number in *each* group second ex p.274 mu2 = 63.5, mu2 = 64.1, power.t.test(delta = .6, sd = 2.5, n=11) produces power = 0.07727976 ; SW say <.10 p.274 SW Appendix 7.1 p. 623, how big n? two sample t-test examples [find n for specied power--matches Table 5 p.678 entries] >power.t.test(delta=.4,sd = 1, power = .8) |> power.t.test(delta=.5,sd=1, power=.8) Two-sample t test power calculation | Two-sample t test power calculation n = 99.08057 | n = 63.76576 delta = 0.4 | delta = 0.5 sd = 1 | sd = 1 sig.level = 0.05 #SW did one-tail.025| sig.level = 0.05 power = 0.8 | power = 0.8 alternative = two.sided | alternative = two.sided NOTE: n is number in *each* group | NOTE: n is number in *each* group Also can do via 2 group case as one-way anova using power.anova.test (next week) Also to come, power.prop.test Power calculations two sample test for proportions