Instructions
Create an R notebook and include all the code and interpretations/explanations needed to answer the three questions below.
Note: You also need to include the answer to question 1 in this notebook (even when question 1 does NOT require you to use R). Include the answer to question 1 in text sections of this notebook.
Question 1
Four different designs for a digital computer circuit are being studied to compare the amount of noise present. The following data have been obtained:
circuit_design= matrix(c(21, 20, 29, 30, 24,
30, 31, 33, 26, 30,
27, 26, 25, 35, 39,
35, 41, 33, 28, 38), nrow=4, byrow=TRUE, dimnames= list(c("Design 1","Design 2","Design 3","Design 4")))
circuit_design
## [,1] [,2] [,3] [,4] [,5]
## Design 1 21 20 29 30 24
## Design 2 30 31 33 26 30
## Design 3 27 26 25 35 39
## Design 4 35 41 33 28 38
str(circuit_design)
## num [1:4, 1:5] 21 30 27 35 20 31 26 41 29 33 ...
## - attr(*, "dimnames")=List of 2
## ..$ : chr [1:4] "Design 1" "Design 2" "Design 3" "Design 4"
## ..$ : NULL
noise observed
circuit design
4 levels: design 1, design 2, design 3, design 4
M1 = M2 α = 0.05 At least 6 mean comparisons would have to be conducted M1 = M3 α = 0.05 M1 = M4 α = 0.05 M2 = M3 α = 0.05 M2 = M4 α = 0.05 M3 = M4 α = 0.05
The probability of making a type I error in at least one of these 6 comparisons is calculated by the alpha of each comparison 1-0.05=0.95 to the power of 6 means 0.95^6 = 0.7351 which would leave us with 1-0.7351=0.2649, 26.5% probability of committing a type I error in at least one comparison.
Question 2
20 pigs are assigned at random among 4 experimental groups. Each group is fed a different diet. The data are the pig’s weight, in kilograms, after being raised on these diets for 10 months. We wish to determine whether the mean pig weights are the same for all 4 diets or not.
Download the CSV file “Pigs_Weights” from Canvas/ Module 3/ Resources. Then, read it into R.
setwd("E:\\S9510\\CAP3330")
Pigs_Weights = read.csv("Pigs_Weights.csv", stringsAsFactors = T)
Pigs_Weights
str(Pigs_Weights)
## 'data.frame': 20 obs. of 2 variables:
## $ Diet : Factor w/ 4 levels "D1","D2","D3",..: 1 1 1 1 1 2 2 2 2 2 ...
## $ Weight: num 80.8 77.1 85 78.7 81.8 88.3 87.7 79 86.3 79.9 ...
levels(Pigs_Weights$Diet)
## [1] "D1" "D2" "D3" "D4"
The factor levels. 4 levels D1, D2, D3, D4 (4 Diets)
Ho: Md1= Md2= Md3= Md4 (All mean pig weights are the same for all 4 diets)
Ha: At least two of the four mean pig weights are different
sort(tapply(Pigs_Weights$Weight, Pigs_Weights$Diet, mean))
## D1 D2 D4 D3
## 80.68 84.24 86.38 87.34
average_weight <- aggregate(Weight ~ Diet, data = Pigs_Weights, FUN = mean)
average_weight
anova_pigs_weights <- aov(Pigs_Weights$Weight ~ Pigs_Weights$Diet)
summary(anova_pigs_weights)
## Df Sum Sq Mean Sq F value Pr(>F)
## Pigs_Weights$Diet 3 130.8 43.60 3.134 0.0547 .
## Residuals 16 222.5 13.91
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
p-value 0.0547 > 0.05 (alpha) We fail to reject Ho.The data does NOT give us sufficient evidence to support the idea that the mean weight gain for all four diets is different.This result implies that there might be some effect of diet on weight, but the evidence is not strong enough to make a definitive conclusion. With the available data we conclude that the mean weight gain is the same for all four diets so the average weight of the pigs is not affected by the diet
Question 3
Consider the data shown in the table from question 1. Enter this data in R by following these steps:
design= rep (c("1","2","3","4"), each= 5)
noise= c(21, 20, 29, 30, 24,
30, 31, 33, 26, 30,
27, 26, 25, 35, 39,
35, 41, 33, 28, 38)
Conduct an ANOVA test and answer these questions: a) State the hypotheses (Ho and Ha)
Ho: amount of mean noise present in all four circuit designs is the same m1 = m2 = m3 = m4
Ha: At least two of the four designs have different mean noise present
anova_circuit_design <- aov(noise ~ design)
summary(anova_circuit_design)
## Df Sum Sq Mean Sq F value Pr(>F)
## design 3 261 86.98 3.845 0.0301 *
## Residuals 16 362 22.63
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The p-value 0.0301 < alpha (0.05); therefore, the data is giving us evidence to reject Ho and support Ha. We have evidence to conclude that at least two of circuit designs have different mean noise present. We should expect that some designs have less noise than others.
Bonferroni post-hoc tests:
pairwise.t.test (noise, design, p.adjust.method = "bonferroni")
##
## Pairwise comparisons using t tests with pooled SD
##
## data: noise and design
##
## 1 2 3
## 2 0.619 - -
## 3 0.487 1.000 -
## 4 0.022 0.696 0.875
##
## P value adjustment method: bonferroni
The only p-value 0.022 < alpha (0.05) is the one between design 4 and design 1. So, according to the Bonferroni method, the only difference that is statistically significant is the one between the mean of design 4 and design 1. According to Bonferroni, the only two sample means that are statistically different are the ones for 4 and 1.
Tukey post-hoc tests:
TukeyHSD(anova_circuit_design)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = noise ~ design)
##
## $design
## diff lwr upr p adj
## 2-1 5.2 -3.406868 13.806868 0.3419780
## 3-1 5.6 -3.006868 14.206868 0.2826091
## 4-1 10.2 1.593132 18.806868 0.0176270
## 3-2 0.4 -8.206868 9.006868 0.9991237
## 4-2 5.0 -3.606868 13.606868 0.3744075
## 4-3 4.6 -4.006868 13.206868 0.4442230
Similarly to Bonferroni, Tukey p-value 0.017627 < alpha (0.05) only finds one significant difference: the difference between design 4 and 1 since is the only p-value 0.022/0.0176 < alpha(0.05).