Below are the solutions to these exercises on inferential statistics.

#################### # # # Exercise 1 # # # #################### f_1 <- rnorm(28,29,3) f_2 <- rnorm(23,29,6) f <- sd(f_1)^2/sd(f_2)^2;f

## [1] 0.253262

#OR f <- var(f_1)/var(f_2); f

## [1] 0.253262

#################### # # # Exercise 2 # # # #################### df_num <- length(f_1)-1; df_num

## [1] 27

df_den <- length(f_2)-1; df_den

## [1] 22

#################### # # # Exercise 3 # # # #################### two_sided_test <- var.test(f_1,f_2,alternative = "two.sided") two_sided_test

## ## F test to compare two variances ## ## data: f_1 and f_2 ## F = 0.25326, num df = 27, denom df = 22, p-value = 0.0009226 ## alternative hypothesis: true ratio of variances is not equal to 1 ## 95 percent confidence interval: ## 0.1101789 0.5626353 ## sample estimates: ## ratio of variances ## 0.253262

#################### # # # Exercise 4 # # # #################### one_sided_test <- var.test(f_1,f_2,alternative = "less") one_sided_test

## ## F test to compare two variances ## ## data: f_1 and f_2 ## F = 0.25326, num df = 27, denom df = 22, p-value = 0.0004613 ## alternative hypothesis: true ratio of variances is less than 1 ## 95 percent confidence interval: ## 0.0000000 0.4938655 ## sample estimates: ## ratio of variances ## 0.253262

#################### # # # Exercise 5 # # # #################### two_sided_test$estimate

## ratio of variances ## 0.253262

two_sided_test$p.value

## [1] 0.0009226243

one_sided_test$estimate

## ratio of variances ## 0.253262

one_sided_test$p.value

## [1] 0.0004613122

#################### # # # Exercise 6 # # # #################### positive <- length(data$class[which(data$class==1)]) negative <- length(data$class[which(data$class==0)]) #OR positive <- sum(data$class); positive

## [1] 268

negative <- length(data$class)-positive; negative

## [1] 500

#################### # # # Exercise 7 # # # #################### prob <- c(0.10,0.90) res <- c(positive,negative) chisq.test(res, p=prob)

## ## Chi-squared test for given probabilities ## ## data: res ## X-squared = 528.9, df = 1, p-value < 2.2e-16

#################### # # # Exercise 8 # # # #################### TP <- length(data$class[which(data$class==1 & data$mass >= mean(data$mass))]) FP <- length(data$class[which(data$class==1 & data$mass < mean(data$mass))]) TN <- length(data$class[which(data$class==0 & data$mass < mean(data$mass))]) FN <- length(data$class[which(data$class==0 & data$mass >= mean(data$mass))]) res_mut <- matrix(c(TP,FP,TN,FN),2,byrow=TRUE); res_mut

## [,1] [,2] ## [1,] 184 84 ## [2,] 289 211

#################### # # # Exercise 9 # # # #################### chisq.test(res_mut)

## ## Pearson's Chi-squared test with Yates' continuity correction ## ## data: res_mut ## X-squared = 8.2403, df = 1, p-value = 0.004097

#################### # # # Exercise 10 # # # #################### TP <- length(data$class[which(data$class==1 & data$mass >= quantile(data$mass, 0.25))]) FP <- length(data$class[which(data$class==1 & data$mass < quantile(data$mass, 0.25))]) TN <- length(data$class[which(data$class==0 & data$mass < quantile(data$mass, 0.25))]) FN <- length(data$class[which(data$class==0 & data$mass >= quantile(data$mass, 0.25))]) res_mut <- matrix(c(TP,FP,TN,FN),2,byrow=TRUE); res_mut

## [,1] [,2] ## [1,] 248 20 ## [2,] 170 330

chisq.test(res_mut)

## ## Pearson's Chi-squared test with Yates' continuity correction ## ## data: res_mut ## X-squared = 238.68, df = 1, p-value < 2.2e-16

## Leave a Reply