bmmix: Bayesian multinomial mixture model estimation using MCMC

Description Usage Arguments Details Value Author(s) Examples

Description

This function and model are under development. Do not use them, contact the author if interested.

Usage

1
2
3
4
bmmix(x, y, n = 50000, sample.every = 200, move.alpha = TRUE,
  move.phi = FALSE, sd.alpha = 0.1, sd.phi = 0.05, move.phi.every = 10,
  model.unsampled = FALSE, prior.unsampled.contrib = 0.1,
  min.ini.freq = 0.01, file.out = "mcmc.txt", quiet = FALSE)

Arguments

x

a matrix containing multinomial data in columns used to compose the mixture (i.e., each column is an 'origin').

y

a vector of the same length as the number of rows of x containing the response variable.

n

the length of the MCMC.

sample.every

an integer indicating the frequency at which to save MCMC samples.

move.alpha

a logical indicating whether the mixture coefficients (alpha) should be estimated.

move.phi

a logical indicating whether the frequencies in x (phi) should be estimated; see details.

sd.alpha

the standard deviation of the normal distribution used as proposal for alpha.

sd.phi

the standard deviation of the normal distribution used as proposal for phi.

move.phi.every

the frequency at which values of phi should be moved.

model.unsampled

a logical indicating whether an 'unsampled origin' should be allowed; if TRUE, then move.phi should be TRUE as well, to allow for frequencies in this group to be estimated.

prior.unsampled.contrib

the mean of the exponential distribution used as prior for the contribution of the unsampled origin in the mixture; all other origins have flat priors.

min.ini.freq

the default minimum frequency of unobserved items in x used for the initial frequency estimate.

file.out

the name of the file used to store the outputs.

quiet

a logical indicating whether output messages should be hidden.

Details

There are essentially 4 variants of the model implemented by bmmix:

Value

A data.frame with class 'bmmix', containing the MCMC outputs: step, log-posterior, log- likelihood, log-prior, alpha values (mixture coefficients), and optionally frequencies for each group and origin (phi).

Author(s)

Thibaut Jombart t.jombart@imperial.ac.uk

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
## GENERATE TOY DATA ##
## ST frequencies in 3 origins:
## dogs, cows, asymptotic cases in human
f.dogs <- c(.5, .3, .1, .1, 0)
f.cows <- c(.6, .1, .1, .1, .1)
f.asymp <- c(0, .1, .2, 0, .7)

## mixture (y would be symptomatic cases)
f.y <- .1*f.dogs + .1*f.cows + .8*f.asymp

set.seed(1)
dogs <- rmultinom(1, 30, f.dogs)
cows <- rmultinom(1, 50, f.cows)
asymp <- rmultinom(1, 35, f.asymp)
X <- data.frame(dogs, cows, asymp,
   row.names=paste("ST", letters[1:5]))
X
y <- rmultinom(1, 40, f.y)
y

cbind(X,y)


## RUN BMMIX ##

## BASIC MODEL
## note: small n for this example only!
set.seed(1)
res <- bmmix(X,y, n=3e4)
head(res)


## VISUALIZE RESULTS ##
if(require("ggplot2") && require("reshape2")){

## manually ##
## chech log-posterior
ggplot(dat=res) + geom_line(aes(x=step, y=post)) +
   labs(title="Trace of log-posterior values")

## check mixture coefficients
fig.dat <- melt(res, id=1:4)

ggplot(dat=fig.dat, aes(x=step)) +
   geom_line(aes(y=value, colour=variable)) +
   labs(title="Trace of mixture coefficients")


## with process.bmmix ##
## mixture coefficients
temp <- process.bmmix(res, "alpha")
names(temp)
temp$alpha # values
temp$trace # graphics: trace
temp$hist # graphics: histograms
temp$dens # graphics: densities
temp$violin # graphics: violinplot

}


## Not run: 
## MODEL WITH ESTIMATED FREQUENCIES
set.seed(1)
res <- bmmix(X,y, move.phi=TRUE)
head(res)

## VISUALIZE RESULTS
if(require("ggplot2") && require("reshape2")){

## chech log-posterior
ggplot(dat=res) + geom_line(aes(x=step, y=post)) +
   labs(title="Trace of log-posterior values")

fig.dat <- melt(res[,1:7], id=1:4)

## check mixture coefficients
ggplot(dat=fig.dat, aes(x=step)) +
   geom_line(aes(y=value, colour=variable)) +
   labs(title="Trace of mixture coefficients")

## check ST frequencies, i.e. in dogs:
fig.dat <- melt(res[,c(1,grep("dogs", names(res))[-1])], id=1)

ggplot(dat=fig.dat) +
   geom_line(aes(x=step, y=value, colour=variable)) +
   labs(title="Estimate of ST frequencies in dogs")

ggplot(dat=fig.dat) +
   geom_density(aes(x=value, fill=variable),alpha=.2) +
   labs(title="Estimate of ST frequencies in dogs")
}

## End(Not run)

thibautjombart/bmmix documentation built on May 31, 2019, 9:56 a.m.