Learn R Programming

ocomposition (version 1.1)

fitcomp: Gibbs sampler for parameter estimation

Description

The main regression function for compositional rank-index data. For units $i = 1, ..., n$, the response variable is vector $(y_{i1}, ..., y_{in})$, where $\sum_j y_{ij} = 1$ and $y_{i1} \geq y_{i2} \geq ... \geq y_{in}$ for all $i$ and $y_{ij} \in [0, 1]$ for all $i$ and $j$. The regression model has two parts: a truncated negative binomial model for the count of non-zero components and a set of seemingly unrelated t regressions for the compositions. See References for further details.

Usage

fitcomp(data.v, data.x, n.formula, v.formula, l.bound = 1, n.sample = 100, burn = 0, thin = 1, init = NULL)

Arguments

data.v
Matrix of compositional data: rows for units and columns for components. Rows must add up to 1; if not, they are automatically rescaled. NA values turned into 0 automatically. Ordering done automatically.
data.x
Data frame with covariates, missing values not allowed.
n.formula
formula for the number of components: e.g., ~ x1 + x2 + factor(z).
v.formula
formula for the size of components: e.g., ~ x1 + x2.
l.bound
lower bound for the negative binomial regression; must be greater or equal to 1; default = 1.
n.sample
number of samples you want to have after burn-in and thinning; default 100
burn
number of burn-in samples; default 0
thin
thinning of the MCMC chain; default 1
init
initial parameters; not required

Value

g
samples of gamma coefficients for the multivariate regression model
b
posterior samples of the coefficients for the negative binomial regression
mu
hyperparameters for gamma coefficients
rho
shrinkage hyperparameters for gamma coefficients
Sigma
posterior samples of the covariance matrix
nu
degrees of freedom for the Student's t distribution

References

Rozenas, Arturas (2012) 'A Statistical Model for Party Systems Analysis', Political Analysis, 2(20), p.235-247.

Examples

Run this code
	
data(data)	
out <- fitcomp(data$v, data$m, ~ log(m), ~ log(m) + log(n), n.sample = 50)
summary(out)

# predict distribution of votes in a country with 5-member median district

v.hat <- predict(out, data.frame(m=5)) 
plot(v.hat)		

Run the code above in your browser using DataLab