1. LON-CAPA Logo
  2. Help
  3. Log In
 

Browsing resource, all submissions are temporary.


Functions in R

a. Suppose I define the following function in R.

pn <- function(z=1.1, area="right") {
  p <- 0
  if (area=="right") {
    # compute the right-tail area
    p <- pnorm(-z)
  } else if (area=="left") {
    # compute the left-tail area
    p <- pnorm(z)
  } else if (area=="middle") {
    # compute the middle area
    p <- 1-2*pnorm(-abs(z))
  } else {
    # compute the two-tails area
    p <- 2*pnorm(-abs(z))
  }
  p
}

Which of the following commands give the same result as pnorm(-1.1)? (Select all that apply)
pn(z=1.1, area="right")
pn(1.1,"right")
pn(-1.1)
pn(z=1.1,"right")
pn(1.1, lower.tail=FALSE)
pn(1.1)
pn()
pn(1.1, area="middle")

 Tries 0/3

b. What is the result of running pn(-1.56)?





 Tries 0/2

c. What is the result of running pn(-1.13, "left")?





 Tries 0/2

d. A function f is defined as follows.


f <- function(z) {
        pow <- function(x) {
                x^n
        }
        n <- z - floor(z)
        pow(z+1)
}

Suppose I run the following commands


n <- 1.61
f(2.7)

What value is returned by 'f'? Give your answer to 3 decimal places.

 Tries 0/3