set.seed(123)
@@ -460,7 +460,7 @@
## plot the data, color by latent component z
par(mar = c(4, 4, 4, 1))
-plot(d, col = z + 1, main = "Simulated Data by Latent Class",
+plot(d, col = z + 1, main = "Simulated Data by Latent Component",
xlab = "x", ylab = "y")
4 Predicting and Visualizing Results
-We predict the component-specific means (mu1
, mu2
) and the mixing probability (pi
) from the fitted model. Then, we compare the predicted and true class probabilities and plot the fitted means along with the data.
-First, compute predicted parameters
+We predict the component-specific means (mu1
, mu2
) and the mixing probability (pi
) from the fitted model. Then, we compare the predicted and true component probabilities and plot the fitted means along with the data.
+First, compute predicted parameters.
<- predict(b, type = "parameter") p
-Plot estimated vs. true component probabilities
+Plot estimated vs. true component probabilities.
-plot(p$pi, mix_prob, main = "Estimated vs. True Class Probabilities",
+plot(p$pi, mix_prob, main = "Estimated vs. True Component Probabilities",
xlab = "Estimated Probability", ylab = "True Probability")
abline(0, 1)
@@ -546,21 +546,21 @@ ## compute posterior class probabilities
+## compute posterior component probabilities
<- dnorm(d$y, p$mu1, p$sigma1)
d1 <- dnorm(d$y, p$mu2, p$sigma2)
d2 <- rowSums(cbind(p$pi * d1, (1 - p$pi) * d2))
totprob <- p$pi * d1 / totprob
c1 <- (1 - p$pi) * d2 / totprob
c2
-## get classes
-<- apply(cbind(c2, c1), 1, which.max)
+ classes ## get components
+<- apply(cbind(c2, c1), 1, which.max)
comp
## plot the data and fitted component means
par(mar = c(4, 4, 4, 1))
plot(y ~ x, data = d,
main = "Fitted Component Means",
- xlab = "x", ylab = "y", col = classes)
+ xlab = "x", ylab = "y", col = comp)
lines(p$mu1 ~ x, col = 2, lwd = 4)
lines(p$mu2 ~ x, col = 1, lwd = 4)
@@ -574,7 +574,7 @@
5 Summary
-
In this vignette, we have demonstrated how to fit a mixture model where the mixing probabilities depend on a covariate. We simulated data, defined a custom mixture family, and fitted the model to estimate the component means and mixing probabilities. Finally, we compared the predicted class probabilities with the true values and visualized the results.
+In this vignette, we have demonstrated how to fit a mixture model where the mixing probabilities depend on a covariate. We simulated data, defined a custom mixture family, and fitted the model to estimate the component means and mixing probabilities. Finally, we compared the predicted component probabilities with the true values and visualized the results.
diff --git a/vignettes/mixture_files/figure-html/unnamed-chunk-1-1.png b/vignettes/mixture_files/figure-html/unnamed-chunk-1-1.png
index d766115..0107f52 100644
Binary files a/vignettes/mixture_files/figure-html/unnamed-chunk-1-1.png and b/vignettes/mixture_files/figure-html/unnamed-chunk-1-1.png differ
diff --git a/vignettes/mixture_files/figure-html/unnamed-chunk-6-1.png b/vignettes/mixture_files/figure-html/unnamed-chunk-6-1.png
index 1cff4b9..9117023 100644
Binary files a/vignettes/mixture_files/figure-html/unnamed-chunk-6-1.png and b/vignettes/mixture_files/figure-html/unnamed-chunk-6-1.png differ
diff --git a/vignettes/spatial.html b/vignettes/spatial.html
index 94b2854..720a1c4 100644
--- a/vignettes/spatial.html
+++ b/vignettes/spatial.html
@@ -595,7 +595,7 @@
+AIC = 16682.1271 elapsed = 4.40sec
Model calibration is checked using histogram, Q-Q plot, wormplot etc.
diff --git a/vignettes/spatial_files/figure-html/unnamed-chunk-7-1.png b/vignettes/spatial_files/figure-html/unnamed-chunk-7-1.png
index 8ea89f6..326d8b7 100644
Binary files a/vignettes/spatial_files/figure-html/unnamed-chunk-7-1.png and b/vignettes/spatial_files/figure-html/unnamed-chunk-7-1.png differ
4 Predicting and Visualizing Results
-We predict the component-specific means (mu1
, mu2
) and the mixing probability (pi
) from the fitted model. Then, we compare the predicted and true class probabilities and plot the fitted means along with the data.
First, compute predicted parameters
+We predict the component-specific means (mu1
, mu2
) and the mixing probability (pi
) from the fitted model. Then, we compare the predicted and true component probabilities and plot the fitted means along with the data.
First, compute predicted parameters.
<- predict(b, type = "parameter") p
Plot estimated vs. true component probabilities
+Plot estimated vs. true component probabilities.
plot(p$pi, mix_prob, main = "Estimated vs. True Class Probabilities",
+plot(p$pi, mix_prob, main = "Estimated vs. True Component Probabilities",
xlab = "Estimated Probability", ylab = "True Probability")
abline(0, 1)
@@ -546,21 +546,21 @@ ## compute posterior class probabilities
+## compute posterior component probabilities
<- dnorm(d$y, p$mu1, p$sigma1)
d1 <- dnorm(d$y, p$mu2, p$sigma2)
d2 <- rowSums(cbind(p$pi * d1, (1 - p$pi) * d2))
totprob <- p$pi * d1 / totprob
c1 <- (1 - p$pi) * d2 / totprob
c2
-## get classes
-<- apply(cbind(c2, c1), 1, which.max)
+ classes ## get components
+<- apply(cbind(c2, c1), 1, which.max)
comp
## plot the data and fitted component means
par(mar = c(4, 4, 4, 1))
plot(y ~ x, data = d,
main = "Fitted Component Means",
- xlab = "x", ylab = "y", col = classes)
+ xlab = "x", ylab = "y", col = comp)
lines(p$mu1 ~ x, col = 2, lwd = 4)
lines(p$mu2 ~ x, col = 1, lwd = 4)
@@ -574,7 +574,7 @@
5 Summary
-
In this vignette, we have demonstrated how to fit a mixture model where the mixing probabilities depend on a covariate. We simulated data, defined a custom mixture family, and fitted the model to estimate the component means and mixing probabilities. Finally, we compared the predicted class probabilities with the true values and visualized the results.
+In this vignette, we have demonstrated how to fit a mixture model where the mixing probabilities depend on a covariate. We simulated data, defined a custom mixture family, and fitted the model to estimate the component means and mixing probabilities. Finally, we compared the predicted component probabilities with the true values and visualized the results.
diff --git a/vignettes/mixture_files/figure-html/unnamed-chunk-1-1.png b/vignettes/mixture_files/figure-html/unnamed-chunk-1-1.png
index d766115..0107f52 100644
Binary files a/vignettes/mixture_files/figure-html/unnamed-chunk-1-1.png and b/vignettes/mixture_files/figure-html/unnamed-chunk-1-1.png differ
diff --git a/vignettes/mixture_files/figure-html/unnamed-chunk-6-1.png b/vignettes/mixture_files/figure-html/unnamed-chunk-6-1.png
index 1cff4b9..9117023 100644
Binary files a/vignettes/mixture_files/figure-html/unnamed-chunk-6-1.png and b/vignettes/mixture_files/figure-html/unnamed-chunk-6-1.png differ
diff --git a/vignettes/spatial.html b/vignettes/spatial.html
index 94b2854..720a1c4 100644
--- a/vignettes/spatial.html
+++ b/vignettes/spatial.html
@@ -595,7 +595,7 @@
+AIC = 16682.1271 elapsed = 4.40sec
Model calibration is checked using histogram, Q-Q plot, wormplot etc.
diff --git a/vignettes/spatial_files/figure-html/unnamed-chunk-7-1.png b/vignettes/spatial_files/figure-html/unnamed-chunk-7-1.png
index 8ea89f6..326d8b7 100644
Binary files a/vignettes/spatial_files/figure-html/unnamed-chunk-7-1.png and b/vignettes/spatial_files/figure-html/unnamed-chunk-7-1.png differ