# Problem 1: Daniel Dewitt Cme 195: Introduction To R Xiaotong Suo Mcclure Assignment #2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Daniel DeWitt

CME 195: Introduction to R


Xiaotong Suo McClure
Assignment #2
# Problem 1
n <- 12;
# n is 12 here, but it can take any positive integer value
i <- c(0:n);
sum((-1)^i*choose(n,i));
# the sum returns 0 for all positive integer values of n

# Problem 2
U1 <- runif(1000);
U2 <- runif(1000);
Z <- sqrt(-2*log(U1))*cos(2*pi*U2);
# 1
p1 <- sum(Z >= 0)/1000;
q1 <- 1 - pnorm(0);
# p1 was found to be 0.487
# q1 was found to be 0.500
# pnorm()computes the area of the probability distribution function
# of a normal distribution below the number passed in as an argument
# 2
p2 <- sum(Z > 0 & Z <= 1)/1000;
q2 <- pnorm(1) - pnorm(0);
# p2 was found to be 0.333
# q2 was found to be 0.341
# 3
p3 <- sum(Z > 1 & Z <= 2)/1000;
q3 <- pnorm(2) - pnorm(1);
# p3 was found to be 0.131
# q3 was found to be 0.134
# 4
p4 <- sum(Z > 2)/1000;
q4 <- 1 - pnorm(2);
# p4 was found to be 0.023
# q4 was found to be 0.024

You might also like