This page summarises the results for homework 4. The questions can be found on the corresponding homework sheet.

The following counts were obtained by inspecting the uploaded files, but without trying to run R yet.

- 327 students are enrolled in the module
- 258 out of 327 students (78.9%) submitted a solution
- 251 (97.3%) — probably an R script [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [249] [250] [251]
- 2 (0.8%) — possibly an R script, but without functions [1]
- 2 (0.8%) — no file attached
- 1 (0.4%) — probably an R script, but without functions [1]
- 1 (0.4%) — possibly an R script [1]
- 1 (0.4%) — not an R script, possibly Microsoft Word

- 254 out of 258 files (98.4%) can be marked

I tried to load all solutions which are possibly R scripts into R.

- 254 files were loaded into R

The following list shows some of the errors which prevented files from being loaded:

> ex25 <- function(n + n <- lm(y ~ x) Error: unexpected symbol in: "ex25 <- function(n n" Execution halted

[source]> ex22 <- function() {z <- read.csv("ex04-3.csv") + cov(z[,1], z[,5])/sd(z[,1])*sd(z[,5])) Error: unexpected ')' in: "ex22 <- function() {z <- read.csv("ex04-3.csv") cov(z[,1], z[,5])/sd(z[,1])*sd(z[,5]))" Execution halted

[source]> ex23 <- function(x, y) { + m <- lm(y ~ x) + beta <- coef(m)([2] Error: unexpected '[' in: " m <- lm(y ~ x) beta <- coef(m)([" Execution halted

[source]> ex23 <- { m<- lm(a~b) + coef(m) + } Error in eval(expr, envir, enclos) : object 'a' not found Calls: lm ... eval -> <Anonymous> -> model.frame.default -> eval -> eval Execution halted

[source]> ex23 <- function(x, y) {m <-lm(y~x) coef(m) Error: unexpected symbol in "ex23 <- function(x, y) {m <-lm(y~x) coef" Execution halted

[source]> ex22 <- function() { + z<- read.csv("ex04-3.csv") + > a <-z[,1] Error: unexpected '>' in: " z<- read.csv("ex04-3.csv") >" Execution halted

[source]> b <- a^2 Error: object 'a' not found Execution halted

[source]> ex22 <- function(x) { + d <- read.csv("ex04-3.csv") + c1 <- d[,1] + c5 <- d[,5] + cor(c1,c5) + + ex23 <- function(x,y) { + e <- read.csv("ex04-1.csv") + x1 <- e[,"x"] + y1 <- e[,"y"] + m <- lm(y1 ~ x1) + m + } + + ex24 <- function(x,y) { + f <- read.csv("ex04-1.csv") + x2 <- f[,"x"] + y2 <- f[,"y"] + m2 <- lm(y2 ~ x2) + fitted(m2)[7] + } + + ex25 <- function(m) { + g <- read.csv("ex04-1.csv") + x3 <- g[,"x"] + y3 <- g[,"y"] + m3 <- lm(y3 ~ x3) + o <- sum((resid(m))^2) + o + } + Error: unexpected end of input Execution halted

[source]> ex23 <- function(x, y){ + m <- 1m(y ~ x) Error: unexpected symbol in: "ex23 <- function(x, y){ m <- 1m" Execution halted

[source]

As an example, here is a (randomly chosen) student solution which got full marks:

ex19 <- function() { x <- read.csv("ex04-1.csv") }[source]

I called your function and checked whether the correct data set is returned.

- 250 answers were marked

As an example, here is a (randomly chosen) student solution which got full marks:

ex20 <- function(x) {read.csv("ex04-2.csv", sep=";") }[source]

I called your function and checked whether the correct data
is returned. This data set has columns separated by semicolons,
so the option `sep=";"` is required here.

- 251 answers were marked
- 194 (77.3%) — expected a 13x2 data frame but got a 13x1 data frame [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [192] [193] [194]
- 36 (14.3%) — ok [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [34] [35] [36]
- 12 (4.8%) — failed with error [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]
- 2 (0.8%) — expected a data frame but got NULL [1] [2]
- 2 (0.8%) — expected a 13x2 data frame but got a 14x1 data frame [1] [2]
- 2 (0.8%) — expected a 13x2 data frame but got a 12x2 data frame [1] [2]
- 2 (0.8%) — [1] [2]
- 1 (0.4%) — expected a 13x2 data frame but got a 871x6 data frame [1]

As an example, here is a (randomly chosen) student solution which got full marks:

ex21 <- function() { c <- read.csv("ex04-3.csv", header=F) }[source]

I called your function and checked whether the correct data
set is returned. This data set has no column headers, so the
option `header=FALSE` is required when importing these
data.

- 249 answers were marked
- 159 (63.9%) — expected a 872x6 data frame but got a 871x6 data frame [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [157] [158] [159]
- 75 (30.1%) — ok [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [73] [74] [75]
- 13 (5.2%) — failed with error [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]
- 2 (0.8%) — expected a data frame but got NULL [1] [2]

As an example, here is a (randomly chosen) student solution which got full marks:

ex22 <- function(z) {z <- read.csv("ex04-3.csv", header=FALSE) a=z[,1] b=z[,5] c=z[,1]-mean(a) d=z[,5]-mean(b) (sum(c*d))/(sqrt((sum(c^2))*(sum(d^2)))) }[source]

I called your function and checked whether the correct correlation is returned.

- 236 answers were marked
- 104 (44.1%) — expected 0.03464 but got 0.03916 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [102] [103] [104]
- 60 (25.4%) — ok [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [58] [59] [60]
- 53 (22.5%) — failed with error [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [51] [52] [53]
- 5 (2.1%) — expected 0.03464 but got a matrix [1] [2] [3] [4] [5]
- 2 (0.8%) — expected 0.03464 but got a data frame [1] [2]
- 2 (0.8%) — expected 0.03464 but got NULL [1] [2]
- 2 (0.8%) — expected 0.03464 but got 0.0327 [1] [2]
- 1 (0.4%) — expected 0.03464 but got an object of class htest [1]
- 1 (0.4%) — expected 0.03464 but got a function [1]
- 1 (0.4%) — expected 0.03464 but got 0.9864 [1]
- 1 (0.4%) — expected 0.03464 but got 0.04165 [1]
- 1 (0.4%) — expected 0.03464 but got 0.03682 [1]
- 1 (0.4%) — expected 0.03464 but got -0.02948 [1]
- 1 (0.4%) — expected 0.03464 but got -0.02441 [1]
- 1 (0.4%) — expected 0.03464 but got -0.0009795 [1]

As an example, here is a (randomly chosen) student solution which got full marks:

ex23 <- function(x, y) { lm(y~x)$coefficients[[2]] }[source]

For testing, I called your function twice, using two different sets of paired data. For each call I compared the output of your function to the output of my own function.

- 237 answers were marked
- 95 (40.1%) — first test: ok; second test: ok [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [93] [94] [95]
- 40 (16.9%) — failed with error [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [38] [39] [40]
- 36 (15.2%) — first test: expected 2 but got -0.01663; second test: expected -3.266 but got -0.01663 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [34] [35] [36]
- 25 (10.5%) — first test: expected 2 but got a linear model; second test: expected -3.266 but got a linear model [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [23] [24] [25]
- 12 (5.1%) — first test: expected 2 but got 0.5; second test: expected -3.266 but got -0.3035 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]
- 8 (3.4%) — first test: expected 2 but got NULL; second test: expected -3.266 but got NULL [1] [2] [3] [4] [5] [6] [7] [8]
- 4 (1.7%) — first test: expected 2 but got 9.826; second test: expected -3.266 but got 9.826 [1] [2] [3] [4]
- 2 (0.8%) — first test: expected 2 but got 0.9193; second test: expected -3.266 but got 0.9588 [1] [2]
- 2 (0.8%) — first test: expected 2 but got 0.3196; second test: expected -3.266 but got 0.3196 [1] [2]
- 2 (0.8%) — first test: expected 2 but got -0.02097; second test: expected -3.266 but got -0.02097 [1] [2]
- 1 (0.4%) — first test: expected 2 but got c(5, -1); second test: expected -3.266 but got c(5, -1) [1]
- 1 (0.4%) — first test: expected 2 but got c(1.15, -0.0807); second test: expected -3.266 but got c(0.13, -0.0412) [1]
- 1 (0.4%) — first test: expected 2 but got c(-1, 1); second test: expected -3.266 but got c(-1, 1) [1]
- 1 (0.4%) — first test: expected 2 but got c(-0.0785, -0.021); second test: expected -3.266 but got c(-0.0785, -0.021) [1]
- 1 (0.4%) — first test: expected 2 but got 3; second test: expected -3.266 but got 1.629 [1]
- 1 (0.4%) — first test: expected 2 but got 1; second test: expected -3.266 but got 1 [1]
- 1 (0.4%) — first test: expected 2 but got 0.9758; second test: expected -3.266 but got 0.9758 [1]
- 1 (0.4%) — first test: expected 2 but got 0.8469; second test: expected -3.266 but got 0.8469 [1]
- 1 (0.4%) — first test: expected 2 but got 0.03777; second test: expected -3.266 but got 0.03777 [1]
- 1 (0.4%) — first test: expected 2 but got -1; second test: expected -3.266 but got -1 [1]
- 1 (0.4%) — first test: expected 2 but got -0.1615; second test: expected -3.266 but got -0.4825 [1]

As an example, here is a (randomly chosen) student solution which got full marks:

ex24 <- function(x, y) {m<- lm(y~x) predict(m, newdata=data.frame(x=7)) }[source]

For testing, I called your function twice, using two different sets of paired data. For each call I compared the output of your function to the output of my own function.

- 241 answers were marked
- 60 (24.9%) — first test: ok; second test: ok [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [58] [59] [60]
- 51 (21.2%) — failed with error [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [49] [50] [51]
- 24 (10.0%) — first test: expected 15 but got NA; second test: expected -20.53 but got 6.522 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [22] [23] [24]
- 24 (10.0%) — first test: expected 15 but got 0.2015; second test: expected -20.53 but got 0.2015 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [22] [23] [24]
- 23 (9.5%) — first test: expected 15 but got 0.319; second test: expected -20.53 but got 0.319 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [21] [22] [23]
- 10 (4.1%) — first test: expected 15 but got c(15, 15, 15); second test: expected -20.53 but got a vector [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
- 10 (4.1%) — first test: expected 15 but got NULL; second test: expected -20.53 but got NULL [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
- 8 (3.3%) — first test: expected 15 but got c(1, 2, 3); second test: expected -20.53 but got a vector [1] [2] [3] [4] [5] [6] [7] [8]
- 3 (1.2%) — first test: expected 15 but got a linear model; second test: expected -20.53 but got a linear model [1] [2] [3]
- 3 (1.2%) — first test: expected 15 but got NA; second test: expected -20.53 but got -1.413 [1] [2] [3]
- 2 (0.8%) — first test: expected 15 but got c(3, 5, 7); second test: expected -20.53 but got a vector [1] [2]
- 2 (0.8%) — first test: expected 15 but got a vector; second test: expected -20.53 but got a vector [1] [2]
- 2 (0.8%) — first test: expected 15 but got a data frame; second test: expected -20.53 but got a data frame [1] [2]
- 2 (0.8%) — first test: expected 15 but got 3; second test: expected -20.53 but got -1.411 [1] [2]
- 2 (0.8%) — first test: expected 15 but got -1.351; second test: expected -20.53 but got -1.351 [1] [2]
- 2 (0.8%) — first test: expected 15 but got -0.1855; second test: expected -20.53 but got 0.03839 [1] [2]
- 2 (0.8%) — first test: expected 15 but got -0.05683; second test: expected -20.53 but got -0.05683 [1] [2]
- 1 (0.4%) — first test: expected 15 but got c(5, 5, 5); second test: expected -20.53 but got a vector [1]
- 1 (0.4%) — first test: expected 15 but got 7.588; second test: expected -20.53 but got 6.841 [1]
- 1 (0.4%) — first test: expected 15 but got 6.964; second test: expected -20.53 but got 6.964 [1]
- 1 (0.4%) — first test: expected 15 but got 5.051; second test: expected -20.53 but got 5.051 [1]
- 1 (0.4%) — first test: expected 15 but got 3; second test: expected -20.53 but got 3 [1]
- 1 (0.4%) — first test: expected 15 but got 0.5879; second test: expected -20.53 but got -0.159 [1]
- 1 (0.4%) — first test: expected 15 but got 0.3013; second test: expected -20.53 but got 0.3013 [1]
- 1 (0.4%) — first test: expected 15 but got 0.04584; second test: expected -20.53 but got 0.04584 [1]
- 1 (0.4%) — first test: expected 15 but got -2; second test: expected -20.53 but got -2 [1]
- 1 (0.4%) — first test: expected 15 but got -0.5; second test: expected -20.53 but got 0.7142 [1]
- 1 (0.4%) — first test: expected 15 but got -0.2253; second test: expected -20.53 but got -0.2253 [1]

As an example, here is a (randomly chosen) student solution which got full marks:

ex25 <- function(m) { rss <-sum(residuals(m)^2) rss }[source]

For testing, I called your function twice, using two different
linear models fitted using the `lm()` command. For each
call I compared the output of your function to the output of
my own function.

- 232 answers were marked
- 78 (33.6%) — first test: ok; second test: ok [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [76] [77] [78]
- 76 (32.8%) — failed with error [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [74] [75] [76]
- 52 (22.4%) — first test: expected 0.9027 but got 9.826; second test: expected 0.08389 but got 9.826 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [50] [51] [52]
- 10 (4.3%) — first test: expected 0.9027 but got NULL; second test: expected 0.08389 but got NULL [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
- 3 (1.3%) — first test: expected 0.9027 but got 12.39; second test: expected 0.08389 but got 12.39 [1] [2] [3]
- 2 (0.9%) — first test: expected 0.9027 but got a vector; second test: expected 0.08389 but got a vector [1] [2]
- 2 (0.9%) — first test: expected 0.9027 but got 5.443; second test: expected 0.08389 but got 6.114 [1] [2]
- 2 (0.9%) — first test: expected 0.9027 but got 4.58e-16; second test: expected 0.08389 but got -1.388e-17 [1] [2]
- 1 (0.4%) — first test: expected 0.9027 but got c(0, 0, 0, 0); second test: expected 0.08389 but got c(0, 0, 0, 0) [1]
- 1 (0.4%) — first test: expected 0.9027 but got 787.6; second test: expected 0.08389 but got 787.6 [1]
- 1 (0.4%) — first test: expected 0.9027 but got 5.974; second test: expected 0.08389 but got 6.155 [1]
- 1 (0.4%) — first test: expected 0.9027 but got 5.564; second test: expected 0.08389 but got 0.2346 [1]
- 1 (0.4%) — first test: expected 0.9027 but got 3.952; second test: expected 0.08389 but got 3.952 [1]
- 1 (0.4%) — first test: expected 0.9027 but got 0; second test: expected 0.08389 but got 0 [1]
- 1 (0.4%) — first test: expected 0.9027 but got -1.11e-16; second test: expected 0.08389 but got 5.204e-18 [1]

- 69 — not handed in
- 14 — 0.0 marks [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
- 76 — 0.5 marks [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [74] [75] [76]
- 14 — 1.0 marks [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]
- 43 — 1.5 marks [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [41] [42] [43]
- 21 — 2.0 marks [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [19] [20] [21]
- 44 — 2.5 marks [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [42] [43] [44]
- 8 — 3.0 marks [1] [2] [3] [4] [5] [6] [7] [8]
- 25 — 3.5 marks [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] … [23] [24] [25]
- 8 — 4.0 marks [1] [2] [3] [4] [5] [6] [7] [8]
- 2 — 4.5 marks [1] [2]
- 3 — 5.0 marks [1] [2] [3]