Question 1

Part 1.1

# Load necessary library
library(ggplot2)

# a) Probability of obtaining X = 10
# Using the dpois function
prob_x_10 <- dpois(10, lambda = 7)
print(paste("Probability of X = 10: ", prob_x_10))
## [1] "Probability of X = 10:  0.0709832686504137"
# b) Probability of obtaining a value more than 7 but less than 10
# We calculate P(X <= 9) - P(X <= 7)
prob_more_than_7_less_than_10 <- ppois(9, lambda = 7) - ppois(7, lambda = 7)
print(paste("Probability of 7 < X < 10: ", prob_more_than_7_less_than_10))
## [1] "Probability of 7 < X < 10:  0.231782101715637"
# c) Draw the graph of the probability mass function f(x)
# Calculating probabilities for X values from 0 to 50
x_values <- 0:50
probabilities <- dpois(x_values, lambda = 7)

# Creating the plot
plot_data <- data.frame(X = x_values, Probability = probabilities)
ggplot(plot_data, aes(x = X, y = Probability)) +
  geom_point() + 
  geom_line() + 
  ggtitle("Probability Mass Function of Poisson Distribution (lambda = 7)") +
  xlab("X") +
  ylab("Probability")

Part 1.2

# Load necessary library
library(ggplot2)

# a) Generate 100 equidistant values of p between 0 and 1
p_values <- seq(0, 1, length.out = 100)

# b) Calculate the probability of observing x = 84 for each value of p
n <- 100
x <- 84
probabilities <- dbinom(x, size = n, prob = p_values)

# Plot the probabilities against p values
plot_data <- data.frame(P_Value = p_values, Probability = probabilities)
ggplot(plot_data, aes(x = P_Value, y = Probability)) +
  geom_line() +
  ggtitle("Probability of Observing X = 84 for Different p Values") +
  xlab("p Value") +
  ylab("Probability")

# c) Identify the most likely value of p
max_prob_index <- which.max(probabilities)
most_likely_p <- p_values[max_prob_index]
print(paste("The most likely value of p: ", most_likely_p))
## [1] "The most likely value of p:  0.838383838383838"

Question 2

Part 2.1

# a) Probability density of obtaining x = 0, µ = 1, σ = 1
mu_a <- 1
sigma_a <- 1
x_a <- 0
density_a <- dnorm(x_a, mean = mu_a, sd = sigma_a)
print(paste("Probability density at x = 0 (µ = 1, σ = 1):", density_a))
## [1] "Probability density at x = 0 (µ = 1, σ = 1): 0.241970724519143"
# b) Probability density of obtaining x = 1, µ = 0, σ = 1
mu_b <- 0
sigma_b <- 1
x_b <- 1
density_b <- dnorm(x_b, mean = mu_b, sd = sigma_b)
print(paste("Probability density at x = 1 (µ = 0, σ = 1):", density_b))
## [1] "Probability density at x = 1 (µ = 0, σ = 1): 0.241970724519143"
# c) Probability that the outcome occurs between x2 and x3
# Given: P(x1 ≤ X ≤ x2) = 0.3, P(x1 ≤ X ≤ x3) = 0.45
# Need to find: P(x2 ≤ X ≤ x3) = P(x1 ≤ X ≤ x3) - P(x1 ≤ X ≤ x2)
prob_x1_x2 <- 0.3
prob_x1_x3 <- 0.45
prob_x2_x3 <- prob_x1_x3 - prob_x1_x2
print(paste("Probability that the outcome occurs between x2 and x3:", prob_x2_x3))
## [1] "Probability that the outcome occurs between x2 and x3: 0.15"

Part 2.2

# Normal distribution parameters
mean <- 650
sd <- 125

# Value for which we want to find the probability density
x <- 550

# Calculate the probability density
density <- dnorm(x, mean = mean, sd = sd)

# Output the result
print(paste("Probability density at x = 550:", density))
## [1] "Probability density at x = 550: 0.00231753242209186"

Part 2.3

# Normal distribution parameters
mean <- 500
sd <- 100

# a) Probability of obtaining a value of 700 or less
prob_less_than_700 <- pnorm(700, mean = mean, sd = sd)
print(paste("Probability of obtaining a value of 700 or less:", prob_less_than_700))
## [1] "Probability of obtaining a value of 700 or less: 0.977249868051821"
# b) Probability of obtaining a value of 900 or more
# This is 1 - Probability of obtaining a value of 900 or less
prob_more_than_900 <- 1 - pnorm(900, mean = mean, sd = sd)
print(paste("Probability of obtaining a value of 900 or more:", prob_more_than_900))
## [1] "Probability of obtaining a value of 900 or more: 3.167124183312e-05"
# c) Probability of obtaining values between 200 and 800
# This is Probability of obtaining a value of 800 or less minus
# Probability of obtaining a value of 200 or less
prob_between_200_and_800 <- pnorm(800, mean = mean, sd = sd) - pnorm(200, mean = mean, sd = sd)
print(paste("Probability of obtaining values between 200 and 800:", prob_between_200_and_800))
## [1] "Probability of obtaining values between 200 and 800: 0.99730020393674"

Part 2.4

# Set the number of values to draw
n <- 10000

# Draw n values from the normal distribution
xsim <- rnorm(n, mean = 300, sd = 200)

# Calculate the mean
mean_xsim <- mean(xsim)
print(paste("Mean of xsim:", mean_xsim))
## [1] "Mean of xsim: 301.598989900143"
# Calculate the standard deviation
sd_xsim <- sd(xsim)
print(paste("Standard deviation of xsim:", sd_xsim))
## [1] "Standard deviation of xsim: 200.38353636666"
# Find the minimum value
min_xsim <- min(xsim)
print(paste("Minimum of xsim:", min_xsim))
## [1] "Minimum of xsim: -462.494568329051"
# Find the maximum value
max_xsim <- max(xsim)
print(paste("Maximum of xsim:", max_xsim))
## [1] "Maximum of xsim: 1103.54190537731"

Question 3

Part 3.1 (a)

# Load necessary library
library(ggplot2)

# Define the PDF
f <- function(x, mu) {
  1 / (x * sqrt(2 * pi)) * exp(-((log(x) - mu)^2) / 2)
}

# Fixed x value
x_fixed <- 220

# Range of µ values
mu_values <- seq(0, 500, by = 5)
densities <- numeric(length(mu_values))

# Calculate the probability densities
for (i in 1:length(mu_values)) {
  densities[i] <- f(x_fixed, mu_values[i])
}

# Plot the likelihood function for x = 220
plot_data <- data.frame(Mu = mu_values, Density = densities)
ggplot(plot_data, aes(x = Mu, y = Density)) +
  geom_line() +
  ggtitle("Likelihood Function for x = 220") +
  xlab("µ") +
  ylab("Likelihood")

Part 3.1 (b)

# Observed sample of recognition times
x_observed <- c(303, 443, 220, 560, 880)
likelihoods <- numeric(length(mu_values))

# Likelihood function for the observed sample
for (j in 1:length(mu_values)) {
  likelihood_product <- 1
  for (x_val in x_observed) {
    likelihood_product <- likelihood_product * f(x_val, mu_values[j])
  }
  likelihoods[j] <- likelihood_product
}

# Plot the likelihood function for the observed sample
plot_data <- data.frame(Mu = mu_values, Likelihood = likelihoods)
ggplot(plot_data, aes(x = Mu, y = Likelihood)) +
  geom_line() +
  ggtitle("Likelihood Function for Observed Sample") +
  xlab("µ") +
  ylab("Likelihood")

Part 3.1 (c)

# Identify the µ value that maximizes the likelihood
max_likelihood_mu <- mu_values[which.max(likelihoods)]
print(paste("µ value with maximum likelihood: ", max_likelihood_mu))
## [1] "µ value with maximum likelihood:  5"

Question 4

Part 4.1

To determine which language has the highest number of word pairs with a linear distance of 0, we need to look at the PMF for each language and evaluate it for k = 0. Since the PMF is a Poisson distribution, at k = 0, the PMF simplifies to -> f(0, lambda) = e(-lambda)

The value of this function decreases as lambda increases. So, the language with the smallest lambda will have the highest probability for a word pair with linear distance 0.

We’re given that lambda 3 < lambda 1 < lambda 2; it follows that: e(-lambda 3) > e(-lambda 1) > e(-lambda 2).

Therefore, the Czech language (having lambda 3) will have the highest number of word pairs with a linear distance of 0, given all three languages have an equal number of word pairs.

Part 4.2

# Calculate the number of word-pairs with linear distance 1 for each language

# λ values for each language
lambda_english <- 0.7
lambda_german <- 0.8
lambda_czech <- 0.6

# Total number of word-pairs in each corpus
total_pairs_english <- 10^5
total_pairs_german <- 10^7
total_pairs_czech <- 10^8

# Calculate the number of word-pairs with distance 1 in each language using dpois
word_pairs_distance_1_english <- dpois(1, lambda_english) * total_pairs_english
word_pairs_distance_1_german <- dpois(1, lambda_german) * total_pairs_german
word_pairs_distance_1_czech <- dpois(1, lambda_czech) * total_pairs_czech

# Output the results
print(paste("Number of English word-pairs with distance 1:", word_pairs_distance_1_english))
## [1] "Number of English word-pairs with distance 1: 34760.9712653987"
print(paste("Number of German word-pairs with distance 1:", word_pairs_distance_1_german))
## [1] "Number of German word-pairs with distance 1: 3594631.71293777"
print(paste("Number of Czech word-pairs with distance 1:", word_pairs_distance_1_czech))
## [1] "Number of Czech word-pairs with distance 1: 32928698.1656416"

Part 4.3

The rate parameter for our artificial language is 2, which is higher than those for natural languages (which is generally < 1). With lower values of lambda, it goes to show that there is a higher probability for smaller distances, or, words are more closely related. With lambda = 2, on the other hand, the distribution is different, likely with a higher probability for larger distances. Further, a higher lambda in the artificial language suggests a distribution that is less skewed towards smaller distances, potentially indicating a more uniform or even spread across different distances, indicating a less natural linguistic structure.