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.35, 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.35)? (Select all that apply)
pn(-1.35)
pn(1.35,"right")
pn(1.35, area="middle")
pn()
pn(z=1.35,"right")
pn(1.35, lower.tail=FALSE)
pn(1.35)
pn(z=1.35, area="right")

 Tries 0/3

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





 Tries 0/2

c. What is the result of running pn(-1.14, "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.3
f(2.26)

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

 Tries 0/3