title: “lab1” author: “soon” date: “3/23/2022” output: html_nodocument: df_print: paged–
1i)
c <- list("setosa","versicolor","virginica")
for(x in c)
{
data <- iris %>% filter(Species == x) %>% select(Petal.Length)
message("variance :" ,x)
print(apply(data,2,var))
}
## variance :setosa
## Petal.Length
## 0.03015918
## variance :versicolor
## Petal.Length
## 0.2208163
## variance :virginica
## Petal.Length
## 0.3045878
for(y in c)
{
data2 <- iris %>% filter(Species == y) %>% select(Petal.Width)
message("average :", y)
print(apply(data2,2,mean))
}
## average :setosa
## Petal.Width
## 0.246
## average :versicolor
## Petal.Width
## 1.326
## average :virginica
## Petal.Width
## 2.026
1ii)
print("median of the petal width")
## [1] "median of the petal width"
tapply(iris$Petal.Width, iris$Species, median)
## setosa versicolor virginica
## 0.2 1.3 2.0
print("3rd quartile of the sepal length")
## [1] "3rd quartile of the sepal length"
tapply(iris$Sepal.Length, iris$Species, quantile, probs=0.75)
## setosa versicolor virginica
## 5.2 6.3 6.9
2i
Based the recorded forces from the table, the current wire is meets the
customer’s specifications. This is because all recorded forces needed
for current wire are more than 20 pounds. Therefore, the current wires
achieve customer’s demand, which is minimum of 20 pounds.
2ii
sample1= c(28.8, 24.4,30.1,25.6,26.4,23.9,22.1,22.5,27.6,28.1,20.8,27.7,24.4,25.1,24.6,26.3,28.2,22.2,26.3,24.4)
sample2 = c(14.1,12.2,14.0,14.6,8.5,12.6,13.7,14.8,14.1,13.2,12.1,11.4,10.1,14.2,13.6,13.1,11.9,14.8,11.1,13.5)
message("sample average for current :", mean(sample1))
## sample average for current :25.475
message("sample variance for current :", var(sample1))
## sample variance for current :6.21776315789474
message("sample average for new :", mean(sample2))
## sample average for new :12.88
message("sample variance for new :", var(sample2))
## sample variance for new :2.75852631578947
2iii
Before to answer the question, variance is the average of the square of
distance that each value is from the mean. It means if the values are
near to the mean, the variance will be small and vice versa.
I will recommend not to changing electrical wire harness and keep using the old ones. This is because the average of pull the spliced wires apart for the current wire (mean=25.475) is higher than the new wire (mean=12.88), which is stastify the customer demand, minimum of 20 pounds to pull the spliced wires apart for the present wire. While the mean of new wire are not meet the requirement.
The variability of data for current wire is much higher than the new wire. It means the data for new wire have stronger consistency, more reliable than the current wire. But i will not take it into consideration due to the mean for new wire cannot achieve the customer requirement, which is minimum of 20 pounds to pull the spliced wires apart