Title: | Semiparametric Factor and Regression Models for Symmetric Relational Data |
---|---|
Description: | Estimation of the parameters in a model for symmetric relational data (e.g., the above-diagonal part of a square matrix), using a model-based eigenvalue decomposition and regression. Missing data is accommodated, and a posterior mean for missing data is calculated under the assumption that the data are missing at random. The marginal distribution of the relational data can be arbitrary, and is fit with an ordered probit specification. See Hoff (2007) <arXiv:0711.1146> for details on the model. |
Authors: | Peter Hoff |
Maintainer: | Peter Hoff <[email protected]> |
License: | GPL-2 |
Version: | 1.11 |
Built: | 2024-10-31 21:06:56 UTC |
Source: | https://github.com/cran/eigenmodel |
Estimation of the parameters in a model for symmetric relational data (e.g., the above-diagonal part of a square matrix), using a model-based eigenvalue decomposition and regression. Missing data is accomodated, and a posterior mean for missing data is calculated under the assumption that the data are missing at random. The marginal distribution of the relational data can be arbitrary, and is fit with an ordered probit specification. See Hoff (2007) <arXiv:0711.1146> for details on the model.
Package: | eigenmodel |
Type: | Package |
Version: | 1.11 |
Date: | 2019-05-28 |
License: | GPL Version 2 |
Peter Hoff <[email protected]>
Hoff (2007) “Modeling homophily and stochastic equivalence in symmetric relational data”
data(YX_Friend) fit<-eigenmodel_mcmc(Y=YX_Friend$Y,X=YX_Friend$X,R=2,S=50,burn=50) # in general you should run the Markov chain longer than 50 scans plot(fit) # people familiar with MCMC might want to implement # their own Markov chains: Y<-YX_Friend$Y X<-YX_Friend$X eigenmodel_setup(R=2) for(s in 1:50) { # you should run your chain longer than 50 scans Z<-rZ_fc() UL<-rUL_fc() b<-rb_fc() } #fit_Gen<-eigenmodel_mcmc(Y=Y_Gen,R=3,S=10000) #fit_Pro<-eigenmodel_mcmc(Y=Y_Pro,R=3,S=10000)
data(YX_Friend) fit<-eigenmodel_mcmc(Y=YX_Friend$Y,X=YX_Friend$X,R=2,S=50,burn=50) # in general you should run the Markov chain longer than 50 scans plot(fit) # people familiar with MCMC might want to implement # their own Markov chains: Y<-YX_Friend$Y X<-YX_Friend$X eigenmodel_setup(R=2) for(s in 1:50) { # you should run your chain longer than 50 scans Z<-rZ_fc() UL<-rUL_fc() b<-rb_fc() } #fit_Gen<-eigenmodel_mcmc(Y=Y_Gen,R=3,S=10000) #fit_Pro<-eigenmodel_mcmc(Y=Y_Pro,R=3,S=10000)
Adds lines between nodes to an existing plot of nodes
addlines(U, Y, col = "green", lwd = 1, lty = 1)
addlines(U, Y, col = "green", lwd = 1, lty = 1)
U |
an n x 2 matrix of node locations |
Y |
a symmetric matrix |
col |
color of the lines |
lwd |
width of the lines |
lty |
line type |
Peter Hoff
Construct approximate samples from the posterior distribution of the parameters and latent variables in an eigenmodel for symmetric relational data.
eigenmodel_mcmc(Y, X = NULL, R = 2, S = 1000, seed = 1, Nss = min(S, 1000), burn = 100)
eigenmodel_mcmc(Y, X = NULL, R = 2, S = 1000, seed = 1, Nss = min(S, 1000), burn = 100)
Y |
an n x n symmetric matrix with missing diagonal entries. Off-diagonal missing values are allowed. |
X |
an n x n x p array of regressors |
R |
the rank of the approximating factor matrix |
S |
number of samples from the Markov chain |
seed |
a random seed |
Nss |
number of samples to be saved |
burn |
number of initial scans of the Markov chain to be dropped |
a list with the following components:
Z_postmean |
posterior mean of the latent variable in the probit specification |
ULU_postmean |
posterior mean of the reduced-rank approximating matrix |
Y_postmean |
the original data matrix with missing values replaced by posterior means |
L_postsamp |
samples of the eigenvalues |
b_postsamp |
samples of the regression coefficients |
Y |
original data matrix |
X |
original regressor array |
S |
number of scans of the Markov chain |
Peter Hoff
data(YX_Friend) fit<-eigenmodel_mcmc(Y=YX_Friend$Y,X=YX_Friend$X,R=2,S=50,burn=50) # in general you should run the Markov chain longer than 50 scans plot(fit) #fit<-eigenmodel_mcmc(Y=Y_Gen,R=3,S=10000) #fit<-eigenmodel_mcmc(Y=Y_Pro,R=3,S=10000)
data(YX_Friend) fit<-eigenmodel_mcmc(Y=YX_Friend$Y,X=YX_Friend$X,R=2,S=50,burn=50) # in general you should run the Markov chain longer than 50 scans plot(fit) #fit<-eigenmodel_mcmc(Y=Y_Gen,R=3,S=10000) #fit<-eigenmodel_mcmc(Y=Y_Pro,R=3,S=10000)
Setup constants and starting values for an eigenmodel fit
eigenmodel_setup(R = 0, seed = 1, em_env = .GlobalEnv)
eigenmodel_setup(R = 0, seed = 1, em_env = .GlobalEnv)
R |
non-negative integer rank of the approximating matrix |
seed |
a random seed |
em_env |
enviromnemt within which to do the fitting |
Peter Hoff
A graphical display of MCMC output and posterior estimates of model parameters in an eigenmodel fit. Includes 95 percent quantile-based posterior confidence intervals of regression coefficients.
## S3 method for class 'eigenmodel_post' plot(x, ...)
## S3 method for class 'eigenmodel_post' plot(x, ...)
x |
an object of class |
... |
additional plotting options |
Peter Hoff
Sample from the full conditional distribution of the regression coefficients in an eigenmodel
rb_fc(E = Z - ULU(UL))
rb_fc(E = Z - ULU(UL))
E |
a symmetric matrix |
a p x 1 vector
Peter Hoff
Sample from the multivariate normal distribution
rmvnorm(mu, Sig2)
rmvnorm(mu, Sig2)
mu |
a p x 1 vector |
Sig2 |
a p x p positive definite matrix |
a p x 1 vector
Peter Hoff
rmvnorm( c(0,0,0),diag(rep(3,1)) )
rmvnorm( c(0,0,0),diag(rep(3,1)) )
Samples the components of a reduced rank approximating matrix from their full conditional distributions
rUL_fc(E = Z - XB(X, b))
rUL_fc(E = Z - XB(X, b))
E |
an n x n symmetric matrix to be modeled with a reduced rank matrix |
A list with the following components:
U |
an n x r matrix of eigenvectors |
L |
an r x r diagonal matrix of eigenvalues |
Peter Hoff
Sample from the full conditional distribution of the latent variables in the ordered probit model
rZ_fc(EZ = XB(X, b) + ULU(UL), MH = TRUE)
rZ_fc(EZ = XB(X, b) + ULU(UL), MH = TRUE)
EZ |
a symmetric matrix with elements equal to the expected values of the latent variables |
MH |
whether or not to do a Metropolis update in addition to the Gibbs sampling |
a symmetric matrix
Peter Hoff
Computes a matrix from its eigenvalue decomposition
ULU(UL)
ULU(UL)
UL |
a list with first component “U”, an n x r matrix and the second component “L” an r x r diagonal matrix |
an n x n matrix
Peter Hoff
Computes a sociomatrix of regression effects
XB(X, b)
XB(X, b)
X |
an n x n x p array |
b |
a p x 1 vector |
an n x n matrix
Peter Hoff
The i,j th entry of this matrix is the numerical count of the number of times word i was next to word j in the first chapter of Genesis.
data(Y_Gen)
data(Y_Gen)
Impute missing values of a sociomatrix
Y_impute()
Y_impute()
Imputes missing values of a sociomatrix from a matrix of latent variables and an ordered-probit specification.
symmetric matrix
Peter Hoff
Butland's protein-protein interaction data
Butland et al (2005) “Interaction network containing conserved and essential protein complexes in Escherichia coli”
data(Y_Pro)
data(Y_Pro)
A list in which Y
encodes the presence of a friendship tie between 90
12th graders. The array X
indicates pairs of the same sex and of the
same race.
http://www.cpc.unc.edu/projects/addhealth/design
data(YX_Friend)
data(YX_Friend)