# #设置,包括= FALSE ----------------------------------------------------- 库(knitr) #全局选项opts_chunk $ (fig.path = "无花果 /") ## ---- NetResponse1,警告= FALSE,消息= FALSE ------------------------------- 库(netresponse) #产生模拟数据res < -生成。toydata(Dim = 3, Nc = 3, Ns = 200, sd0 = 3, rgam。形状= 1,rgam。1) D <- res$data组件。表示<- res$表示组件。sds <- res$sds sample2comp <- res$sample2comp #使用全连接网络网络<- matrix(rep(1,9), nrow = 3) #适合NetResponse模型#支持各种网络格式,请参阅help(detect.responses)了解#详细信息。对于大型数据集,考虑“加速”选项。Set.seed (4243) res <-检测。反应(D,网络,混合。方法= "vdp", pca。base = TRUE) #列出子网(每个是节点的列表)子网。id <- names(get.subnets(res))[[1]] ## ----NetResponse2, fig.width=6, fig.height=6, warning=FALSE, message=FALSE, fig.show="hide", eval=FALSE---- # library(ggplot2) # vis <- plot_responses(res,子网。id, plot_mode = "pca") ## ----NetResponse2b, fig.width=6, fig.height=5, warning=FALSE, message=FALSE, eval=FALSE---- ##修改生成的ggplot2对象以增强可视化# p <- vis$p #从结果中选择ggplot2对象# p <- p + geom_point(size = 3) #修改点大小# print(p) ## ----NetResponse3, fig.width=8, fig.height=8, warning=FALSE, message=FALSE, eval=FALSE---- # vis <- plot_responses(res,子网。id, plot_mode = "network") ## ----NetResponse4, fig.width=8, fig.height=8, warning=FALSE, message=FALSE, eval=FALSE---- # vis <- plot_responses(res,子网。id, plot_mode = "heatmap") ## ----NetResponse5, fig.width=8, fig.height=8, warning=FALSE, message=FALSE, eval=FALSE---- # vis <- plot_responses(res,子网。id, plot_mode = "boxplot_data") ## ----NetResponse7, fig.width=8, fig.height=8, warning=FALSE, message=FALSE, eval=FALSE---- # plot_scale(vis$breaks, vis$palette,两个。支持= TRUE) # #——NetResponse8警告= FALSE,消息= FALSE ------------------------------- 子网。id <- 'Subnet-1' #样本-响应概率(软集群分配)响应。Probs <- sample2response(res, subnet.id) tail(round(response. id)问题,6))#样本-回答困难的任务。clusters <- response2sample(res, subnet.id) print(hard.clusters) ## ----NetResponse9, warning=FALSE, message=FALSE------------------------------- params <- get.model.parameters(res, subnet.id) names(params) ## ----vdp, warning=FALSE, message=FALSE---------------------------------------- # Generate 2-dimensional simulated data with 3 clusters res <- generate.toydata(Dim = 2, Nc = 3, Ns = 200, sd0 = 3, rgam.shape = 1, rgam.scale = 1) D <- res$data real.means <- res$means real.sds <- res$sds real.sample2comp <- res$sample2comp # Infinite Gaussian mixture model with # Variational Dirichlet Process approximation mixt <- vdp.mixt( D ) # Centroids of the detected Gaussian components estimated.means <- mixt$posterior$centroids # The colors denote the known clusters # The blue ball denotes the original (known) cluster centroids and # the triangle denotes the estimated centroids plot(D, col = real.sample2comp, pch = 1) points(real.means, col = "blue", pch = 16, cex = 2) points(estimated.means, col = "blue", pch = 17, cex = 2) # Hard mixture component assignment for each sample estimated.sample2comp <- apply(mixt$posterior$qOFz, 1, which.max) # Compare known and estimated mixture components # (note that cluster indices may have switched due to unidentifiability) # nearly all samples have one-to-one match between the real and estimated # clusters head(table(estimated.sample2comp, real.sample2comp)) ## ----cite, warning=FALSE, message=FALSE--------------------------------------- citation("netresponse") ## ----version, warning=FALSE, message=FALSE------------------------------------ sessionInfo()