STAT425HW6ySolution - STAT425HW6Solution Wenjing Yin...

This preview shows page 1 - 3 out of 6 pages.

STAT425HW6Solution Wenjing Yin November 14, 2016 Problem 1 (8 pts) (a) ## You could also work with original data format BFHS = read.table ( BFHS.dat , header = TRUE ) mydata = matrix ( 0 , nrow = 26 , ncol = 3 ) colnames (mydata) = c ( Town , group , average ) mydata[ 1 : 13 , 1 ] = seq ( 1 , 13 ) mydata[ 14 : 26 , 1 ] = seq ( 1 , 13 ) mydata[ 1 : 13 , 2 ] = 1 mydata[ 14 : 26 , 2 ] = 2 mydata[ 1 : 13 , 3 ] = BFHS$Intervention mydata[ 14 : 26 , 3 ] = BFHS$ExternalComparison mydata = data.frame (mydata) mydata$Town = as.factor (mydata$Town) mydata$group = as.factor (mydata$group) summary (mydata) ## Town group average ## 1 : 2 1:13 Min. :5.370 ## 2 : 2 2:13 1st Qu.:5.538 ## 3 : 2 Median :5.620 ## 4 : 2 Mean :5.629 ## 5 : 2 3rd Qu.:5.716 ## 6 : 2 Max. :6.067 ## (Other):14 (b) with (mydata, t.test (average[group == 1 ] - average[group == 2 ])) ## ## One Sample t-test ## ## data: average[group == 1] - average[group == 2] ## t = -2.0702, df = 12, p-value = 0.06067 ## alternative hypothesis: true mean is not equal to 0 ## 95 percent confidence interval: ## -0.228613888 0.005844657 ## sample estimates: ## mean of x ## -0.1113846 We obtain a p-value higher than 5%. There is no evidence of a difference between the two groups (c) 1
attach (mydata) tstats <- replicate ( 100000 , t.test ( (average[group == 1 ] - average[group == 2 ])* sample ( c (- 1 , 1 ), 13 , replac t.observed <- t.test (average[group == 1 ] - average[group == 2 ])$statistic approx.pval <- mean ( abs (tstats) >= abs (t.observed)) approx.pval ## [1] 0.03803 Based on the randomization result, the p-value is less than 5%. Therefore we have to reject the null hypothesis and conclude that there is actually difference between two groups. The result changed from what we have in

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture