Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some help with this please, and can I have this in R system. Please show

ID: 3057322 • Letter: I

Question

I need some help with this please, and can I have this in R system. Please show me the code how to work.

Reading in the data.

# Reading the data into R:

my.datafile <- tempfile()

cat(file=my.datafile, "

1 15

1 20

1 19

1 14

2 10

2 11

2 15

2 10

3 34

3 28

3 29

3 31

4 20

4 19

4 25

4 10

", sep=" ")

options(scipen=999) # suppressing scientific notation

banks <- read.table(my.datafile, header=FALSE, col.names=c("branch", "leave"))

attach(banks)

# Making "branch" a factor:

branch <- factor(branch)

# The data frame called banks is now created.

########

Question :

You are to write the R code and answer the two questions. For part (a) Do the data indicate difference in Branches? For part (b) Which Branches are different and for this you will be using Fisher’S LSD test and Tukey’s test exactly like Rice Data set we did in class. This will tell you exactly which banks are different your answer should include test statistic, null and alternative hypothesis, p value, statistical decision as well as practical decision. Extra (3) points for those who can do a side by side boxplot with labels of the banks sick leaves (get creative).

Explanation / Answer

# Reading the data into R:

my.datafile <- tempfile()

cat(file=my.datafile, "
  
1 15
  
1 20
  
1 19
  
1 14
  
2 10
  
2 11
  
2 15
  
2 10
  
3 34
  
3 28
  
3 29
  
3 31
  
4 20
  
4 19
  
4 25
  
4 10
  
", sep=" ")

options(scipen=999)
banks <- read.table(my.datafile, header=FALSE, col.names=c("branch", "leave"))

attach(banks)
# Making "branch" a factor:

branch <- factor(branch)

# The data frame called banks is now created.

#a) Do the data indicate difference in Branches?

#Below is R code

lm1=lm(leave~branch)
aov=aov(lm1)

# Result

#Null Hypothesis=Mean of all banks are equal

#Alternative hypothesis=Mean of at least one banks differe from each other

#P value=0.0001285 is small less than 0.05 so we reject null haypothesis

#So we need to test which banks are different for this we will be using Fisher’S LSD test and Tukey’s test

#We will do it using R

#we need package "agricolae" install it if it is not installed in your system

library(agricolae)
out<-LSD.test(aov,"branch")
plot(out,variation="SD")

#Using tukeys test

TukeyHSD(aov)

# We test below

#Null Hypothesis=Mean of two banks are equal

#Alternative Hypothesis=Mean of two banks are not equal

# test statistic-Tukey's test is essentially a t-test

# p-vlaue in the last column for each pair for e,g p value for comparision between bank 2 and 1 is 0.24

#Conclusion: Bank 3 is different from bank 1,2,and 4

Tukey multiple comparisons of means
95% family-wise confidence level

Fit: aov(formula = lm1)

$branch
diff lwr upr p adj
2-1 -5.5 -13.653224 2.653224 0.2401777
3-1 13.5 5.346776 21.653224 0.0017453
4-1 1.5 -6.653224 9.653224 0.9458094
3-2 19.0 10.846776 27.153224 0.0000824
4-2 7.0 -1.153224 15.153224 0.1018821
4-3 -12.0 -20.153224 -3.846776 0.0043695

#3) Boxplot with labels of the banks sick leaves

boxplot(leave~branch,main="Banks sick leaves",xlab="Bank ID")