'Retrieving the values from the paramHankel.scaled() function (mixComp package)
paramHankel.scaled() is a function in mixComp package to be used for determining the components of a finite mixed model. For example, the following piece of codes shows how the function is used:
library("mixComp")
set.seed(0)
# construct a Mix object:
normLocMix <- Mix("norm", discrete = FALSE, w = c(0.3, 0.4, 0.3), mean = c(10, 13, 17), sd =
c(1, 1, 1))
# generate random samples:
normLocRMix <- rMix(1000, obj = normLocMix)
# plot the histograms of the random samples:
plot(normLocRMix, main = "Three component normal mixture", cex.main = 0.9)
# define the function for computing the moments:
mom.std.norm <- function(j){
ifelse(j %% 2 == 0, prod(seq(1, j - 1, by = 2)), 0)
}
MLE.norm.mean <- function(dat) mean(dat)
MLE.norm.sd <- function(dat){
sqrt((length(dat) - 1) / length(dat)) * sd(dat)
}
MLE.norm.list <- list("MLE.norm.mean" = MLE.norm.mean, "MLE.norm.sd" = MLE.norm.sd)
# define the range for parameter values:
norm.bound.list <- list("mean" = c(-Inf, Inf), "sd" = c(0, Inf))
# create datMix objects:
normLoc.dM <- RtoDat(normLocRMix, theta.bound.list = norm.bound.list,
MLE.function = MLE.norm.list, Hankel.method = "translation",
Hankel.function = mom.std.norm)
# define the penalty function:
pen <- function(j, n){
j * log(n)
}
# apply papamHankel.scaled to datMix objects:
norm_sca_pen <- paramHankel.scaled(normLoc.dM)
# plot the results for both mixtures:
par(mar=c(5, 5, 1, 1))
plot(norm_sca_pen)
In the last lines we used
norm_sca_pen <- paramHankel.scaled(normLoc.dM)
The parameters of the mixture model for 2 components are:
Parameter estimation for a 2 component 'norm' mixture model:
Function value: 2392.6800
w mean sd
Component 1: 0.74923 11.88077 2.0151
Component 2: 0.25077 17.14082 0.9251
Converged in 3 iterations.
How can I retrieve the values of weights (w), means and sd's from norm_sca_pen for the 2 components model?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
