# NOT RUN {
## observations from a (presumed) mixture model
obs <- faithful$waiting
## generate list of parameter bounds (assuming gaussian components)
norm.bound.list <- list("mean" = c(-Inf, Inf), "sd" = c(0, Inf))
## generate MLE functions
# for "mean"
MLE.norm.mean <- function(dat) mean(dat)
# for "sd" (the sd function uses (n-1) as denominator)
MLE.norm.sd <- function(dat){
sqrt((length(dat) - 1) / length(dat)) * sd(dat)
}
# combining the functions to a list
MLE.norm.list <- list("MLE.norm.mean" = MLE.norm.mean,
"MLE.norm.sd" = MLE.norm.sd)
## function giving the j^th raw moment of the standard normal distribution,
## needed for calculation of the Hankel matrix via the "translation" method
## (assuming gaussian components with variance 1)
mom.std.norm <- function(j){
ifelse(j %% 2 == 0, prod(seq(1, j - 1, by = 2)), 0)
}
## generate 'datMix' object
faithful.dM <- datMix(obs, dist = "norm", discrete = FALSE,
theta.bound.list = norm.bound.list, MLE.function = MLE.norm.list,
Hankel.method = "translation", Hankel.function = mom.std.norm)
## using 'datMix' object to estimate the mixture complexity
set.seed(1)
res <- paramHankel.scaled(faithful.dM)
plot(res)
# }
Run the code above in your browser using DataLab