This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
#assignment -3
# Generate 40 random values with lambda = 20
random_values <- rpois(40, 20)
# Compute the mean (lambda) of the random values
lambda <- mean(random_values)
# Print lambda
print(paste("Lambda: ", lambda))
## [1] "Lambda: 19.875"
# Calculate the probability of exactly 8 calls in a 5-minute period
prob_exactly_8 <- dpois(8, lambda)
# Print the probability of exactly 8 calls
print(paste("Probability of exactly 8 calls: ", prob_exactly_8))
## [1] "Probability of exactly 8 calls: 0.00141037222732335"
# Calculate the probability of at least 8 calls in a 5-minute period
prob_at_least_8 <- 1 - ppois(7, lambda)
# Print the probability of at least 8 calls
print(paste("Probability of at least 8 calls: ", prob_at_least_8))
## [1] "Probability of at least 8 calls: 0.999153247934627"
# Generate 40 random values with lambda = 20
random_values <- rpois(40, 20)
# Compute the mean (lambda) of the random values
lambda <- mean(random_values)
# Print lambda
print(paste("Lambda: ", lambda))
## [1] "Lambda: 20.175"
# Calculate the probability of exactly 8 calls in a 5-minute period
prob_exactly_8 <- dpois(8, lambda)
# Print the probability of exactly 8 calls
print(paste("Probability of exactly 8 calls: ", prob_exactly_8))
## [1] "Probability of exactly 8 calls: 0.00117786807640067"
# Calculate the probability of at least 8 calls in a 5-minute period
prob_at_least_8 <- 1 - ppois(7, lambda)
# Print the probability of at least 8 calls
print(paste("Probability of at least 8 calls: ", prob_at_least_8))
## [1] "Probability of at least 8 calls: 0.999307991183293"
# Create a histogram for the number of calls
hist(random_values, breaks = seq(min(random_values)-0.5, max(random_values)+0.5),
main = "Call Frequency Histogram",
xlab = "Number of Calls", ylab = "Frequency", col = "blue")
#2nd
# Define the parameters of the normal distribution
mean <- 1
sd <- 2
# Define the values of x
x_values <- c(-1, -2, 0, 1, 2)
# Compute PDF values for each x
pdf_values <- dnorm(x_values, mean, sd)
# Compute CDF values for each x
cdf_values <- pnorm(x_values, mean, sd)
# Create a data frame to display the results
results_df <- data.frame(x = x_values, PDF = pdf_values, CDF = cdf_values)
# Print the data frame
print(results_df)
## x PDF CDF
## 1 -1 0.1209854 0.1586553
## 2 -2 0.0647588 0.0668072
## 3 0 0.1760327 0.3085375
## 4 1 0.1994711 0.5000000
## 5 2 0.1760327 0.6914625
# 3 question
# Generate 100 random values with mean=2 and variance=9
random_values_1 <- rnorm(100, 2, 3^2) # Variance = (standard deviation)^2
# Compute mean and variance of the first dataset
mean_1 <- mean(random_values_1)
variance_1 <- var(random_values_1)
# Generate 150 random values with mean=-2 and variance=0.15
random_values_2 <- rnorm(150, -2, sqrt(0.15)) # Variance = (standard deviation)^2
# Compute mean and variance of the second dataset
mean_2 <- mean(random_values_2)
variance_2 <- var(random_values_2)
# Generate sequence of numbers from -5 to 5 with an increment of 0.05
x <- seq(-5, 5, by = 0.05)
# Calculate PDF values for each distribution
pdf_1 <- dnorm(x, mean_1, sqrt(variance_1))
pdf_2 <- dnorm(x, 0, sqrt(4)) # N(0,4)
pdf_3 <- dnorm(x, mean_2, sqrt(variance_2))
# Plot the PDFs
plot(x, pdf_1, type = "l", col = "blue", ylim = c(0, 0.2),
main = "Probability Density Function (PDF)",
xlab = "x", ylab = "Density")
lines(x, pdf_2, col = "red")
lines(x, pdf_3, col = "green")
legend("topright", legend = c(paste("N(", mean_1, ",", variance_1, ")"), "N(0,4)", paste("N(", mean_2, ",", variance_2, ")")),
col = c("blue", "red", "green"), lty = 1)
# Proper observation from the plots:
# The plot shows the probability density functions of three normal distributions.
# The blue curve represents a normal distribution with mean and variance calculated from the first dataset.
# The red curve represents the standard normal distribution N(0, 4) with mean 0 and variance 4.
# The green curve represents a normal distribution with mean and variance calculated from the second dataset.