## Generate simulated dataset.
Theta <- rbind(pdf1 = rep("normal", 2),
theta1.1 = c(10, 20),
theta2.1 = c(3.0, 2.0),
pdf1 = rep("Weibull", 2),
theta1.1 = c(3, 2),
theta2.1 = c(20, 10))
simulated <- RNGMIX(Dataset = "simulated",
rseed = -1,
n = c(15, 25),
Theta = Theta)
## Estimate number of components, component weights and component parameters.
simulatedest <- REBMIX(Dataset = simulated$Dataset,
Preprocessing = "Parzen window",
D = 0.025,
cmax = 4,
Criterion = "BIC",
Variables = c("continuous", "continuous"),
pdf = c("normal", "Weibull"),
K = 8)
## Preprocess and plot finite mixtures.
opar <- plot(simulatedest)
par(opar)
y1f <- demix(x = simulatedest$Dataset[[1]][, 1, drop = FALSE],
Preprocessing = "Parzen window",
Variables = "continuous",
k = 8)
y1 <- seq(from = min(y1f[, 1]), to = max(y1f[, 1]), length.out = 200)
f1 <- dfmix(x = cbind(y1), w = simulatedest$w[[1]], simulatedest$Theta[[1]][1:3,])
y2f <- demix(x = simulatedest$Dataset[[1]][, 2, drop = FALSE],
Preprocessing = "Parzen window",
Variables = "continuous",
k = 8)
y2 <- seq(from = min(y2f[, 1]), to = max(y2f[, 1]), length.out = 200)
f2 <- dfmix(x = cbind(y2), w = simulatedest$w[[1]], simulatedest$Theta[[1]][4:6,])
opar <- par(mfrow = c(1, 2))
plot(y1, f1, xlab = bquote(y[1]), ylab = bquote(f(y[1])), type = "l", col = "blue")
points(y1f, pch = 3, col = "red")
plot(y2, f2, xlab = bquote(y[2]), ylab = bquote(f(y[2])), type = "l", col = "blue")
points(y2f, pch = 3, col = "red")
par(opar)
Run the code above in your browser using DataLab