Input data

library(readxl)
## Warning: package 'readxl' was built under R version 4.0.3
X19_10_20_Black_soldier_fly <- read_excel("C:/Users/Admin/Desktop/LR of BSL/19.10.20 Black soldier fly.xlsx", sheet = "Tukey", col_types = c("text", 
"numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric"))
## Warning in strptime(x, format, tz = tz): unable to identify current timezone 'C':
## please set environment variable 'TZ'
attach(X19_10_20_Black_soldier_fly)

General view of the relationship between Treatment and Final body weight

require(ggplot2)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.0.3
h=ggplot(X19_10_20_Black_soldier_fly,aes(x=Treatment,y=`Final weight (g)`))
h+geom_boxplot()+theme_bw()+theme_classic()

Assumption 1: All samplems are independent and >2 categorical groups (if equal 2=> t-test).

X19_10_20_Black_soldier_fly$Treatment=as.factor(X19_10_20_Black_soldier_fly$Treatment)
# treatment as factor checking
class(X19_10_20_Black_soldier_fly$Treatment)
## [1] "factor"

Assumption 2: Denpendent variable is continuous (all denpendent variables are already continous)

Assumption 3: Normal distribution (in each group)

shapiro.test(`Final weight (g)`)
## 
##  Shapiro-Wilk normality test
## 
## data:  Final weight (g)
## W = 0.90585, p-value = 0.117

Assumption 4 Homogeneity of variances (p>0.05 => variances are Homogeneity)

bartlett.test(`Final weight (g)`~Treatment,data=X19_10_20_Black_soldier_fly)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  Final weight (g) by Treatment
## Bartlett's K-squared = 5.5779, df = 4, p-value = 0.233

ANOVA test

Final_BW= aov(`Final weight (g)`~Treatment)
summary(Final_BW)
##             Df Sum Sq Mean Sq F value  Pr(>F)    
## Treatment    4  536.7   134.2   14.43 0.00037 ***
## Residuals   10   93.0     9.3                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#Posthoc test by Tukey

require(lsmeans)
## Loading required package: lsmeans
## Warning: package 'lsmeans' was built under R version 4.0.3
## Loading required package: emmeans
## Warning: package 'emmeans' was built under R version 4.0.3
## The 'lsmeans' package is now basically a front end for 'emmeans'.
## Users are encouraged to switch the rest of the way.
## See help('transition') for more information, including how to
## convert old 'lsmeans' objects and scripts to work with 'emmeans'.
require(multcomp)
## Loading required package: multcomp
## Warning: package 'multcomp' was built under R version 4.0.3
## Loading required package: mvtnorm
## Warning: package 'mvtnorm' was built under R version 4.0.3
## Loading required package: survival
## Loading required package: TH.data
## Warning: package 'TH.data' was built under R version 4.0.3
## Loading required package: MASS
## Warning: package 'MASS' was built under R version 4.0.3
## 
## Attaching package: 'TH.data'
## The following object is masked from 'package:MASS':
## 
##     geyser
Posthoc_Final_weight=lsmeans(Final_BW,pairwise~Treatment,adjust="Tukey")
cld(Posthoc_Final_weight[[1]],alpha=0.05,Letters=letters)
##  Treatment lsmean   SE df lower.CL upper.CL .group
##  0%BSF       30.1 1.76 10     26.2     34.0  a    
##  5%BSF       32.7 1.76 10     28.8     36.7  ab   
##  10%BSF      34.9 1.76 10     31.0     38.8  ab   
##  15%BSF      38.6 1.76 10     34.7     42.5   b   
##  20%BSF      47.3 1.76 10     43.4     51.2    c  
## 
## Confidence level used: 0.95 
## P value adjustment: tukey method for comparing a family of 5 estimates 
## significance level used: alpha = 0.05

Visualization

level_order=c("0%BSF","5%BSF","10%BSF","15%BSF","20%BSF")
h=ggplot(X19_10_20_Black_soldier_fly,aes(x=factor(Treatment,level_order),y=`Final weight (g)`))
h+stat_summary(fun="mean",geom="bar",fill=("blue"),width=0.5)+stat_summary(geom = "errorbar", fun.data=mean_se,position="dodge",width=0.2)+theme_bw()+theme_classic()+stat_summary(geom= 'text', fun.y = max,position=position_dodge(.7), label = c("a","ab","ab","b","c"), vjust =-0.3)+xlab("Treatment")
## Warning: `fun.y` is deprecated. Use `fun` instead.