To find the likelihood function β(π; π¦_1, β― , π¦_π), we need to multiply the probability functions of each observation in the sample. Given the exponential probability function, π«(π¦; π) = (1/π)*exp(-π¦/π), we can write the likelihood function as:
β(π; π¦_1, β― , π¦_π) = π«(π¦_1; π) * π«(π¦_2; π) * β¦ * π«(π¦_π; π)
Now, substitute the exponential probability function into the likelihood function:
β(π; π¦_1, β― , π¦_π) = (1/π) * exp(-π¦_1/π) * (1/π) * exp(-π¦_2/π) * β¦ * (1/π) * exp(-π¦_π/π)
Simplify the expression:
β(π; π¦_1, β― , π¦_π) = (1/π^n) * exp(-(π¦_1 + π¦_2 + β¦ + π¦_π)/π)
Let π = π¦_1 + π¦_2 + β¦ + π¦_π be the sum of all the observations in the sample, and let π¦Μ = π/π be the sample mean. Then, the likelihood function becomes:
β(π; π¦_1, β― , π¦_π) = (1/π^n) * exp(-π*π¦Μ /π)
Now, letβs find the log-likelihood function β(π; π¦_1, β― , π¦_π) by taking the natural logarithm of the likelihood function:
β(π; π¦_1, β― , π¦_π) = ln(β(π; π¦_1, β― , π¦_π)) = ln((1/π^n) * exp(-π*π¦Μ /π))
Use the properties of logarithms to simplify the expression:
β(π; π¦_1, β― , π¦_π) = ln(1/π^n) + ln(exp(-ππ¦Μ /π)) = -π ln(π) - (π*π¦Μ /π)
So, the log-likelihood function is:
β(π; π¦_1, β― , π¦_π) = -π * ln(π) - (π*π¦Μ /π)
The score function π(π) is the first derivative of the log-likelihood function β(π; π¦_1, β― , π¦_π) with respect to the unknown parameter π. Given the log-likelihood function we derived earlier:
β(π; π¦_1, β― , π¦_π) = -π * ln(π) - (π*π¦Μ /π)
Letβs differentiate this with respect to π:
π(π) = dβ(π)/dπ
First, differentiate the term -π * ln(π):
d(-π * ln(π))/dπ = -π * (1/π)
Next, differentiate the term -(π*π¦Μ /π):
d(-(ππ¦Μ /π))/dπ = ππ¦Μ /π^2
Now, add these two terms together to find the score function:
π(π) = -π * (1/π) + π*π¦Μ /π^2
So, the score function is:
π(π) = -π * (1/π) + π*π¦Μ /π^2
To find the maximum likelihood estimate (MLE) of π, denoted as πΜ, we need to set the score function π(π) to zero and solve for π. From the score function we derived earlier:
π(π) = -π * (1/π) + π*π¦Μ /π^2
Set π(π) to zero:
0 = -π * (1/π) + π*π¦Μ /π^2
Now, weβll solve for π:
π * (1/π) = π*π¦Μ /π^2
Cancel out the π term:
1/π = π¦Μ /π^2
Now, cross-multiply to eliminate the fractions:
π^2 = π¦Μ *π
Since π > 0 (as given in the problem context), we can safely divide both sides by π:
π = π¦Μ
So, the maximum likelihood estimate (MLE) for π, denoted as πΜ, is equal to the sample mean:
πΜ = π¦Μ
The observed information for π, denoted as πΌ(π), is the negative of the second derivative of the log-likelihood function β(π; π¦_1, β― , π¦_π) with respect to the unknown parameter π. Given the log-likelihood function we derived earlier:
β(π; π¦_1, β― , π¦_π) = -π * ln(π) - (π*π¦Μ /π)
Letβs differentiate it twice with respect to π:
First, we already found the first derivative (the score function π(π)):
π(π) = -π * (1/π) + π*π¦Μ /π^2
Now, differentiate π(π) with respect to π:
dπ(π)/dπ = π/π^2 - 2π*π¦Μ /π^3
The observed information πΌ(π) is the negative of the second derivative of the log-likelihood function:
πΌ(π) = -dΒ²β(π)/dπΒ² = -dπ(π)/dπ
Now, plug in the second derivative:
πΌ(π) = - (π/π^2 - 2π*π¦Μ /π^3)
Simplify the expression:
πΌ(π) = -π/π^2 + 2π*π¦Μ /π^3
So, the observed information for π is:
πΌ(π) = -π/π^2 + 2π*π¦Μ /π^3
The expected information for π, also known as the Fisher information, is the expected value of the observed information πΌ(π) with respect to the distribution of the data. In this case, weβre working with the exponential distribution.
Since the observed information πΌ(π) is:
πΌ(π) = -π/π^2 + 2π*π¦Μ /π^3
Letβs compute the expected information for π, denoted as πΌ_E(π):
πΌ_E(π) = E[πΌ(π)]
Now, recall that for the exponential distribution, the mean and variance are both equal to π:
E[π¦] = π Var(π¦) = π^2
So, the expected value of π¦Μ (sample mean) is π:
E[π¦Μ ] = π
Now, substitute the expected value of π¦Μ into the observed information πΌ(π):
πΌ_E(π) = -π/π^2 + 2π*E[π¦Μ ]/π^3
Plug in E[π¦Μ ] = π:
πΌ_E(π) = -π/π^2 + 2π*π/π^3
Simplify the expression:
πΌ_E(π) = -π/π^2 + 2π/π^2
Now, combine the terms:
πΌ_E(π) = π/π^2
So, the expected information for π is:
πΌ_E(π) = π/π^2
To find the estimated standard error for πΜ, denoted as π π(πΜ), we need to find the square root of the inverse of the expected information for π. We have previously found the expected information for π:
πΌ_E(π) = π/π^2
Now, letβs find the inverse of πΌ_E(π):
πΌ_E(π)^(-1) = π^2/π
The estimated variance of πΜ is given by the inverse of the expected information for π:
Var(πΜ) = π^2/π
Now, weβll take the square root of the variance to find the estimated standard error:
π π(πΜ) = β(Var(πΜ)) = β(π^2/π)
Recall that we have found the maximum likelihood estimate (MLE) for π:
πΜ = π¦Μ
Substitute πΜ for π in the standard error formula:
π π(πΜ) = β(πΜ^2/π)
So, the estimated standard error for πΜ is:
π π(πΜ) = πΜ/βπ
The Wald test statistic is used to test a hypothesis about a parameter in a statistical model. In this case, we are testing the null hypothesis π»_0: π = 1.
The Wald test statistic is given by the following formula:
π = (πΜ - π_0) / π π(πΜ)
where πΜ is the maximum likelihood estimate (MLE) of the parameter (in this case, πΜ), π_0 is the hypothesized value of the parameter under the null hypothesis (in this case, 1), and π π(πΜ) is the estimated standard error of the MLE.
We have already found the MLE for π:
πΜ = π¦Μ
And the estimated standard error for πΜ:
π π(πΜ) = πΜ/βπ
Now, weβll substitute these values into the Wald test statistic formula:
π = (πΜ - 1) / (πΜ/βπ)
Now, multiply both numerator and denominator by βπ to eliminate the fraction in the denominator:
π = (βπ * (πΜ - 1)) / πΜ
Now, simplify the expression:
π = (βπ * πΜ - βπ) / πΜ
So, the Wald test statistic for testing π»_0: π = 1 is:
π = (πΜ - 1) / (βπΜ^2/π)
The likelihood ratio test statistic is used to test a hypothesis about a parameter in a statistical model. In this case, we are testing the null hypothesis π»_0: π = 1.
The likelihood ratio test statistic is given by the following formula:
πΏ = 2 * (β(πΜ) - β(π_0))
where πΜ is the maximum likelihood estimate (MLE) of the parameter (in this case, πΜ), π_0 is the hypothesized value of the parameter under the null hypothesis (in this case, 1), and β(π) is the log-likelihood function for the parameter π.
We have already found the MLE for π:
πΜ = π¦Μ
And the log-likelihood function:
β(π; π¦_1, β― , π¦_π) = -π * ln(π) - (π * π¦Μ /π)
Now, letβs evaluate the log-likelihood function at πΜ:
β(πΜ) = -π * ln(πΜ) - (π * π¦Μ /πΜ)
Since πΜ = π¦Μ :
β(πΜ) = -π * ln(π¦Μ ) - π
Next, evaluate the log-likelihood function at π_0 = 1:
β(1) = -π * ln(1) - (π * π¦Μ /1)
Since ln(1) = 0:
β(1) = -π * π¦Μ
Now, letβs substitute these values into the likelihood ratio test statistic formula:
πΏ = 2 * (β(πΜ) - β(1)) = 2 * (-π * ln(π¦Μ ) - π - (-π * π¦Μ ))
Simplify the expression:
πΏ = 2 * (π * π¦Μ - π * ln(π¦Μ ) - π)
Factor out π:
πΏ = 2π(π¦Μ - ln(π¦Μ ) - 1)
Since πΜ = π¦Μ :
πΏ = 2π(πΜ - log(πΜ) - 1)
So, the likelihood ratio test statistic for testing π»_0: π = 1 is:
πΏ = 2π(πΜ - log(πΜ) - 1)
# Load required libraries
library(ggplot2)
# Define the sample size
n <- 10
# Generate a sequence of mu_hat values
mu_hat <- seq(0.5, 2.0, by = 0.1)
# Calculate W^2 and LRT
W_sq <- ((mu_hat - 1) / (sqrt(mu_hat^2 / n)))^2
LRT <- 2 * n * (mu_hat - log(mu_hat) - 1)
# Combine the data into a data frame
data <- data.frame(mu_hat = mu_hat, W_sq = W_sq, LRT = LRT)
# Create a ggplot object
p <- ggplot(data) +
geom_line(aes(x = mu_hat, y = W_sq, color = "W^2")) +
geom_line(aes(x = mu_hat, y = LRT, color = "LRT")) +
labs(x = expression(hat(mu)), y = "Test Statistic Value", title = "W^2 and LRT vs. Mu_hat") +
scale_color_manual(values = c("W^2" = "red", "LRT" = "blue"), name = "Test Statistic") +
theme_minimal()
# Print the plot
print(p)
The resulting plot shows the relationship between π^2 and LRT as πΜ varies. Both test statistics increase as the difference between the null hypothesis value (π = 1) and πΜ increases, indicating a stronger evidence against the null hypothesis.
# Define the sample size
n <- 100
# Generate a sequence of mu_hat values
mu_hat <- seq(0.5, 2.0, by = 0.1)
# Calculate W^2 and LRT
W_sq <- ((mu_hat - 1) / (sqrt(mu_hat^2 / n)))^2
LRT <- 2 * n * (mu_hat - log(mu_hat) - 1)
# Combine the data into a data frame
data <- data.frame(mu_hat = mu_hat, W_sq = W_sq, LRT = LRT)
# Create a ggplot object
p <- ggplot(data) +
geom_line(aes(x = mu_hat, y = W_sq, color = "W^2")) +
geom_line(aes(x = mu_hat, y = LRT, color = "LRT")) +
labs(x = expression(hat(mu)), y = "Test Statistic Value", title = "W^2 and LRT vs. Mu_hat") +
scale_color_manual(values = c("W^2" = "red", "LRT" = "blue"), name = "Test Statistic") +
theme_minimal()
# Print the plot
print(p)
The resulting plot shows the relationship between π^2 and LRT as πΜ varies for π = 100. As with the previous plot, both test statistics increase as the difference between the null hypothesis value (π = 1) and πΜ increases, indicating stronger evidence against the null hypothesis. However, for π = 100, the test statistics increase more sharply compared to π = 10, as a larger sample size provides more evidence against the null hypothesis when the true value of π is different from the hypothesized value.
To calculate the variance-covariance matrix of π½Μ0, π½Μ1, and π½Μ2, we need to find the inverse of the information matrix πΌ(π·Μ).
# Define the information matrix
information_matrix <- matrix(c(4823, 12334, 20871,
12334, 31798, 53423,
20871, 53423, 90348), nrow = 3, ncol = 3, byrow = TRUE)
# Calculate the variance-covariance matrix
var_cov_matrix <- solve(information_matrix)
# Print the variance-covariance matrix
print(var_cov_matrix)
## [,1] [,2] [,3]
## [1,] 0.70524128 0.023890843 -0.177042229
## [2,] 0.02389084 0.005597557 -0.008828796
## [3,] -0.17704223 -0.008828796 0.046129512
The formula used to calculate the variance-covariance matrix is:
Var-Cov(π·Μ) = πΌ(π·Μ)^(-1)
where πΌ(π·Μ) is the information matrix and πΌ(π·Μ)^(-1) is its inverse.
To find the estimated standard error of π½Μ1, we need to take the square root of the corresponding diagonal element in the variance-covariance matrix.
# Calculate the standard error of beta_hat_1
se_beta_hat_1 <- sqrt(var_cov_matrix[2, 2])
# Print the standard error
print(se_beta_hat_1)
## [1] 0.07481683
To find the 95% confidence interval of π½Μ1, we will use the estimated standard error we calculated previously, as well as the t-distribution critical value for a 95% confidence level.
The formula for the confidence interval is:
CI(π½Μ1) = π½Μ1 Β± t_Ξ±/2 * SE(π½Μ1)
The degrees of freedom for the t-distribution in a GLM are usually calculated as n - p, where n is the number of observations and p is the number of parameters. However, we donβt have the number of observations in this case, so we will use the normal distribution critical value (z-score) as an approximation, which is 1.96 for a 95% confidence interval.
# Define the MLE of beta_1
beta_hat_1 <- 2.0
# Define the critical value (z-score) for a 95% confidence interval
z_critical <- 1.96
# Calculate the confidence interval for beta_hat_1
lower_bound_1 <- beta_hat_1 - z_critical * se_beta_hat_1
upper_bound_1 <- beta_hat_1 + z_critical * se_beta_hat_1
# Print the confidence interval
cat("95% confidence interval for beta_hat_1: (", lower_bound_1, ", ", upper_bound_1, ")\n")
## 95% confidence interval for beta_hat_1: ( 1.853359 , 2.146641 )
To find the estimated standard error of π½Μ1 β π½Μ2, we need to consider the covariance between π½Μ1 and π½Μ2 as well. The formula for the standard error of π½Μ1 β π½Μ2 is:
SE(π½Μ1 β π½Μ2) = sqrt(Var(π½Μ1) + Var(π½Μ2) - 2 * Cov(π½Μ1, π½Μ2))
where Var(π½Μ1) and Var(π½Μ2) are the variances of π½Μ1 and π½Μ2, and Cov(π½Μ1, π½Μ2) is the covariance between π½Μ1 and π½Μ2. These values can be obtained from the variance-covariance matrix calculated earlier.
# Extract variances and covariance from the variance-covariance matrix
var_beta_hat_1 <- var_cov_matrix[2, 2]
var_beta_hat_2 <- var_cov_matrix[3, 3]
cov_beta_hat_1_2 <- var_cov_matrix[2, 3]
# Calculate the standard error of beta_hat_1 - beta_hat_2
se_beta_hat_1_2 <- sqrt(var_beta_hat_1 + var_beta_hat_2 - 2 * cov_beta_hat_1_2)
# Print the standard error
print(se_beta_hat_1_2)
## [1] 0.2634097
To find the 95% confidence interval of π½Μ1 β π½Μ2, we will use the estimated standard error we calculated previously, as well as the normal distribution critical value (z-score) for a 95% confidence level, which is 1.96.
The formula for the confidence interval is:
CI(π½Μ1 - π½Μ2) = (π½Μ1 - π½Μ2) Β± z_Ξ±/2 * SE(π½Μ1 - π½Μ2)
where (π½Μ1 - π½Μ2) is the difference between the MLEs of π½1 and π½2, z_Ξ±/2 is the critical value from the normal distribution for a 95% confidence level (Ξ± = 0.05), and SE(π½Μ1 - π½Μ2) is the estimated standard error of π½Μ1 - π½Μ2.
# Define the MLEs of beta_1 and beta_2
beta_hat_1 <- 2.0
beta_hat_2 <- 1.0
# Define the critical value (z-score) for a 95% confidence interval
z_critical <- 1.96
# Calculate the difference between beta_hat_1 and beta_hat_2
beta_hat_diff <- beta_hat_1 - beta_hat_2
# Calculate the confidence interval for beta_hat_diff
lower_bound_2 <- beta_hat_diff - z_critical * se_beta_hat_1_2
upper_bound_2 <- beta_hat_diff + z_critical * se_beta_hat_1_2
# Print the confidence interval
cat("95% confidence interval for beta_hat_1 - beta_hat_2: (", lower_bound_2, ", ", upper_bound_2, ")\n")
## 95% confidence interval for beta_hat_1 - beta_hat_2: ( 0.483717 , 1.516283 )
Letβs summarize the 95% confidence intervals obtained in the previous two questions:
Now, weβll comment on the two null hypotheses:
π»0: π½Μ1 = 1.5 To test this hypothesis at a significance level of 0.05, we need to check if the hypothesized value (1.5) is within the 95% confidence interval for π½Μ1. The value 1.5 is not within the interval (1.853359, 2.146641), we reject the null hypothesis.
π»0: π½Μ1 - π½Μ2 = 0 To test this hypothesis at a significance level of 0.05, we need to check if the hypothesized value (0) is within the 95% confidence interval for π½Μ1 - π½Μ2. The value 0 is not within the interval (0.483717, 1.516283), we reject the null hypothesis.
We are given that π«(π¦; π) = exp(π¦ β π1(π) - π2(π)). Letβs rewrite the geometric distributionβs probability mass function in terms of exponential functions:
π«(π¦; π) = π(1 β π)^(π¦-1)
Taking the natural logarithm of π and (1 - π)^(π¦-1):
log(π) = log(exp(log(π)))
(1 - π)^(π¦-1) = exp((π¦-1) * log(1-π))
Now, letβs rewrite the geometric distribution in terms of exponentials:
π«(π¦; π) = exp(log(π) + (π¦-1) * log(1-π))
Now, we can see that π1(π) = log(1-π) and π2(π) = -log(π). So we have:
π = π1(π) = log(1-π) π (π) = π2(π) = -log(π)
To rewrite π (π) as a function of π, we need to express π in terms of π:
π = log(1-π) βΉ exp(π) = 1-π βΉ π = 1 - exp(π)
Now, substitute π in π (π):
π (π) = -log(1 - exp(π))
Since π = 1, we can find π(π¦,π):
π(π¦,π) = π¦ - 1
So, we have:
π = log(1-π) π = 1 π (π) = -log(1 - exp(π)) π(π¦,π) = π¦ - 1
We know that for the geometric distribution, π = πΈ[π¦] = 1/π. We also know that π = log(1-π). Our goal is to find the canonical link function, π(π), such that π = π(π).
First, letβs express π in terms of π:
1/π = π βΉ π = 1/π
Now, substitute this expression for π in the equation for π:
π = log(1 - (1/π))
Thus, the canonical link function for the geometric distribution is:
π(π) = log(1 - (1/π))
We know that for the geometric distribution, π£ππ[π¦] = (1βπ)/π^2. We also know that π = 1/π and π = 1. Our goal is to find the variance function, π(π), such that π£ππ[π¦] = π β π(π).
First, letβs rewrite π£ππ[π¦] in terms of π:
π£ππ[π¦] = (1β(1/π))/(1/π)^2
Now, since π = 1, the variance function π(π) is equal to π£ππ[π¦]:
π(π) = (1β(1/π))/(1/π)^2
Thus, the variance function for the geometric distribution is:
π(π) = (1β(1/π))/(1/π)^2
π (π) = -log(1 - exp(π)) ππ (π)/ππ = exp(π)/(1 - exp(π))
exp(π) = 1-π
ππ (π)/ππ = (1-π)/π
π = (1-π)/π
π = 1/(1+π)
π = 1/π
ππ (π)/ππ = (1-π)/π
πΒ²π (π)/ππΒ² = π((1-(1-exp(π)))/((1-exp(π))))/ππ = π(exp(π)/(1-exp(π)))/ππ
Let u = exp(π) and v = (1 - exp(π)):
πΒ²π (π)/ππΒ² = (v(πu/ππ) - u(πv/ππ))/vΒ²
Since πu/ππ = exp(π) and πv/ππ = -exp(π):
πΒ²π (π)/ππΒ² = ((1-exp(π))(exp(π)) - exp(π)(-exp(π)))/(1-exp(π))^2 = (exp(2π))/(1-exp(π))^2
Now, letβs find π£ππ[π¦] = π((πΒ²π (π)/ππΒ²)):
Since π = 1:
π£ππ[π¦] = (exp(2π))/(1-exp(π))^2
We know that π = log(1-π), so exp(π) = 1-π:
π£ππ[π¦] = (1-π)2/(π2) = (1-π)/π^2
To find the MLE of π for a single observation π¦1, we need to maximize the likelihood function.
L(π; π¦1) = π(1-π)^(π¦1-1)
β(π) = log(π) + (π¦1 - 1)log(1-π)
Differentiating β(π) with respect to π:
dβ(π)/dπ = 1/π - (π¦1 - 1)/(1-π)
Setting the derivative equal to zero:
1/π - (π¦1 - 1)/(1-π) = 0
Solving for π:
π = 1/π¦1
The MLE of π is 1/π¦1.
# Load the data
data(nambeware)
nambeware_data <- nambeware
# Create a scatter plot
plot(nambeware_data$Diam, nambeware_data$Price, xlab="Diam", ylab="Price", main="Price vs. Diam")
# Add a regression line
model <- lm(Price ~ Diam, data=nambeware_data)
abline(model, col="red")
Trend: The price tends to increase as the diameter increases, thereβs a positive correlation between the two variables.
Dispersion: With lower diameters the price appears to be closely correlated with diameter, but as diameter increases we see an increase in the variance of dispersion of the points along our line.
# Divide the data into age groups
groups <- cut(nambeware_data$Diam, breaks=c(-Inf, 8.25, 10.25, 12.25, 14.25, Inf), right = FALSE)
# Calculate group means, variances, and sample sizes
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
group_summary <- nambeware_data %>%
mutate(group = groups) %>%
group_by(group) %>%
summarise(
mean_blocks = mean(Diam),
var_blocks = var(Diam),
sample_size = n()
)
# Log-transform the group means and variances
group_summary$log_mean <- log(group_summary$mean_blocks)
group_summary$log_var <- log(group_summary$var_blocks)
# Plot log(group_variance) vs log(group_mean)
plot(group_summary$log_mean, group_summary$log_var,
xlab = "Log(Group Mean)", ylab = "Log(Group Variance)")
# Fit a linear model
lm_model <- lm(group_summary$log_var ~ group_summary$log_mean)
# Add the regression line to the plot
abline(lm_model, col="red")
# Convert the group_summary data.frame to a table
group_summary_table <- group_summary %>%
select(-log_mean, -log_var) %>%
rename(
`Age Group` = group,
`Sample Mean` = mean_blocks,
`Sample Variance` = var_blocks,
`Sample Size` = sample_size
)
# Transpose the group_summary_table
group_summary_table_transposed <- as.data.frame(t(group_summary_table[,-1]))
# Set the column names as the Age Group values
colnames(group_summary_table_transposed) <- group_summary_table$`Age Group`
# Add row names for Sample Mean, Sample Variance, and Sample Size
rownames(group_summary_table_transposed) <- c("Sample Mean", "Sample Variance", "Sample Size")
# Print the transposed table
print(group_summary_table_transposed)
## [-Inf,8.25) [8.25,10.2) [10.2,12.2) [12.2,14.2) [14.2, Inf)
## Sample Mean 6.420000 9.2818182 11.1666667 13.1583333 17.15556
## Sample Variance 1.137429 0.3056364 0.2842424 0.5499242 11.09028
## Sample Size 15.000000 11.0000000 12.0000000 12.0000000 9.00000
The table and plot of log(Group Variance) vs log(Group Mean) show a positive relationship between group mean and variance. A suitable Exponential Dispersion Model (EDM) for this is the Gamma distribution, with a variance function:
V(ΞΌ) = ΞΌ^2
This suggests that the variance increases quadratically with the mean, fitting the observed relationship in the data.