Browsing resource, all submissions are temporary.
In one of Week 7's assignments, you were asked to write a function to calculate the 100(1-level)% confidence interval for the mean for a given numeric vector x. Consider two such functions CImean1() and CImean2() below.
CImean1()
CImean2()
CImean1 <- function(x, level=0.95) { xbar <- mean(x) w <- -qnorm((1-level)*0.5)*sqrt(var(x)/length(x)) c(xbar-w, xbar+w) }
CImean2 <- function(x, level=0.95) { w <- -qnorm((1-level)*0.5)*sqrt(var(x)/length(x)) xbar <- mean(x) c(xbar-w, xbar+w) }
The two functions are practically the same except the first two lines are switched. They produce the same output for any given values of x and level.
x
level
Now consider the following function calls:
(i)
set.seed(32126) CImean1(runif(57), runif(1, 0.6,0.99))
(ii)
set.seed(32126) CImean2(runif(57), runif(1, 0.6,0.99))
a. Are the returned numbers in (i) and (ii) exactly the same? yes no
Consider the following 4 function calls:
(iii)
set.seed(32126) x1 <- runif(57) level1 <- runif(1, 0.6,0.99) CImean1(x1,level1)
(iv)
set.seed(32126) level2 <- runif(1, 0.6,0.99) x2 <- runif(57) CImean1(x2,level2)
(v)
set.seed(32126) x1 <- runif(57) level1 <- runif(1, 0.6,0.99) CImean2(x1,level1)
(vi)
set.seed(32126) level2 <- runif(1, 0.6,0.99) x2 <- runif(57) CImean2(x2,level2)
b. Are the numbers in x1 and x2 identical? yes no
x1
x2
c. Are level1 and level2 identical? yes no
level1
level2
d. Are the numbers returned by CImean1(x1,level1) exactly the same as those returned by CImean2(x1,level1)? yes no
CImean1(x1,level1)
CImean2(x1,level1)
e. Are the numbers returned by CImean1(x2,level2) exactly the same as those returned by CImean2(x2,level2)? yes no
CImean1(x2,level2)
CImean2(x2,level2)
f. Which of the following function calls return the exact same numbers as the call in (i)? (Select all that apply) (iii) (iv) (v) (vi) None of the above
g. Which of the following function calls return the exact same numbers as the call in (ii)? (Select all that apply) (iii) (iv) (v) (vi) None of the above