x <- c(5260,5470,5640,6180,6390,6515,6805,7515,7515,8230,8770)
# (i)
mean(x)
## [1] 6753.636
# (ii)
sd(x)
## [1] 1142.123
x<-sqrt((x-(mean(x)))^2/length(x))
x
## [1] 450.34831 387.03093 335.77400 172.95787 109.64049 71.95157 15.48672
## [8] 229.55977 229.55977 445.14039 607.95651
# (iii)
var(x)
## [1] 33717.7
~Question no 1(2)
boxplot(x)
#Interpetation: we get the value of p = 0.018 which isless then alpha value 0.05 so reject the Ho and conclude that the intake hypothesis deviate is not 7725.
n<-length(x)
shapiro.test(x)
##
## Shapiro-Wilk normality test
##
## data: x
## W = 0.96747, p-value = 0.8599
t.test(x, mu=7725,alternative="two.sided",conf.level = 0.95)
##
## One Sample t-test
##
## data: x
## t = -134.51, df = 10, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 7725
## 95 percent confidence interval:
## 154.4041 401.1244
## sample estimates:
## mean of x
## 277.7642
t<- (mean(x)-7725)/(sd(x)/sqrt(n))
t
## [1] -134.5125
#Chi-Square Test of Independence
mydata<- matrix(c(120,110,90,95,40,45),nrow=2)
colnames(mydata)<-c("Republican","Democratic","Independent")
rownames(mydata)<-c("Male","Female")
mydata
## Republican Democratic Independent
## Male 120 90 40
## Female 110 95 45
chi_square_test <- chisq.test(mydata)
print(chi_square_test)
##
## Pearson's Chi-squared test
##
## data: mydata
## X-squared = 0.86404, df = 2, p-value = 0.6492
chi.sq<-function(matrix){
row_totals <- rowSums(matrix)
col_totals <- colSums(matrix)
total <- sum(matrix)
expected_values <- outer(row_totals, col_totals) / total
chi_square_statistic <- sum((matrix - expected_values)^2 / expected_values)
cat("Calculated value of chi-square = ", chi_square_statistic, "\n")
}
observed_values<- matrix(c(120,110,90,95,40,45),nrow=2)
colnames(mydata)<-c("Republican","Democratic","Independent")
rownames(mydata)<-c("Male","Female")
print(observed_values)
## [,1] [,2] [,3]
## [1,] 120 90 40
## [2,] 110 95 45
chi.sq(observed_values)
## Calculated value of chi-square = 0.8640354
data_list <- list(
studenta = c(52, 46, 62, 48, 57, 54),
studentb = c(63, 49, 64, 53, 68),
studentc = c(63, 65, 58, 70, 71, 73)
)
result <- kruskal.test(data_list)
print(result)
##
## Kruskal-Wallis rank sum test
##
## data: data_list
## Kruskal-Wallis chi-squared = 8.3472, df = 2, p-value = 0.0154