# Exercise 4.1 aggregate(circumference ~ Tree, data = Orange, FUN = mean) A <- matrix(c(1, 1, 1, 3, 2, 4, 5, -3, 2), 3, 3, byrow = TRUE) k <- matrix(c(3, 7, 5)) x <- solve(A) %*% k solve(A, k) # Exercise 4.2 cor.test(cars$speed, cars$dist) temp <- data.frame(Seatbelts) t.test(DriversKilled ~ law, data = temp, var.equal = TRUE) chisq.test(occupationalStatus) # Assignment 4 compliance <- c(30, 58, 25, 54, 79, 48, 29, 52, 54, 45, 23, 45, 58, 58, 40, 55, 61, 35, 50, 55, 60, 47, 73, 45, 69, 84, 37, 77, 50, 48, 74, 35, 43, 58, 60, 35, 49, 87, 49, 79) personnel <- c(26, 46, 38, 49, 58, 40, 47, 60, 64, 46, 31, 48, 58, 58, 39, 36, 51, 44, 49, 52, 45, 52, 56, 35, 44, 62, 34, 52, 60, 35, 46, 43, 48, 51, 42, 44, 48, 63, 29, 49) place <- c(47, 35, 47, 34, 57, 48, 33, 38, 47, 51, 27, 64, 53, 58, 42, 34, 41, 20, 43, 41, 44, 54, 56, 55, 56, 69, 48, 53, 53, 47, 54, 28, 52, 64, 51, 62, 43, 73, 49, 68) method <- c(47, 41, 44, 34, 61, 45, 61, 42, 51, 56, 35, 67, 52, 60, 62, 48, 48, 46, 44, 57, 35, 41, 45, 59, 51, 56, 48, 47, 40, 39, 58, 24, 45, 51, 45, 53, 45, 71, 37, 58) time <- c(8, 8, 8, 9, 10, 11, 4, 8, 8, 7, 9, 9, 9, 8, 5, 5, 4, 6, 9, 10, 5, 1, 9, 3, 4, 7, 6, 6, 3, 7, 4, 5, 3, 2, 1, 4, 4, 6, 4, 6) sex <- factor(rep(1:2, each = 20), labels = c("male", "female")) dat <- data.frame(compliance, personnel, place, method, time, sex) t.test(personnel ~ sex, data = dat, var.equal = TRUE) boxplot(personnel ~ sex, data = dat) aggregate(personnel ~ sex, data = dat, FUN = mean) aggregate(personnel ~ sex, data = dat, FUN = sd) cor(dat[,1:4]) t.test(dat$time, mu = 7) cor.test(dat$time, dat$personnel) plot(dat$time, dat$personnel) time2 <- rep(1, 40) time2[time >= 5] <- 2 time2[time > 8] <- 3 time2 <- ordered(time2, labels = c("1-4", "5-8", ">8")) tab <- table(sex, time2) chisq.test(tab, correct = FALSE)