library(splines)
ratings= c(8,7,6.5,7.5,6.5,10,8.5,8,7,10,55)
mean(ratings)
## [1] 12.18182
median(ratings)
## [1] 8
var(ratings)
## [1] 203.1636
sd(ratings)
## [1] 14.25355
min(ratings)
## [1] 6.5
max(ratings)
## [1] 55
quantile(ratings, 0.25)
## 25%
## 7
quantile(ratings, 0.50)
## 50%
## 8
quantile(ratings, 0.75)
## 75%
## 9.25
IQR = IQR(ratings)
quantile(ratings, 0.45)
## 45%
## 7.75
No I believe there is a mistake in the data because there is an outlier of 55 skewing the data affecting the mean and variance.
boxplot(ratings)
quantile(ratings, c(0.25,0.50,0.75)) #3 quantiles
## 25% 50% 75%
## 7.00 8.00 9.25
cat("Min=", min(ratings), "Max=", max(ratings)) #assigning min and max
## Min= 6.5 Max= 55
#finding lower and upper fences
cat("Upper Fence=",quantile(ratings,0.75) + 1.5 * IQR(ratings))
## Upper Fence= 12.625
cat("Lower Fence=", quantile(ratings,0.25) - 1.5 * IQR(ratings))
## Lower Fence= 3.625
#discard any values in the data outside the lower and upper fence since these are identified as outliers and recalculate mean, median, variance and IQR.
ratings= c(8,7,6.5,7.5,6.5,10,8.5,8,7,10)
mean(ratings)
## [1] 7.9
median(ratings)
## [1] 7.75
var(ratings)
## [1] 1.655556
IQR(ratings)
## [1] 1.375
Also explain what you are doing in this part here.
The lower and upper fence of the data set was calculated using the IQR and quantiles to determine outliers. After the fences are determined, “ratings” was redefined excluding the outlier (55) and the mean, median, var and IQR were recalculated.
bodyfat_data = read.csv(url("https://hbiostat.org/data/repo/bodyfat.csv"))
data("mtcars")
Density, BodyFat, Age, Weight, Height, Neck, Chest, Abdomen, Hip, Thigh, Knee, Ankle, Biceps, Forearm, Wrist.
colnames(bodyfat_data)
Weight = bodyfat_data$Weight
mean(Weight)
## [1] 178.9244
median(Weight)
## [1] 176.5
var(Weight)
## [1] 863.7227
#sample mean and median are equal to population mean and median
t.test(Weight, conf.level = 0.95)$conf.int
## [1] 175.2783 182.5706
## attr(,"conf.level")
## [1] 0.95
95 confidence interval for population mean is (175.2783,182.5706)
t.test(Weight, conf.level = 0.90)$conf.int
## [1] 175.8679 181.9809
## attr(,"conf.level")
## [1] 0.9
90 confidence intveral for pop mean is (175.8679,181.9809)
t.test(bodyfat_data, alternative= "two.sided", mu=25, conf.level = 0.95)
##
## One Sample t-test
##
## data: bodyfat_data
## t = 42.478, df = 3779, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 25
## 95 percent confidence interval:
## 54.93212 57.82886
## sample estimates:
## mean of x
## 56.38049
The test statistic is 42.478. The p-value found is 2.2e-16 and our significance level was 0.05, since the p-value is less than 0.05, we can reject the null hypothesis.
t.test(bodyfat_data,alternative="less", mu = 17,conf.level = 0.95)
##
## One Sample t-test
##
## data: bodyfat_data
## t = 53.307, df = 3779, p-value = 1
## alternative hypothesis: true mean is less than 17
## 95 percent confidence interval:
## -Inf 57.59591
## sample estimates:
## mean of x
## 56.38049
Test statistic= 52.307. The p-pvalue is 1 and our significance level was 0.05, since our p-value is greater than the significance level we fail to reject the null hypothesis since there is not enough statistical evidence to conclude.