Search This Blog

Tuesday, March 20, 2012

R: Semiparametric Bayesian Gaussian copula estimation and imputation

sbgcop.mcmc {sbgcop}R Documentation

Semiparametric Bayesian Gaussian copula estimation and imputation

Description

sbgcop.mcmc is used to semiparametrically estimate the parameters of a Gaussian copula. It can be used for posterior inference on the copula parameters, and for imputation of missing values in a matrix of ordinal and/or continuous values.

Usage

sbgcop.mcmc(Y, S0 = diag(dim(Y)[2]), n0 = dim(Y)[2] + 2, nsamp = 100,
  odens = max(1, round(nsamp/1000)), 
 impute=any(is.na(Y)),
 plugin.threshold=100,
 plugin.marginal=(apply(Y,2,function(x){ length(unique(x))})>plugin.threshold),
seed = 1, verb = TRUE)

Arguments

Y an n x p matrix. Missing values are allowed.
S0 a p x p positive definite matrix
n0 a positive integer
nsamp number of iterations of the Markov chain.
odens output density: number of iterations between saved samples.
impute save posterior predictive values of missing data(TRUE/FALSE)?
plugin.threshold if the number of unique values of a variable exceeds this integer, then plug-in the empirical distribution as the marginal.
plugin.marginal a logical of length p. Gives finer control over which margins to use the empirical distribution for.
seed an integer for the random seed
verb print progress of MCMC(TRUE/FALSE)?

Details

This function produces MCMC samples from the posterior distribution of a correlation matrix, using a scaled inverse-Wishart prior distribution and an extended rank likelihood. It also provides imputation for missing values in a multivariate dataset.

Value

An object of class psgc containing the following components:
C.psamp an array of size p x p x nsamp/odens, consisting of posterior samples of the correlation matrix.
Y.pmean the original datamatrix with imputed values replacing missing data
Y.impute an array of size n x p x nsamp/odens, consisting of copies of the original data matrix, with posterior samples of missing values included.
LPC the log-probability of the latent variables at each saved sample. Used for diagnostic purposes.

Author(s)

Peter Hoff

References

http://www.stat.washington.edu/hoff/

Examples

fit<-sbgcop.mcmc(swiss)
summary(fit)
plot(fit)

Results

R version 2.11.1 (2010-05-31)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

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.

  Natural language support but running in an English locale

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(sbgcop)
> png(filename="sbgcop.mcmc_%03d_med.png", width=480, height=480)
> ### Name: sbgcop.mcmc
> ### Title: Semiparametric Bayesian Gaussian copula estimation and
> ###   imputation
> ### Aliases: sbgcop.mcmc plot.psgc summary.psgc print.sum.psgc
> ### Keywords: multivariate models
> 
> ### ** Examples
> 
> fit<-sbgcop.mcmc(swiss)
10 percent done  Thu Oct 14 22:51:27 2010 
20 percent done  Thu Oct 14 22:51:27 2010 
30 percent done  Thu Oct 14 22:51:28 2010 
40 percent done  Thu Oct 14 22:51:28 2010 
50 percent done  Thu Oct 14 22:51:28 2010 
60 percent done  Thu Oct 14 22:51:28 2010 
70 percent done  Thu Oct 14 22:51:29 2010 
80 percent done  Thu Oct 14 22:51:29 2010 
90 percent done  Thu Oct 14 22:51:29 2010 
100 percent done  Thu Oct 14 22:51:29 2010 
> summary(fit)

 #### MCMC details         #### 

 number of saved samples: 100 

 average effective sample size: 94.51049 

 effective sample sizes 
       Fertility*Agriculture        Fertility*Examination 
                      126.70                       158.88 
         Fertility*Education           Fertility*Catholic 
                      106.27                        74.17 
  Fertility*Infant.Mortality      Agriculture*Examination 
                      114.38                        75.09 
       Agriculture*Education         Agriculture*Catholic 
                       81.68                        69.64 
Agriculture*Infant.Mortality        Examination*Education 
                       75.75                        41.05 
        Examination*Catholic Examination*Infant.Mortality 
                       80.47                       137.03 
          Education*Catholic   Education*Infant.Mortality 
                      129.33                        79.29 
   Catholic*Infant.Mortality 
                       67.93 

 #### Parameter estimation #### 
 Posterior quantiles of correlation coefficients: 
                             2.5% quantile 50% quantile 97.5% quantile
Fertility*Agriculture                 0.05         0.27           0.50
Fertility*Examination                -0.74        -0.58          -0.39
Fertility*Education                  -0.63        -0.44          -0.20
Fertility*Catholic                    0.13         0.32           0.57
Fertility*Infant.Mortality            0.17         0.38           0.56
Agriculture*Examination              -0.73        -0.60          -0.42
Agriculture*Education                -0.73        -0.60          -0.42
Agriculture*Catholic                  0.10         0.35           0.58
Agriculture*Infant.Mortality         -0.37        -0.11           0.16
Examination*Education                 0.47         0.63           0.78
Examination*Catholic                 -0.59        -0.41          -0.18
Examination*Infant.Mortality         -0.25         0.02           0.22
Education*Catholic                   -0.39        -0.14           0.11
Education*Infant.Mortality           -0.29         0.00           0.20
Catholic*Infant.Mortality            -0.15         0.08           0.33

 Posterior quantiles of regression coefficients: 
                             2.5% quantile 50% quantile 97.5% quantile
Fertility~Agriculture                -0.41        -0.11           0.19
Fertility~Examination                -0.73        -0.50          -0.27
Fertility~Education                  -0.46        -0.17           0.09
Fertility~Catholic                   -0.10         0.12           0.36
Fertility~Infant.Mortality            0.18         0.35           0.54
Agriculture~Fertility                -0.36        -0.13           0.20
Agriculture~Examination              -0.52        -0.30          -0.03
Agriculture~Education                -0.63        -0.44          -0.21
Agriculture~Catholic                 -0.03         0.21           0.45
Agriculture~Infant.Mortality         -0.31        -0.10           0.12
Examination~Fertility                -0.59        -0.38          -0.17
Examination~Agriculture              -0.44        -0.22          -0.03
Examination~Education                 0.11         0.30           0.53
Examination~Catholic                 -0.34        -0.20          -0.02
Examination~Infant.Mortality         -0.05         0.16           0.37
Education~Fertility                  -0.38        -0.17           0.07
Education~Agriculture                -0.62        -0.41          -0.20
Education~Examination                 0.17         0.38           0.65
Education~Catholic                    0.03         0.24           0.43
Education~Infant.Mortality           -0.25        -0.04           0.13
Catholic~Fertility                   -0.13         0.18           0.48
Catholic~Agriculture                 -0.04         0.34           0.66
Catholic~Examination                 -0.72        -0.37          -0.04
Catholic~Education                    0.05         0.36           0.69
Catholic~Infant.Mortality            -0.21         0.09           0.35
Infant.Mortality~Fertility            0.27         0.52           0.77
Infant.Mortality~Agriculture         -0.46        -0.17           0.19
Infant.Mortality~Examination         -0.10         0.32           0.66
Infant.Mortality~Education           -0.44        -0.07           0.25
Infant.Mortality~Catholic            -0.17         0.10           0.37
> plot(fit)
> 
> 
> 
> 
> dev.off()
null device 
          1 
> 
> 

Image(s)

No comments:

Post a Comment

Thank you