dat<-ToothGrowth
head(dat)
## len supp dose
## 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.0 VC 0.5
str(dat)
## 'data.frame': 60 obs. of 3 variables:
## $ len : num 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 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
summary(dat)
## 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
library(ggplot2)
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
dat %>%
ggplot(aes(len))+
geom_boxplot()
dat %>%
ggplot(aes(len))+
geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
I installed the package “ToothGrowth” and subsequently called the functions “head”, “str” and “summary” in order to expand the data sets. Then, I created a box plot and a histogram respectively with the functions geom_boxplot() and geom_histogram().
H0 states that the Guinea Pig’s teeth is 17, while the alternative hypothesis states that the Guinea Pig’s teeth is 17 or above.
We need to execute a one-tailed test, as our alternative hypothesis is testing if the Guinea Pig’s teeth is 17 or ABOVE, rather than testing if the teeth is 17 or not.
We need to find the t-value, as we do not know what the standard deviation of the data set is.
sample_mean<-18.81
sample_size<-60
population_mean<-17
sample_sd<-3
t_value<-(sample_mean-population_mean)/(sample_sd/sqrt(sample_size))
answer<-1-pt(t_value, df=sample_size-1)
answer
## [1] 8.817918e-06
We cannot reject the null hypothesis, as the p-value of 8.82 is greater than the alpha (0.05).
sample_mean<-18.81
sample_size<-60
population_mean<-18
sample_sd<-3
H0 states that the Guinea Pig’s teeth is 18, while the alternative hypothesis states that the teeth is NOT 18.
We need to execute a two-tailed test, as the hypothesis is testing whether or not the hypothesized value is true or not.
sample_mean<-18.81
sample_size<-60
population_mean<-18
sample_sd<-3
t_value<-t_value<-(sample_mean-population_mean)/(sample_sd/sqrt(sample_size))
answer<-1-pt(t_value, df=sample_size-1)
p_value<-answer*2
p_value
## [1] 0.0408057
H0 should be rejected, as the p-value (0.04) is less than the alpha (significance range).