3.23

Type_1Fluid<-c(17.6, 18.9, 16.3, 17.4, 20.1, 21.6)
Type_2Fluid<-c(16.9, 15.3, 18.6, 17.1, 19.5, 20.3)
Type_3Fluid<-c(21.4, 23.6, 19.4, 18.5, 20.5, 22.3)
Type_4Fluid<-c(19.3, 21.1, 16.9, 17.5, 18.3, 19.8)
dat1<-data.frame(Type_1Fluid,Type_2Fluid,Type_3Fluid,Type_4Fluid)
library(tidyr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
dat<-pivot_longer(data = dat1,c(Type_1Fluid,Type_2Fluid,Type_3Fluid,Type_4Fluid))
colnames(dat)<-c("TypesofFluids","Values")
dat$TypesofFluids<-as.factor(dat$TypesofFluids)
qqnorm(dat$Values)
qqline(dat$Values)

comments; As from above all points are close to normal there are not much deviated from normal line. Therefore normality assumptions meets.

boxplot(dat1)

Comments: From above it is not very much clear but all of them are almost equal sizes. So we can consider the constant variance assumption and i am going for anova model.

anova_model<-aov(dat$Values~dat$TypesofFluids,data=dat)
summary(anova_model)
##                   Df Sum Sq Mean Sq F value Pr(>F)  
## dat$TypesofFluids  3  30.16   10.05   3.047 0.0525 .
## Residuals         20  65.99    3.30                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
residules<-resid(anova_model)
plot(anova_model)

Comments: The p-value = 0.0525, for α = 0.05 level of signifance. we don’t have sufficient evidence to reject Null Hypothesis (Ho).

(a) Is there any indication that the fluids differ? Use alpha = 0.05.

The ANOVA - we accept Null Hypothesis (Ho). we could state that There isn’t significant differ in the fluids.

(b) Which fluid would you select, given that the objective is long life?

From the box plot we could see that the fluid 3 could be choose because of the high max value, median and upper quartile value.

(c) Analyze the residuals from this experiment. Are the basic analysis of variance assumptions satisfied?

The Model seen to be adequate with minute deviations(could be assumed to have constant variance), the normal q-q plot of residuals is normal (normal assumptions meet).

Source Code

Type_1Fluid<-c(17.6, 18.9, 16.3, 17.4, 20.1, 21.6)
Type_2Fluid<-c(16.9, 15.3, 18.6, 17.1, 19.5, 20.3)
Type_3Fluid<-c(21.4, 23.6, 19.4, 18.5, 20.5, 22.3)
Type_4Fluid<-c(19.3, 21.1, 16.9, 17.5, 18.3, 19.8)
dat1<-data.frame(Type_1Fluid,Type_2Fluid,Type_3Fluid,Type_4Fluid)
library(tidyr)
library(dplyr)
dat<-pivot_longer(data = dat1,c(Type_1Fluid,Type_2Fluid,Type_3Fluid,Type_4Fluid))
colnames(dat)<-c("TypesofFluids","Values")
dat$TypesofFluids<-as.factor(dat$TypesofFluids)
qqnorm(dat$Values)
qqline(dat$Values)
boxplot(dat1)
anova_model<-aov(dat$Values~dat$TypesofFluids,data=dat)
summary(anova_model)
residules<-resid(anova_model)
plot(anova_model)

3.51 and 3.52

3.51 and 3.52 . Use the Kruskal–Wallis test for the experiment in Problem 3.23. Compare the conclusions obtained with those from the usual analysis of variance.

kruskal.test(dat$Values~dat$TypesofFluids,data=dat)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  dat$Values by dat$TypesofFluids
## Kruskal-Wallis chi-squared = 6.2177, df = 3, p-value = 0.1015

Comments: p-value = 0.1015. We have strong evidence of accepting the Null hypothesis at α = 0.05 level of significance.

Source Code

kruskal.test(dat$Values~dat$TypesofFluids,data=dat)

3.28

M1<-c(110, 157, 194, 178)
M2<-c(1, 2, 4, 18)
M3<-c(880, 1256, 5276, 4355)
M4<-c(495, 7040, 5307, 10050)
M5<-c(7, 5, 29, 2)
dat1<-cbind.data.frame(M1,M2,M3,M4,M5)
library(tidyr)
library(dplyr)
dat<-pivot_longer(dat1,c(M1,M2,M3,M4,M5))
dat$name<-as.factor(dat$name)

(a) Do all five materials have the same effect on mean failure time?

boxplot(dat1)

#(a)Answer ## Comments: The box plot is incomparable with each other. From the box plot we could see that the sample mean contribution is by Material 3 and Material 4.

(b) Plot the residuals versus the predicted response. Construct a normal probability plot of the residuals. What information is conveyed by these plots?

model_anova<-aov(value~name , data = dat)
summary(model_anova)
##             Df    Sum Sq  Mean Sq F value  Pr(>F)   
## name         4 103191489 25797872   6.191 0.00379 **
## Residuals   15  62505657  4167044                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
residules<-resid(model_anova)
plot(model_anova)

We can reject Null hypothesis becuase we got p value as 0.00379 so it far less than 0.05. So we can reject all means are same.

### Plot of Residuals vs Predicted Responce.
residuals <- resid(model_anova)
qqplot(dat$value, residuals, main = "Residuals vs  Predicted Responce", xlab = "Predicted Responce", ylab = "Residuals")
qqline(dat$value, residuals)
## Warning in if (datax) {: the condition has length > 1 and only the first element
## will be used

plot(model_anova)

Comments: Model is incomparable inadequate and the normal probability of the residuals looks normally distributed

(c) Based on your answer to part (b) conduct another analysis of the failure time data and draw appropriate conclusions.

LSD Test

library(agricolae)
## Warning: package 'agricolae' was built under R version 4.1.3
model_LSD<-LSD.test(model_anova, "name", console = T)
## 
## Study: model_anova ~ "name"
## 
## LSD t Test for value 
## 
## Mean Square Error:  4167044 
## 
## name,  means and individual ( 95 %) CI
## 
##      value         std r      LCL     UCL Min   Max
## M1  159.75   36.463452 4 -2015.75 2335.25 110   194
## M2    6.25    7.932003 4 -2169.25 2181.75   1    18
## M3 2941.75 2201.405971 4   766.25 5117.25 880  5276
## M4 5723.00 3998.435444 4  3547.50 7898.50 495 10050
## M5   10.75   12.338963 4 -2164.75 2186.25   2    29
## 
## Alpha: 0.05 ; DF Error: 15
## Critical Value of t: 2.13145 
## 
## least Significant Difference: 3076.622 
## 
## Treatments with the same letter are not significantly different.
## 
##      value groups
## M4 5723.00      a
## M3 2941.75     ab
## M1  159.75      b
## M5   10.75      b
## M2    6.25      b
model_LSD$groups
##      value groups
## M4 5723.00      a
## M3 2941.75     ab
## M1  159.75      b
## M5   10.75      b
## M2    6.25      b
## By above code  Method4,Method3,Method1 are significantly differ in mean. So we can reject null hypothesis by fisher's test.

By (model_LSD$groups) code output table we can see Method4,Method3,Method1 are significantly differ in mean. So we can reject null hypothesis by fisher’s test.

##Source Code

M1<-c(110, 157, 194, 178)
M2<-c(1, 2, 4, 18)
M3<-c(880, 1256, 5276, 4355)
M4<-c(495, 7040, 5307, 10050)
M5<-c(7, 5, 29, 2)
dat1<-cbind.data.frame(M1,M2,M3,M4,M5)
library(tidyr)
library(dplyr)
dat<-pivot_longer(dat1,c(M1,M2,M3,M4,M5))
dat$name<-as.factor(dat$name)
boxplot(dat1)
model_anova<-aov(value~name , data = dat)
summary(model_anova)
residules<-resid(model_anova)
plot(model_anova)
### Plot of Residuals vs Predicted Responce.
residuals <- resid(model_anova)
qqplot(dat$value, residuals, main = "Residuals vs  Predicted Responce", xlab = "Predicted Responce", ylab = "Residuals")
qqline(dat$value, residuals)
library(agricolae)
model_LSD<-LSD.test(model_anova, "name", console = T)
model_LSD$groups
## By above code  Method4,Method3,Method1 are significantly differ in mean. So we can reject null hypothesis by fisher's test.

Q3.29

M_1<-c(31, 10, 21, 4, 1)
M_2<-c(62, 40, 24, 30, 35)
M_3<-c(53, 27, 120, 97, 68)
data1<-cbind.data.frame(M_1, M_2, M_3)
library(tidyr)
data2 <- pivot_longer(data = data1, c(M_1, M_2, M_3))
colnames(data2)<- c("Method", "Count")
data2$Method<-as.factor(data2$Method)

(a) Do all methods have the same effect on mean particle count

Box plot….

boxplot(data1)

The box plot is incomparable with each other.

From the box plot we could see that the sample mean contribution is by Method 3.

(b) Plot the residuals versus the predicted response.Construct a normal probability plot of the residuals.Are there potential concerns about the validity of the assumptions?

ANOVA and Residuals……

anova_model1<-aov(Count ~ Method, data = data2)
residules2<-resid(anova_model1)
plot(anova_model1)

Model is incomparable inadequate and the normal probability of the residuals looks normally distributed.

(c) Based on your answer to part (b) conduct another analysis of the particle count data and draw appropriate conclusion

LSD test……

library(agricolae)
LSD_model1<-LSD.test(anova_model1, "Method", console = T)
## 
## Study: anova_model1 ~ "Method"
## 
## LSD t Test for Count 
## 
## Mean Square Error:  566.3333 
## 
## Method,  means and individual ( 95 %) CI
## 
##     Count      std r       LCL      UCL Min Max
## M_1  13.4 12.46194 5 -9.788411 36.58841   1  31
## M_2  38.2 14.56709 5 15.011589 61.38841  24  62
## M_3  73.0 36.48972 5 49.811589 96.18841  27 120
## 
## Alpha: 0.05 ; DF Error: 12
## Critical Value of t: 2.178813 
## 
## least Significant Difference: 32.79336 
## 
## Treatments with the same letter are not significantly different.
## 
##     Count groups
## M_3  73.0      a
## M_2  38.2      b
## M_1  13.4      b
LSD_model1$groups
##     Count groups
## M_3  73.0      a
## M_2  38.2      b
## M_1  13.4      b
plot(LSD_model1)

From the plot we could see that the Methods 1 and 2 differ from the Method 3.

From Code (LSD_model1$groups) output we can see that Method 3 mean is significantly differ from Method 1 and Method 2 so we can reject null Hypothesis ie all means are equal.

Source Code:

M_1<-c(31, 10, 21, 4, 1)
M_2<-c(62, 40, 24, 30, 35)
M_3<-c(53, 27, 120, 97, 68)
data1<-cbind.data.frame(M_1, M_2, M_3)
library(tidyr)
data2 <- pivot_longer(data = data1, c(M_1, M_2, M_3))
colnames(data2)<- c("Method", "Count")
data2$Method<-as.factor(data2$Method)
boxplot(data1)
anova_model1<-aov(Count ~ Method, data = data2)
residules2<-resid(anova_model1)
plot(anova_model1)
library(agricolae)
LSD_model1<-LSD.test(anova_model1, "Method", console = T)
LSD_model1$groups
plot(LSD_model1)