> "Anorexia" <- + structure(list(Therapy = structure(c(1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 + ), .Label = c("Control", "Family", "Cog/Behav"), class = "factor"), + Before = c(80.7, 89.4, 91.8, 74, 78.1, 88.3, 87.3, 75.1, + 80.6, 78.4, 77.6, 88.7, 81.3, 78.1, 70.5, 77.3, 85.2, 86, + 84.1, 79.7, 85.5, 84.4, 79.6, 77.5, 72.3, 89, 83.8, 83.3, + 86, 82.5, 86.7, 79.6, 76.9, 94.2, 73.4, 80.5, 81.6, 82.1, + 77.6, 83.5, 89.9, 86, 87.3, 80.5, 84.9, 81.5, 82.6, 79.9, + 88.7, 94.9, 76.3, 81, 80.5, 85, 89.2, 81.3, 76.5, 70, 80.4, + 83.3, 83, 87.7, 84.2, 86.4, 76.5, 87.8, 83.3, 79.7, 84.5, + 80.8, 87.4), After = c(80.2, 80.1, 86.4, 86.3, 76.1, 78.1, + 75.1, 86.7, 73.5, 84.6, 77.4, 79.5, 89.6, 81.4, 81.8, 77.3, + 84.2, 75.4, 79.5, 73, 88.3, 84.7, 81.4, 81.2, 88.2, 78.8, + 95.2, 94.3, 91.5, 91.9, 100.3, 76.7, 76.8, 101.6, 94.9, 75.2, + 77.8, 95.5, 90.7, 92.5, 93.8, 91.7, 98, 82.2, 85.6, 81.4, + 81.9, 76.4, 103.6, 98.4, 93.4, 73.4, 82.1, 96.7, 95.3, 82.4, + 72.5, 90.9, 71.3, 85.4, 81.6, 89.1, 83.9, 82.7, 75.7, 100.4, + 85.2, 83.6, 84.6, 96.2, 86.7), Y = c(-0.5, -9.30000000000001, + -5.39999999999999, 12.3, -2, -10.2, -12.2, 11.6, -7.1, 6.19999999999999, + -0.199999999999989, -9.2, 8.3, 3.30000000000001, 11.3, 0, + -1, -10.6, -4.59999999999999, -6.7, 2.800, 0.299999999999997, + 1.80000000000001, 3.7, 15.9, -10.2, 11.4, 11, 5.5, 9.4, 13.6, + -2.89999999999999, -0.100000000000009, 7.39999999999999, + 21.5, -5.3, -3.8, 13.4, 13.1, 9, 3.89999999999999, 5.7, 10.7, + 1.70000000000000, 0.699999999999989, -0.0999999999999943, + -0.699999999999989, -3.5, 14.9, 3.5, 17.1, -7.6, 1.59999999999999, + 11.7, 6.1, 1.10000000000001, -4, 20.9, -9.1, 2.10000000000001, + -1.40000000000001, 1.39999999999999, -0.299999999999997, + -3.7, -0.799999999999997, 12.6, 1.90000000000001, 3.89999999999999, + 0.0999999999999943, 15.4, -0.700000000000003)), .Names = c("Therapy", + "Before", "After", "Y"), row.names = c("1", "2", "3", "4", "5", + "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", + "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", + "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", + "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", + "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", + "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71" + ), class = "data.frame") > > > Anorexia Therapy Before After Y 1 Control 80.7 80.2 -0.5 2 Control 89.4 80.1 -9.3 3 Control 91.8 86.4 -5.4 4 Control 74.0 86.3 12.3 5 Control 78.1 76.1 -2.0 6 Control 88.3 78.1 -10.2 7 Control 87.3 75.1 -12.2 8 Control 75.1 86.7 11.6 9 Control 80.6 73.5 -7.1 10 Control 78.4 84.6 6.2 11 Control 77.6 77.4 -0.2 12 Control 88.7 79.5 -9.2 13 Control 81.3 89.6 8.3 14 Control 78.1 81.4 3.3 15 Control 70.5 81.8 11.3 16 Control 77.3 77.3 0.0 17 Control 85.2 84.2 -1.0 18 Control 86.0 75.4 -10.6 19 Control 84.1 79.5 -4.6 20 Control 79.7 73.0 -6.7 21 Control 85.5 88.3 2.8 22 Control 84.4 84.7 0.3 23 Control 79.6 81.4 1.8 24 Control 77.5 81.2 3.7 25 Control 72.3 88.2 15.9 26 Control 89.0 78.8 -10.2 27 Family 83.8 95.2 11.4 28 Family 83.3 94.3 11.0 29 Family 86.0 91.5 5.5 30 Family 82.5 91.9 9.4 31 Family 86.7 100.3 13.6 32 Family 79.6 76.7 -2.9 33 Family 76.9 76.8 -0.1 34 Family 94.2 101.6 7.4 35 Family 73.4 94.9 21.5 36 Family 80.5 75.2 -5.3 37 Family 81.6 77.8 -3.8 38 Family 82.1 95.5 13.4 39 Family 77.6 90.7 13.1 40 Family 83.5 92.5 9.0 41 Family 89.9 93.8 3.9 42 Family 86.0 91.7 5.7 43 Family 87.3 98.0 10.7 44 Cog/Behav 80.5 82.2 1.7 45 Cog/Behav 84.9 85.6 0.7 46 Cog/Behav 81.5 81.4 -0.1 47 Cog/Behav 82.6 81.9 -0.7 48 Cog/Behav 79.9 76.4 -3.5 49 Cog/Behav 88.7 103.6 14.9 50 Cog/Behav 94.9 98.4 3.5 51 Cog/Behav 76.3 93.4 17.1 52 Cog/Behav 81.0 73.4 -7.6 53 Cog/Behav 80.5 82.1 1.6 54 Cog/Behav 85.0 96.7 11.7 55 Cog/Behav 89.2 95.3 6.1 56 Cog/Behav 81.3 82.4 1.1 57 Cog/Behav 76.5 72.5 -4.0 58 Cog/Behav 70.0 90.9 20.9 59 Cog/Behav 80.4 71.3 -9.1 60 Cog/Behav 83.3 85.4 2.1 61 Cog/Behav 83.0 81.6 -1.4 62 Cog/Behav 87.7 89.1 1.4 63 Cog/Behav 84.2 83.9 -0.3 64 Cog/Behav 86.4 82.7 -3.7 65 Cog/Behav 76.5 75.7 -0.8 66 Cog/Behav 87.8 100.4 12.6 67 Cog/Behav 83.3 85.2 1.9 68 Cog/Behav 79.7 83.6 3.9 69 Cog/Behav 84.5 84.6 0.1 70 Cog/Behav 80.8 96.2 15.4 71 Cog/Behav 87.4 86.7 -0.7 > attach(Anorexia) > boxplot(Y~Therapy) > Fam = Anorexia$Y[Anorexia$Therapy=="Family"] > Cont = Anorexia$Y[Anorexia$Therapy=="Control"] > Fam [1] 11.4 11.0 5.5 9.4 13.6 -2.9 -0.1 7.4 21.5 -5.3 -3.8 13.4 13.1 9.0 3.9 5.7 10.7 > length(Fam) [1] 17 > Cont [1] -0.5 -9.3 -5.4 12.3 -2.0 -10.2 -12.2 11.6 [9] -7.1 6.2 -0.2 -9.2 8.3 3.3 11.3 0.0 [17] -1.0 -10.6 -4.6 -6.7 2.8 0.3 1.8 3.7 [25] 15.9 -10.2 > length(Cont) [1] 26 > ## Number of subjects on the Family therapy = 17: > m=length(Fam) > m [1] 17 > # Mean weight gain (positive): > xbar=mean(Fam) > xbar [1] 7.264706 > # Sample variance of weight gains: > sx2=var(Fam) > sx2 [1] 51.22868 > > ## Number of subjects on the Control therapy = > n=length(Cont) > n [1] 26 > # Mean weight gain: > ybar=mean(Cont) > ybar [1] -0.45 > # Sample variance of weight gains: > sy2=var(Cont) > sy2 [1] 63.8194 > > xbar-ybar [1] 7.714706 > sy2/sx2 # Not ideal, but sy2 only 25% higher [1] 1.245775 > > qqnorm(Fam) # Hard to tell with small sample size > qqline(Fam) > > qqnorm(Cont) > qqline(Cont) > s2.pool = ((m-1)*sx2+(n-1)*sy2)/(m+n-2) > > s2.pool [1] 58.90595 > sx2 [1] 51.22868 > sy2 [1] 63.8194 > T = (xbar-ybar)/sqrt(s2.pool*(1/m+1/n)) > T [1] 3.222676 > n+m-2 [1] 41 > pt(T,m+n-2,lower.tail=FALSE) [1] 0.001245507 > > t.test(Fam,Cont,alternative="greater",var.equal=TRUE) Two Sample t-test data: Fam and Cont t = 3.2227, df = 41, p-value = 0.001246 alternative hypothesis: true difference in means is greater than 0 95 percent confidence interval: 3.686095 Inf sample estimates: mean of x mean of y 7.264706 -0.450000 > t.test(Fam,Cont,var.equal=TRUE) Two Sample t-test data: Fam and Cont t = 3.2227, df = 41, p-value = 0.002491 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 2.880164 12.549248 sample estimates: mean of x mean of y 7.264706 -0.450000 > t.test(Fam,Cont,alternative="greater") Welch Two Sample t-test data: Fam and Cont t = 3.2992, df = 36.979, p-value = 0.001076 alternative hypothesis: true difference in means is greater than 0 95 percent confidence interval: 3.769574 Inf sample estimates: mean of x mean of y 7.264706 -0.450000 > t.test(Fam) One Sample t-test data: Fam t = 4.1849, df = 16, p-value = 0.0007003 alternative hypothesis: true mean is not equal to 0 95 percent confidence interval: 3.58470 10.94471 sample estimates: mean of x 7.264706 > curve(df(x,5,5)) > curve(df(x,5,5),0,10) > curve(df(x,5,5),0,4) > curve(df(x,50,50),40,50) > curve(df(x,50,50),0,50) > curve(df(x,25,16),0,20) > curve(df(x,25,16),0,4) > abline(v=1.246,col="red") > pf(1.246,25,16,lower.tail=FALSE) [1] 0.3291944 > 2*.329 [1] 0.658 > var.test(Cont,Fam,alternative="greater") F test to compare two variances data: Cont and Fam F = 1.2458, num df = 25, denom df = 16, p-value = 0.3293 alternative hypothesis: true ratio of variances is greater than 1 95 percent confidence interval: 0.5593434 Inf sample estimates: ratio of variances 1.245775 > > var.test(Cont,Fam) F test to compare two variances data: Cont and Fam F = 1.2458, num df = 25, denom df = 16, p-value = 0.6587 alternative hypothesis: true ratio of variances is not equal to 1 95 percent confidence interval: 0.4766073 2.9699299 sample estimates: ratio of variances 1.245775 >