Paet A

making the required distribution

lamda=0.2
vec=vector()
for (i in 1:1000){
   dist=rexp(40,lamda)
   me=mean(dist)
   vec=c(vec,me)
}

plot of distribution histogram wth mean values

library(ggplot2)
vec=data.frame(vec)
g=ggplot(vec,aes(vec))+geom_density(lwd=1,color="black")
g+geom_histogram(color="black",bins = 40,fill="green",aes(y = ..density..))+ggtitle("Histogram of exponential distribution")+labs(x="Mean values")+geom_vline(xintercept =1/lamda, color = "red", size=1)+geom_vline(xintercept =mean(vec$vec), color = "blue", size=1)

### CI form obtained values

CIGraph=mean(vec$vec)+c(-1,1)*qnorm(0.975)*sd(vec$vec)/sqrt(1000)
CIGraph
## [1] 4.973252 5.070751

CI from theoritical values

CITheory=(1/lamda)+c(-1,1)*qnorm(0.975)*(1/lamda)/sqrt(1000)
CITheory
## [1] 4.690102 5.309898

Lokks like a normal distribution

g=ggplot(vec,aes(vec))
g=ggplot(vec,aes(vec))+geom_density(lwd=1,color="black")
g+geom_histogram(color="black",bins = 40,fill="magenta",aes(y = ..density..))+ggtitle("Histogram of exponential distribution")+labs(x="Mean values")

## Part 2 ###Identify the data

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(datasets)
data=tbl_df(ToothGrowth)
## Warning: `tbl_df()` is deprecated as of dplyr 1.0.0.
## Please use `tibble::as_tibble()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
data1=tbl_df(ToothGrowth)
data
## # A tibble: 60 x 3
##      len supp   dose
##    <dbl> <fct> <dbl>
##  1   4.2 VC      0.5
##  2  11.5 VC      0.5
##  3   7.3 VC      0.5
##  4   5.8 VC      0.5
##  5   6.4 VC      0.5
##  6  10   VC      0.5
##  7  11.2 VC      0.5
##  8  11.2 VC      0.5
##  9   5.2 VC      0.5
## 10   7   VC      0.5
## # ... with 50 more rows

####summary of the data

summary(data)
##       len        supp         dose      
##  Min.   : 4.20   OJ:30   Min.   :0.500  
##  1st Qu.:13.07   VC:30   1st Qu.:0.500  
##  Median :19.25           Median :1.000  
##  Mean   :18.81           Mean   :1.167  
##  3rd Qu.:25.27           3rd Qu.:2.000  
##  Max.   :33.90           Max.   :2.000
str(data)
## tibble [60 x 3] (S3: tbl_df/tbl/data.frame)
##  $ len : num [1:60] 4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
##  $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
##  $ dose: num [1:60] 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
require(graphics)
coplot(len ~ dose | supp, data = ToothGrowth, panel = panel.smooth,
       xlab = "ToothGrowth data: length vs dose, given type of supplement")

data$dose = as.factor(data$dose)
ggplot(aes(y=len), data =data) + 
        geom_boxplot(aes(fill=dose)) + 
        ggtitle("Tooth Length by dose Amount") + 
        xlab("Dose") + 
        ylab("Tooth Length") +
        facet_grid(~supp) 

###t test to identify the relation of suppliment type

t1= t.test(len ~ supp, data =data)
t1
## 
##  Welch Two Sample t-test
## 
## data:  len by supp
## t = 1.9153, df = 55.309, p-value = 0.06063
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1710156  7.5710156
## sample estimates:
## mean in group OJ mean in group VC 
##         20.66333         16.96333

###t test to identify the relation of dose amount

d1 = data1[data1$dose == 0.5, 1]
d2 = data1[data1$dose == 1, 1]
t2 = t.test(d1, d2)
d3 = data[data1$dose == 2, 1]
t3 = t.test(d1, d3)
t2
## 
##  Welch Two Sample t-test
## 
## data:  d1 and d2
## t = -6.4766, df = 37.986, p-value = 1.268e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -11.983781  -6.276219
## sample estimates:
## mean of x mean of y 
##    10.605    19.735
t3
## 
##  Welch Two Sample t-test
## 
## data:  d1 and d3
## t = -11.799, df = 36.883, p-value = 4.398e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -18.15617 -12.83383
## sample estimates:
## mean of x mean of y 
##    10.605    26.100
t4 = t.test(d2, d3)
t4
## 
##  Welch Two Sample t-test
## 
## data:  d2 and d3
## t = -4.9005, df = 37.101, p-value = 1.906e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -8.996481 -3.733519
## sample estimates:
## mean of x mean of y 
##    19.735    26.100

Conclusions

Dose does not affect the teeth grow as they have a really small p values and the mean values does not lie in the confident intervals and supplement type also does not affects the growth of teeth