Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Prob q4 Merged Output

The document contains various statistical problems and their solutions, including correlation calculations, regression analysis, and binomial probability computations. It covers topics such as fitting linear models, calculating probabilities for defective items, and analyzing distributions. The document also includes code snippets in R for executing these statistical analyses.

Uploaded by

Manipriyaa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Prob q4 Merged Output

The document contains various statistical problems and their solutions, including correlation calculations, regression analysis, and binomial probability computations. It covers topics such as fitting linear models, calculating probabilities for defective items, and analyzing distributions. The document also includes code snippets in R for executing these statistical analyses.

Uploaded by

Manipriyaa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

TASK-2 name: Manipriyaa R

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

data <- data.frame(ENJOY, BUY, READ)


correlation_matrix <- cor(data)
print("Correlation Matrix:")

## [1] "Correlation Matrix:"

print(correlation_matrix)

## ENJOY BUY READ


## ENJOY 1.0000000 0.6226953 0.6595060
## BUY 0.6226953 1.0000000 0.5751954
## READ 0.6595060 0.5751954 1.0000000

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

Load the dataset


data <- read.csv(“C:\Users\manip\Downloads\life_satisfaction_1.csv”, header=TRUE)

View the first few rows


head(data)

Select numerical columns (modify based on your dataset)


data_clean <- data[, c(“X2013”, “X2018”, “X2022”)]

Convert columns to numeric (if needed)


data_clean <- data.frame(lapply(data_clean, as.numeric))

Remove missing values


data_clean <- na.omit(data_clean)

Fit the regression model


model <- lm(X2013 ~ X2018 + X2022, data = data_clean)

Show model summary


summary(model)

1
Problem-5
# Given values
n <- 20 # Total trials
p <- 0.10 # Probability of success (defective screw)

# (i) Probability of exactly 2 defectives


p_exactly_2 <- dbinom(2, size = n, prob = p)
print(paste("P(X = 2) =", p_exactly_2))

## [1] "P(X = 2) = 0.285179807064298"

# (ii) Probability of at least 2 defectives


n <- 20 # Total trials
p <- 0.10
p_at_least_2 <- 1 - pbinom(1, size = n, prob = p)
print(paste("P(X � 2) =", p_at_least_2))

## [1] "P(X � 2) = 0.608253001874832"

n <- 20 # Total trials


p <- 0.10
# (iii) Probability of between 1 and 3 defectives (inclusive)
p_between_1_and_3 <- sum(dbinom(1:3, size = n, prob = p))
print(paste("P(1 � X � 3) =", p_between_1_and_3))

## [1] "P(1 � X � 3) = 0.745470021975096"

1
Problem
Problem 6
1: X ~ Bin(20, 0.5)
n1 <- 20 p1 <- 0.5

# (i) P(X < 4) = P(X = 0) + P(X = 1) + P(X = 2) + P(X = 3)


n1 <- 20
p1 <- 0.5

p1_less_than_4 <- pbinom(3, size = n1, prob = p1)


print(paste("P(X < 4) =", p1_less_than_4))

## [1] "P(X < 4) = 0.00128841400146485"

# (ii) P(X > 11) = 1 - P(X � 11)


n1 <- 20
p1 <- 0.5

p1_greater_than_11 <- 1 - pbinom(11, size = n1, prob = p1)


print(paste("P(X > 11) =", p1_greater_than_11))

## [1] "P(X > 11) = 0.25172233581543"

# (iii) P(1 � X � 8) = P(X � 8) - P(X � 0)


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] "P(1 � X � 8) = 0.251721382141113"

1
Problem-7
n <- 10 p <- 0.5

# (i) P(X � 5) = 1 - P(X � 4)


n <- 10
p <- 0.5
p_at_least_5 <- 1 - pbinom(4, size = n, prob = p)
print(paste("P(X � 5) =", p_at_least_5))

## [1] "P(X � 5) = 0.623046875"

# (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] "P(X = 5) = 0.24609375"

# (iii) P(4 � X � 6) = P(X � 6) - P(X � 3)


n <- 10
p <- 0.5
p_between_4_and_6 <- pbinom(6, size = n, prob = p) - pbinom(3, size = n, prob = p)
print(paste("P(4 � X � 6) =", p_between_4_and_6))

## [1] "P(4 � X � 6) = 0.65625"

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")

## X follows a Binomial distribution: X ~ Bin(30, 0.558)

# 2. Sketch the Probability Mass Function (PMF)


n <- 30
p <- 0.558
x_vals <- 0:n
pmf_vals <- dbinom(x_vals, size = n, prob = p)
plot(x_vals, pmf_vals, type = "h", col = "blue", lwd = 2,
main = "Probability Mass Function", xlab = "X", ylab = "P(X)")

Probability Mass Function


0.15
0.10
P(X)

0.05
0.00

0 5 10 15 20 25 30

# 3. Sketch the Cumulative Distribution Function (CDF)


n <- 30
p <- 0.558
cdf_vals <- pbinom(x_vals, size = n, prob = p)
plot(x_vals, cdf_vals, type = "s", col = "red", lwd = 2,
main = "Cumulative Distribution Function", xlab = "X", ylab = "P(X � x)")

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")

## P(X = 17) = 0.1450715

# 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")

## P(X � 13) = 0.1171176

# 6. P(X > 11) = 1 - P(X � 11)


n <- 30
p <- 0.558
p_greater_11 <- 1 - pbinom(11, size = n, prob = p)
cat("P(X > 11) =", p_greater_11, "\n")

## P(X > 11) = 0.9726686

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")

## P(X � 15) = 0.7953302

# 8. P(16 � X � 19) = P(X � 19) - P(X � 15)


n <- 30
p <- 0.558
p_between_16_19 <- pbinom(19, size = n, prob = p) - pbinom(15, size = n, prob = p)
cat("P(16 � X � 19) =", p_between_16_19, "\n")

## P(16 � X � 19) = 0.5223442

# 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

# 11. Standard deviation of X


n <- 30
p <- 0.558
sd_X <- sqrt(var_X)
cat("SD(X) =", sd_X, "\n")

## SD(X) = 2.720125

# 12. E(4X + 51.324) = 4E[X] + 51.324


n <- 30
p <- 0.558
E_4X_plus_51 <- 4 * mean_X + 51.324
cat("E(4X + 51.324) =", E_4X_plus_51, "\n")

## E(4X + 51.324) = 118.284

You might also like