R Markdown

rm(list=ls())
3.1  
## [1] 3.1
#Import dataset 
dat4<-read.csv("D:/Users/cse/Downloads/dat4.csv")
head(dat4)
attach(dat4)
Company=as.factor(Company)
str(dat4)
## '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(dat4)
##        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
sd(dat4$Concentration)
## [1] 1.797305
3.2
## [1] 3.2
#  Histogram of concentrations
hist(Concentration, main="Distribution of Tablet Concentrations", xlab ="Concentration(mg)")

# Boxplot by company 
boxplot(Concentration~Company,data=dat4,main="Tablet Concentrations by Company",xlab = "Company",ylab="Concentration (mg)")

min=min(dat4$concentration)
## Warning in min(dat4$concentration): no non-missing arguments to min; returning
## Inf
max=max(dat4$Concentration)
Q1=98.89
Q3=101.17
Q3-Q1
## [1] 2.28
max-min
## [1] -Inf
3.3
## [1] 3.3
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
3.4 
## [1] 3.4
#Company A vs Company B
t.test(Concentration~Company,data=subset(dat4,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
3.5
## [1] 3.5
# Perform ANOVA
anova_model <-aov(Concentration~Company,data=dat4)
#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