Prob q4 Merged Output
Prob q4 Merged Output
regno: 23BAI0214
problem-1
#Question-1
# Define the data
x <- c(3.545, 2.6, 3.245, 3.93, 3.995, 3.115, 3.235, 3.225, 2.44, 3.24, 2.29, 2.5, 4.02)
y <- c(30, 32, 30, 24, 26, 30, 33, 27, 37, 32, 37, 34, 26)
correlation <- cor(x, y)
cat("The correlation coefficient between weight (x) and fuel efficiency (y) is:", correlation, "\n")
## The correlation coefficient between weight (x) and fuel efficiency (y) is: -0.8977642
1
Problem-2
ENJOY <- c(4, 15, 1, 11, 13, 19, 6, 10, 15, 3, 11, 20, 7, 6, 7, 18, 8, 2, 7, 12, 13, 15, 4, 3, 9, 7, 10,
BUY <- c(16, 19, 0, 19, 25, 24, 23, 21, 13, 7, 28, 31, 4, 12, 14, 16, 20, 13, 12, 13, 22, 19, 12, 10,
READ <- c(6, 13, 1, 13, 12, 11, 7, 8, 12, 4, 15, 14, 7, 5, 7, 12, 10, 6, 9, 23, 9, 13, 9, 5, 7, 8, 8, 2
print(correlation_matrix)
1
Problem-3
# Define the data
Area <- c(1, 2, 3, 4, 5, 6, 7, 8)
Y <- c(110, 80, 70, 102, 105, 90, 70, 120)
X1 <- c(30, 40, 20, 50, 60, 40, 20, 60)
X2 <- c(11, 10, 7, 15, 19, 12, 8, 14)
data <- data.frame(Area, Y, X1, X2)
model <- lm(Y ~ X1 + X2, data=data)
summary(model)
##
## Call:
## lm(formula = Y ~ X1 + X2, data = data)
##
## Residuals:
## 1 2 3 4 5 6 7 8
## 24.282 -11.177 -4.765 -1.230 -9.183 -3.375 -5.863 11.311
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 53.9564 17.4097 3.099 0.0269 *
## X1 0.6558 0.7911 0.829 0.4449
## X2 1.0988 3.2298 0.340 0.7475
## ---
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
## Residual standard error: 14.12 on 5 degrees of freedom
## Multiple R-squared: 0.5977, Adjusted R-squared: 0.4368
## F-statistic: 3.715 on 2 and 5 DF, p-value: 0.1026
1
Problem-4
1
Problem-5
# Given values
n <- 20 # Total trials
p <- 0.10 # Probability of success (defective screw)
1
Problem
Problem 6
1: X ~ Bin(20, 0.5)
n1 <- 20 p1 <- 0.5
p1_between_1_and_8 <- pbinom(8, size = n1, prob = p1) - pbinom(0, size = n1, prob = p1)
print(paste("P(1 � X � 8) =", p1_between_1_and_8))
1
Problem-7
n <- 10 p <- 0.5
# (ii) P(X = 5)
n <- 10
p <- 0.5
p_exactly_5 <- dbinom(5, size = n, prob = p)
print(paste("P(X = 5) =", p_exactly_5))
1
Problem 8
n <- 30 p <- 0.558
# 1. How is X distributed?
n <- 30
p <- 0.558
cat("X follows a Binomial distribution: X ~ Bin(30, 0.558)\n")
0.05
0.00
0 5 10 15 20 25 30
1
Cumulative Distribution Function
1.0
0.8
0.6
P(X = x)
0.4
0.2
0.0
0 5 10 15 20 25 30
# 4. P(X = 17)
n <- 30
p <- 0.558
p_17 <- dbinom(17, size = n, prob = p)
cat("P(X = 17) =", p_17, "\n")
# 5. P(X � 13)
n <- 30
p <- 0.558
p_at_most_13 <- pbinom(13, size = n, prob = p)
cat("P(X � 13) =", p_at_most_13, "\n")
2
# 7. P(X � 15) = 1 - P(X � 14)
n <- 30
p <- 0.558
p_at_least_15 <- 1 - pbinom(14, size = n, prob = p)
cat("P(X � 15) =", p_at_least_15, "\n")
# 9. Mean of X (E[X])
n <- 30
p <- 0.558
mean_X <- n * p
cat("E[X] =", mean_X, "\n")
## E[X] = 16.74
# 10. Variance of X
n <- 30
p <- 0.558
var_X <- n * p * (1 - p)
cat("Var(X) =", var_X, "\n")
## Var(X) = 7.39908
## SD(X) = 2.720125