Maths Lab Assignment - Sugandha

You might also like

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

Maths Lab Assignment

Sugandha Chaudhary

CSE-5

Q15)
a)input:
# define the joint probability mass function
f <- function(x, y) {
ifelse(x %in% c(0, 1, 2) & y %in% c(5, 10), (x*y + 3*y)/180, 0)
}

# compute the marginal distribution of X


f_X <- function(x) {
sum(f(x, c(5, 10)))
}

# compute the marginal distribution of Y


f_Y <- function(y) {
sum(f(c(0, 1, 2), y))
}

# compute and print the marginal distributions


xs <- 0:2
ys <- c(5, 10)
fx <- sapply(xs, f_X)
fy <- sapply(ys, f_Y)
cat("Marginal distribution of X:\n")
print(fx)
cat("Marginal distribution of Y:\n")
print(fy)
output:
Marginal distribution of X:
> print(fx)
[1] 0.2500000 0.3333333 0.4166667
> cat("Marginal distribution of Y:\n")
Marginal distribution of Y:
> print(fy)
[1] 0.3333333 0.6666667
>

b) # Define the joint probability mass function


f <- function(x, y) {
ifelse(x %in% 0:2 & y %in% c(5, 10), (x*y + 3*y)/180, 0)
}

# Compute P(X >= 1)


p_x_ge_1 <- sum(f(1:2, 5:10))

# Print the result


cat("P(X >= 1) = ", p_x_ge_1)
output: P(X >= 1) = 0.3888889
c) # Define the joint probability mass function
f <- function(x, y) {
ifelse(x %in% 0:2 & y %in% c(5, 10), (x*y + 3*y)/180, 0)
}

# Compute the numerator P(X > 0 and Y = 5)


p_xy <- f(1:2, 5)
p_x_gt_0_given_y_5_num <- sum(p_xy)

# Compute the denominator P(Y = 5)


p_y_5 <- sum(f(0:2, 5))

# Compute P(X > 0 | Y = 5)


p_x_gt_0_given_y_5 <- p_x_gt_0_given_y_5_num / p_y_5

# Print the result


cat("P(X > 0 | Y = 5) = ", p_x_gt_0_given_y_5)
output:
P(X > 0 | Y = 5) = 0.75

>

Q7.

You might also like