set.seed(123)
x <- rnorm(100, mean=50, sd=5)
descriptives <- descstats(x)
as.data.frame(descriptives)
descriptives$mean
descriptives$se
# Determining the appropriate k in a given set of different k values.
# This parameter is used to calculate the Huber M-estimator of the location
# Array of k values for testing
k <- seq(0, 5, by = 0.1)
k <- k[k> 0]
result <- sapply(k, function(y) descstats(x, k = y)$hubermean)
names(result) <- paste0("k=", k)
result
plot(k, result, type = "b", col = "blue", pch = 19, ylab = "Huber's mean")
descstats(x, k=2, trim=0.05)$hubermean
Run the code above in your browser using DataLab