# Carrying out the cluster test (3.1) library("bayesclust") data("egDataset1") clusterTestK3 <- cluster.test(egDataset1, nsim=500000, p=2, k=3, mcs=0.1, replications = 4) plot(clusterTestK3) summary(clusterTestK3) # Distribution of estimates under the null hypothesis (3.2) nulldensK3 <- nulldensity(n=75, nsim=8000, k=3, mcs=0.1, p=2, prop=0.25) hist(nulldensK3, main="Null Density Histogram", xlab="samples") # Obtaining frequentist p-value (3.3) emp2pval(clusterTestK3, nulldensK3) # Searching for optimal clusters (3.4) clusterOptK3 <- cluster.optimal(egDataset1, nsim=100000, p=2, k=3, mcs=0.1) plot(clusterOptK3) # Conducting multiple tests on a single dataset (4.1) clusterTestK2 <- cluster.test(egDataset1, nsim=500000, p=2, k=2, mcs=0.1, replications = 4) clusterTestK4 <- cluster.test(egDataset1, nsim=500000, p=2, k=4, mcs=0.1, replications = 4) combine(clusterTestK2, clusterTestK3, clusterTestK4) # Using the default null distributions (4.2) data("cutoffs") tail(cutoffs) # Comparison with mclust (5) library("mclust") data("diabetes") X <- as.matrix(diabetes[,2:4]) clusterTestK3 <- cluster.test(X, nsim=500000, p=3, k=3, mcs=0.1, replications = 4) nulldensK3 <- nulldensity(n=145, nsim=8000, k=3, mcs=0.1, p=3, prop=0.25) emp2pval(clusterTestK3, nulldensK3) clusterOptK3 <- cluster.optimal(X, nsim=200000, p=3, k=3, mcs=0.1)