Here is an example implementation of Auto Adaptive M-Estimation (AAME) in R, finding the mean of a data and the error density. The data could be with a heavy-tailed and/or comtaminated error.
-
Run this in R: AAME_onesamp functions
- Load necessary library:
library(quadprog) - Generate a data, then fit the model:
set.seed(1) mu <- 100 y <- mu + rt(500,df=2) fit <- onesamp(y) - Estimated mean of the data, and its confidence interval:
fit$muhat fit$confidence.intervals - Plot the estimated error density function:
xp <- seq(-max(fit$knots),max(fit$knots),length=100) hist(y,xaxt='n',yaxt='n',xlab='',ylab = '',main="",probability = T,nclass = 100) lines(fit$fhat(xp)~c(xp+fit$muhat),lwd=2)