TODO: Complete the data-specific numerical results and diagnostics when the original
Iris_data.csv is available.The estimate requested is the sample mean, . The named electronic file
Iris_data.csv is not present in the supplied source archive or this repository, and its measurements are not printed in the paper. Consequently its numerical sample mean cannot be recovered from the paper alone. The familiar built-in iris data must not be silently substituted: the question does not identify those observations as its sample.The following R code reads the actual file and prints its sample mean. The later code blocks in Question 2 continue this same script and use the resulting
x, n and xbar.dat <- read.csv("Iris_data.csv", check.names = FALSE)
# Recognize common labels, or a single measurement column.
keys <- tolower(gsub("[^[:alnum:]]", "", names(dat)))
j <- which(keys %in% c("sepallength", "sepallengthcm", "x"))
if (length(j) == 0L && ncol(dat) == 1L) j <- 1L
if (length(j) != 1L) {
stop("Select the sepal-length column explicitly after inspecting names(dat).")
}
x <- dat[[j]]
stopifnot(is.numeric(x), length(x) > 0L, all(is.finite(x)))
n <- length(x)
xbar <- mean(x)
cat("n =", n, " sample mean =", format(xbar, digits = 12), "\n")This reader assumes a header row and one observation per row. An alternative layout should be identified explicitly rather than dropping measurements or treating an identifier column as a length.
TODO: Complete the data-specific numerical results and diagnostics when the original
Iris_data.csv is available.The identityshows that the likelihood function is a bell-shaped curve in , maximized at the sample mean, with width . Its actual vertical scale also depends on the within-sample sum of squares.
Continue the R script with:
sse <- sum((x - xbar)^2)
loglik <- function(mu) {
-n/2 * log(2*pi) - 0.5 * (sse + n * (mu - xbar)^2)
}
grid <- seq(3, 6, length.out = 2001L)
ell <- loglik(grid)
png("q2-likelihood.png", width = 900, height = 600)
par(mar = c(4.5, 4.5, 4, 1))
if (max(ell) > log(.Machine$double.xmin)) {
plot(grid, exp(ell), type = "l", xlab = expression(mu),
ylab = expression(L(mu)), main = "Likelihood on [3,6]")
} else {
# Explicitly label a proportional likelihood if the true scale underflows.
plot(grid, exp(ell - max(ell)), type = "l", xlab = expression(mu),
ylab = "Likelihood relative to maximum on plotted grid",
main = "Likelihood on [3,6] (rescaled)")
}
abline(v = xbar, col = "steelblue", lty = 2)
dev.off()Working first with the log-likelihood avoids premature numerical underflow. The fallback preserves the shape on the requested interval and labels the altered scale. A data-specific plot requires the missing CSV file; no fabricated observation set is used here.
Articles by others on the same topic
There are currently no matching articles.