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 (25 points)

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 Noise Observed

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

  1. (7 points) Identify the dependent variable.

The amount of noise.

  1. (7 points) Identify the factor.

The circuit design.

  1. (7 points) Identify and list the factor levels.

Circuit Design Levels: Design 1, Design 2, Design 3, Design 4.

  1. (4 points) If you decided to conduct multiple t tests instead of ANOVA, list all the t tests you would have to conduct. In other words, list each pair of designs that you would need to compare using t tests.

If we decide to conduct a T-test we have to do 6 tests:

Question 2 (35 points)

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)
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 ...
  1. (5 points) Identify:

The dependent variable.

The factor.

The factor levels.

levels(Pigs_Weights$Diet)
## [1] "D1" "D2" "D3" "D4"
  1. (5 points) State the hypotheses (Ho and Ha).

Ho: All diets give the pigs the same average weight.

Ha: At least one pair of diets has different average weights.

  1. (5 points) Compute the average weight for each diet.
average_weight <- aggregate(Weight ~ Diet, data = Pigs_Weights, FUN = mean)
average_weight                       
  1. (20 points) Run ANOVA and make the appropriate conclusion. Use a significance level of 0.05.
anova_pigs_weight = aov(Pigs_Weights$Weight ~ Pigs_Weights$Diet)
summary(anova_pigs_weight)
##                   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

The PV(0.0547) is more than alpha(0.05), therefore we fail to reject Ho. However since PV is close to alpha, 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. Finally, the current data support that the average weight of the pigs is not affected by the diet

Question 3 (40 points)

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)
design
##  [1] "1" "1" "1" "1" "1" "2" "2" "2" "2" "2" "3" "3" "3" "3" "3" "4" "4" "4" "4"
## [20] "4"
noise = c(21, 20, 29, 30, 24, 30, 31, 33, 26, 30, 27, 26, 25, 35, 39, 35, 41, 33, 28, 38)
noise
##  [1] 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:

  1. (5 points) State the hypotheses (Ho and Ha)

Ho: All circuit designs have the same mean level of noise

Ha: At least one pair of designs has a different mean level of noise

  1. (20 points) Run ANOVA and make the appropriate conclusion. Use a significance level of 0.05.
circuit_design = data.frame(Design = factor(design), Noise = noise)

anova_circuit_design <- aov(Noise ~ Design, data = circuit_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 PV(0.0301) is less than alpha(0.05), therefore we can reject Ho and support Ha. There is significant evidence to conclude that at least one of the circuit designs has a different mean level of noise.

  1. (15 points) Conduct a post-hoc test and discuss which designs lead to different average noise levels.
sort (tapply (circuit_design$Noise, circuit_design$Design, mean))
##    1    2    3    4 
## 24.8 30.0 30.4 35.0

Bonferroni post-hoc tests:

pairwise.t.test(circuit_design$Noise, circuit_design$Design, p.adjust.method = "bonfe")
## 
##  Pairwise comparisons using t tests with pooled SD 
## 
## data:  circuit_design$Noise and circuit_design$Design 
## 
##   1     2     3    
## 2 0.619 -     -    
## 3 0.487 1.000 -    
## 4 0.022 0.696 0.875
## 
## P value adjustment method: bonferroni

Tukey post-hoc tests:

TukeyHSD(anova_circuit_design)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Noise ~ Design, data = circuit_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

The only pair of designs that shows a statistically significant difference in noise levels is design 1 compared to design 4, because is the only PV(0.022/0.0176) that is less than alpha(0.05)