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: 3064587 • Letter: I

Question

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

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.

########

Similar Question like 6.15 from the book.

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

The whole R code to solve the problem is attached,

# 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.

########

## data indicate difference in Branches
plot(branch,leave)
mean(banks[banks$branch==1,]$leave)
mean(banks[banks$branch==2,]$leave)
mean(banks[banks$branch==3,]$leave)
mean(banks[banks$branch==4,]$leave)
## overall mean
mean(banks$leave)

## building anova model
model_anova <- aov(leave ~ branch)
summary(model_anova)


## to perform LSD test
install.packages("agricolae")
library(agricolae)
out<-LSD.test(model_anova,"branch",p.adj="bonferroni",console=TRUE)
plot(out,variation="SD")

## to perform Tukey's HSD test
TukeyHSD(model_anova)

Answer,

(a) Clearly by plotting the data, and checking the mean leaves corresponding to each brach we can conclude that there is significant differences for leaves among the branches.

To make sure of that, we have performed anova on this data, and got that the effect of branch is significant on leaves.

(b)

To find which branches are different, we have performed the fisher's LSD test, and the result is as follows,

Study: model_anova ~ "branch"

LSD t Test for leave
P value adjustment method: bonferroni

Mean Square Error: 15.08333

branch, means and individual ( 95 %) CI

leave std r LCL UCL Min Max
1 17.0 2.943920 4 12.769043 21.23096 14 20
2 11.5 2.380476 4 7.269043 15.73096 10 15
3 30.5 2.645751 4 26.269043 34.73096 28 34
4 18.5 6.244998 4 14.269043 22.73096 10 25

Alpha: 0.05 ; DF Error: 12
Critical Value of t: 3.152681

Minimum Significant Difference: 8.657923

Treatments with the same letter are not significantly different.

leave groups
3 30.5 a
4 18.5 b
1 17.0 b
2 11.5 b

Here, according to the test two groups have been created and the conclution will be the two groups "a" and "b" are significantly different in terms of mean leaves.

After that, Tukey's HSD test is performed and the result is as follows,

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

Fit: aov(formula = leave ~ branch)

$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

Clearly from the first row of output, we can see the pairwise comparisons, and can clearly conclude that,

the,

branch 3 and branch 1 is significantly different in terms of mean leaves. (p value = 0.0017453)

branch 3 and branch 2 is significantly different in terms of mean leaves. (p value = 0.0000824)

branch 3 and branch 4 is significantly different in terms of mean leaves. (p value = 0.0043695)

at alpha = 0.05 level of significance.

So, clearly,the conclusion is,as per the data we have, Branch 3 is differing significantly from other branches at 0.05 level of significance.