#import

dat1=read.csv("C:/VAN's/dat4.csv",header= T)
head(dat1)
##   ID Company Concentration
## 1  1       A        101.09
## 2  2       A         99.95
## 3  3       A        101.37
## 4  4       A        102.94
## 5  5       A         99.78
## 6  6       A         99.78
attach(dat1)
Company=as.factor(Company)
str(dat1)
## 'data.frame':    100 obs. of  3 variables:
##  $ ID           : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ Company      : chr  "A" "A" "A" "A" ...
##  $ Concentration: num  101.1 100 101.4 102.9 99.8 ...
summary(dat1)
##        ID           Company          Concentration   
##  Min.   :  1.00   Length:100         Min.   : 96.02  
##  1st Qu.: 25.75   Class :character   1st Qu.: 98.89  
##  Median : 50.50   Mode  :character   Median : 99.98  
##  Mean   : 50.50                      Mean   :100.02  
##  3rd Qu.: 75.25                      3rd Qu.:101.17  
##  Max.   :100.00                      Max.   :103.97

#data visualization

#Histogram of concentration 
hist(Concentration,
main="Distribution of Tablet Concentrations",
xlab="Concentration (mg)" ,col=c("brown"))

#Boxplot by company 
boxplot(Concentration~Company,
main="Tablet Concentrations by Company",
xlab="Company",
ylab="Concentration (mg)" ,col=c("purple","green","pink"))

#one way t-test

t.test(Concentration, mu=100)
## 
##  One Sample t-test
## 
## data:  Concentration
## t = 0.099037, df = 99, p-value = 0.9213
## alternative hypothesis: true mean is not equal to 100
## 95 percent confidence interval:
##   99.66118 100.37442
## sample estimates:
## mean of x 
##  100.0178

#two sample test

#Company A vs company B
t.test(Concentration~Company,
data=subset(dat1,Company %in% c("A","B")))
## 
##  Welch Two Sample t-test
## 
## data:  Concentration by Company
## t = 1.9312, df = 64.692, p-value = 0.05784
## alternative hypothesis: true difference in means between group A and group B is not equal to 0
## 95 percent confidence interval:
##  -0.02577558  1.53172923
## sample estimates:
## mean in group A mean in group B 
##        99.91176        99.15879

#one way anova

#Perform ANOVA
anova_model=aov(Concentration~Company, data=dat1)
#Display ANOVA table
summary(anova_model)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## Company      2  55.67  27.836   10.22 9.36e-05 ***
## Residuals   97 264.13   2.723                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1