cluster_assign_mode: Function for computing the posterior mode cluster assignment...

Description Usage Arguments Details Value Examples

View source: R/cluster_assign_mode.r

Description

This function takes the cluster_inds - which is a posterior matrix of cluster assignments output by NDPMix(), PDPMix(), and ZDPMix() and computes the posterior mode cluster assignment while implementing a deterministic re-labeling of subjects.

Please see https://stablemarkets.github.io/ChiRPsite/index.html for examples and detailed model and parameter descriptions.

Usage

1

Arguments

c_shell

set this to cluster_inds (for either training or testing sets). cluster_inds is output by NDPMix(), PDPMix(), and ZDPMix().

Details

Please see https://arxiv.org/abs/1810.09494, section on hyperparameters and label switching for more information.

Value

This function returns a list of two objects: adjmat and class_mem. For n subjects, the former is an n by n adjacency matrix with i-j th element giving the posterior probability of subject i and j being clustered together. This can be visualized using a network diagram (see examples on website linked in Details). class_mem is a vector of length n giving posterior mode clsuter membership for each of the n subjects. This can be used for cluster-specific analysis, for example.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# simulate data 

set.seed(1)
n<-200 ## generate from clustered, skewed, data distribution
X11 <- rnorm(n = n, mean = 10, sd = 3)
X12 <- rnorm(n = n, mean = 0, sd = 2)
X13 <- rnorm(n = n, mean = -10, sd = 4)

Y1 <- rnorm(n = n, mean = 100 + .5*X11, 20)*(1-rbinom(n, 1, prob = pnorm( -10 + 1*X11 ) ))
Y2 <- rnorm(n = n, mean = 200 + 1*X12, 30)*(1-rbinom(n, 1, prob = pnorm( 1 + .05*X12 ) ))
Y3 <- rnorm(n = n, mean = 300 + 2*X13, 40)*(1-rbinom(n, 1, prob = pnorm( -3 -.2*X13 ) ))

d <- data.frame(X1=c(X11, X12, X13), Y = c(Y1, Y2, Y3))

# split into training and testing
ids <- sample(1:600, size = 500, replace = FALSE )

d$X1 <- scale(d$X1)

d_train <- d[ids,]
d_test <- d[-ids, ]

# run zero-inflated model #' 
res <- ChiRP::ZDPMix(d_train = d_train, d_test = d_test, formula = Y ~ X1,
                     burnin=100, iter=200, init_k = 5, phi_y = c(10, 10000))

# compute the posterior model cluster assignment for training subjects
train_clus <- ChiRP::cluster_assign_mode(res$cluster_inds$train)

stablemarkets/ChiRP documentation built on July 26, 2021, 2:25 a.m.