Last data update: 2014.03.03

R: Bayesian Latent Class Analysis with one of several methods
blcaR Documentation

Bayesian Latent Class Analysis with one of several methods

Description

Latent class analysis (LCA) attempts to find G hidden classes in binary data X. blca utilises one of: an EM algorithm, a variational Bayes approximation, Gibbs sampling or boot-strapping techniques to find maximum a posteriori (MAP), standard error and density estimates of the parameters.

Usage

blca(X, G, method = c("em", "gibbs", "boot", "vb"), ...)

Arguments

X

The data matrix. This may take one of several forms, see data.blca.

G

The number of classes to run lca for.

method

The method with which to perform lca on the data. Four methods are currently available, "em", "gibbs", "boot" or "vb". Defaults to "em", with a warning.

...

Additional arguments to be passed on, depending on the method. See additional help files for details.

Details

The function calls to one of blca.em, blca.boot, blca.gibbs, blca.vb, depending on the method specified.

Value

A list of class "blca" is returned. All methods return the following items:

classprob

The class probabilities.

itemprob

The item probabilities, conditional on class membership.

Z

Estimate of class membership for each unique datapoint.

prior

A list containing the prior values specified for the model.

See additional help files for details.

Note

Earlier versions of this function erroneously referred to posterior standard deviations as standard errors. This also extended to some of the variable names of the returned function, which are now returned with the corrected suffix blca.em.sd (for standard deviation). For backwards compatability reasons, the earlier suffix .se has been retained as a returned argument.

Author(s)

Arthur White

References

Arthur White, Thomas Brendan Murphy (2014). BayesLCA: An R Package for Bayesian Latent Class Analysis." Journal of Statistical Software, 61(13), 1-28. URL: http://www.jstatsoft.org/v61/i13/.

See Also

blca.em, blca.boot, blca.gibbs, blca.vb

Examples

type1 <- c(0.8, 0.8, 0.2, 0.2)
type2 <- c(0.2, 0.2, 0.8, 0.8)
x<- rlca(1000, rbind(type1,type2), c(0.6,0.4))

set.seed(1)
fit <- blca(x, 2) ## EM algorithm used, warning returned
print(fit)	  ## No posterior standard deviations returned
summary(fit)

set.seed(1)
fit2 <- blca(x, 2, method="em", sd=TRUE) ##No warning - same fit
print(fit2) 				 ##Posterior standard deviations returned

set.seed(1)
##Variational Bayes approximation, with priors specified.
fit3 <- blca(x, 2, method="vb", delta=c(5,5), alpha=2, beta=1) 
print(fit3)	##Posterior standard deviations returned also.
par(mfrow=c(3,2))			  
plot(fit3, which=3:4)
par(mfrow=c(1,1))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(BayesLCA)
Loading required package: e1071
Loading required package: coda
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/BayesLCA/blca.Rd_%03d_medium.png", width=480, height=480)
> ### Name: blca
> ### Title: Bayesian Latent Class Analysis with one of several methods
> ### Aliases: blca
> ### Keywords: blca lca
> 
> ### ** Examples
> 
> type1 <- c(0.8, 0.8, 0.2, 0.2)
> type2 <- c(0.2, 0.2, 0.8, 0.8)
> x<- rlca(1000, rbind(type1,type2), c(0.6,0.4))
> 
> set.seed(1)
> fit <- blca(x, 2) ## EM algorithm used, warning returned
Restart number 1, logpost = -2468.46... 
New maximum found... Restart number 2, logpost = -2468.46... 
Restart number 3, logpost = -2468.46... 
Restart number 4, logpost = -2468.46... 
Restart number 5, logpost = -2468.46... 
> print(fit)	  ## No posterior standard deviations returned

MAP Estimates:
 

Item Probabilities:
 
        Col 1 Col 2 Col 3 Col 4
Group 1 0.806 0.782 0.190 0.199
Group 2 0.214 0.197 0.793 0.814

Membership Probabilities:
 
Group 1 Group 2 
  0.598   0.402 
Warning message:
Posterior standard deviations not returned. 
> summary(fit)
__________________

Bayes-LCA
Diagnostic Summary
__________________

Hyper-Parameters: 

 Item Probabilities:

 alpha: 
        Col 1 Col 2 Col 3 Col 4
Group 1     1     1     1     1
Group 2     1     1     1     1

 beta: 
        Col 1 Col 2 Col 3 Col 4
Group 1     1     1     1     1
Group 2     1     1     1     1

 Class Probabilities:

 delta: 
Group 1 Group 2 
      1       1 
__________________

Method: EM algorithm  

 Number of iterations: 21 

 Log-Posterior Increase at Convergence: 0.001184776 

 Log-Posterior: -2468.456 

 AIC: -4954.912 

 BIC: -4999.082 
> 
> set.seed(1)
> fit2 <- blca(x, 2, method="em", sd=TRUE) ##No warning - same fit
Restart number 1, logpost = -2468.46... 
New maximum found... Restart number 2, logpost = -2468.46... 
Restart number 3, logpost = -2468.46... 
Restart number 4, logpost = -2468.46... 
Restart number 5, logpost = -2468.46... 
> print(fit2) 				 ##Posterior standard deviations returned

MAP Estimates:
 

Item Probabilities:
 
        Col 1 Col 2 Col 3 Col 4
Group 1 0.806 0.782 0.190 0.199
Group 2 0.214 0.197 0.793 0.814

Membership Probabilities:
 
Group 1 Group 2 
  0.598   0.402 

Posterior Standard Deviation Estimates:
 

Item Probabilities:
 
        Col 1 Col 2 Col 3 Col 4
Group 1 0.021 0.021 0.020 0.021
Group 2 0.027 0.028 0.029 0.027

Membership Probabilities:
 
Group 1 Group 2 
  0.024   0.024 
> 
> set.seed(1)
> ##Variational Bayes approximation, with priors specified.
> fit3 <- blca(x, 2, method="vb", delta=c(5,5), alpha=2, beta=1) 
Restart number 1, logpost = -6944.48... 
> print(fit3)	##Posterior standard deviations returned also.

MAP Estimates:
 

Item Probabilities:
 
        Col 1 Col 2 Col 3 Col 4
Group 1 0.806 0.782 0.191 0.200
Group 2 0.216 0.199 0.793 0.815

Membership Probabilities:
 
Group 1 Group 2 
  0.598   0.402 

Posterior Standard Deviation Estimates:
 

Item Probabilities:
 
        Col 1 Col 2 Col 3 Col 4
Group 1 0.016 0.017 0.016 0.016
Group 2 0.020 0.020 0.020 0.019

Membership Probabilities:
 
Group 1 Group 2 
  0.015   0.015 
> par(mfrow=c(3,2))			  
> plot(fit3, which=3:4)
> par(mfrow=c(1,1))
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>