Title: | Additive and Multiplicative Effects Models for Networks and Relational Data |
---|---|
Description: | Analysis of dyadic network and relational data using additive and multiplicative effects (AME) models. The basic model includes regression terms, the covariance structure of the social relations model (Warner, Kenny and Stoto (1979) <DOI:10.1037/0022-3514.37.10.1742>, Wong (1982) <DOI:10.2307/2287296>), and multiplicative factor models (Hoff(2009) <DOI:10.1007/s10588-008-9040-4>). Several different link functions accommodate different relational data structures, including binary/network data, normal relational data, zero-inflated positive outcomes using a tobit model, ordinal relational data and data from fixed-rank nomination schemes. Several of these link functions are discussed in Hoff, Fosdick, Volfovsky and Stovel (2013) <DOI:10.1017/nws.2013.17>. Development of this software was supported in part by NIH grant R01HD067509. |
Authors: | Peter Hoff [aut, cre], Bailey Fosdick [aut], Alex Volfovsky [aut], Yanjun He [ctb] |
Maintainer: | Peter Hoff <[email protected]> |
License: | GPL-3 |
Version: | 1.4.4 |
Built: | 2025-02-07 05:41:54 UTC |
Source: | https://github.com/pdhoff/amen |
Analysis of network and relational data using additive and multiplicative effects (AME) models. The basic model includes regression terms, the covariance structure of the social relations model (Warner, Kenny and Stoto (1979), Wong (1982)), and multiplicative factor effects (Hoff(2009)). Four different link functions accommodate different relational data structures, including binary/network data (bin), normal relational data (nrm), ordinal relational data (ord) and data from fixed-rank nomination schemes (frn). Several of these link functions are discussed in Hoff, Fosdick, Volfovsky and Stovel (2013). Development of this software was supported in part by NICHD grant R01HD067509.
Package: | amen |
Type: | Package |
Version: | 1.4.4 |
Date: | 2020-12-01 |
License: | GPL-3 |
Peter Hoff, Bailey Fosdick, Alex Volfovsky, Yanjun He
Maintainer: Peter Hoff <[email protected]>
data(YX_frn) fit<-ame(YX_frn$Y,YX_frn$X,burn=5,nscan=5,odens=1,family="frn") summary(fit) plot(fit)
data(YX_frn) fit<-ame(YX_frn$Y,YX_frn$X,burn=5,nscan=5,odens=1,family="frn") summary(fit) plot(fit)
A valued sociomatrix (Y) and matrix of nodal attributes (X) for students in community 3 of the AddHealth study.
Y: A sociomatrix in which the value of the edge corresponds to an ad-hoc measure of intensity of the relation. Note that students were only allowed to nominate up to 5 male friends and 5 female friends.
X: Matrix of students attributes, including sex, race (1=white, 2=black, 3=hispanic, 4=asian, 5=mixed/other) and grade.
data(addhealthc3)
data(addhealthc3)
list
A valued sociomatrix (Y) and matrix of nodal attributes (X) for students in community 9 of the AddHealth study.
Y: A sociomatrix in which the value of the edge corresponds to an ad-hoc measure of intensity of the relation. Note that students were only allowed to nominate up to 5 male friends and 5 female friends.
X: Matrix of students attributes, including sex, race (1=white, 2=black, 3=hispanic, 4=asian, 5=mixed/other) and grade.
data(addhealthc9)
data(addhealthc9)
list
Add lines to a network plot
addlines(Y,X,col="lightblue",alength=0,...)
addlines(Y,X,col="lightblue",alength=0,...)
Y |
a sociomatrix |
X |
coordinates of nodes |
col |
color of lines. Can be a vector of length equal to the number of edges to be drawn |
alength |
length of arrows to be drawn |
... |
additional plotting parameters |
Peter Hoff
data(addhealthc3) Y<-addhealthc3$Y X<-xnet(Y) netplot(Y,X) addlines(Y,X,col=Y[Y!=0])
data(addhealthc3) Y<-addhealthc3$Y X<-xnet(Y) netplot(Y,X) addlines(Y,X,col=Y[Y!=0])
An MCMC routine providing a fit to an additive and multiplicative effects (AME) regression model to relational data of various types
ame(Y, Xdyad=NULL, Xrow=NULL, Xcol=NULL, family, R=0, rvar = !(family=="rrl") , cvar = TRUE, dcor = !symmetric, nvar=TRUE, intercept=!is.element(family,c("rrl","ord")), symmetric=FALSE, odmax=rep(max(apply(Y>0,1,sum,na.rm=TRUE)),nrow(Y)), seed = 1, nscan = 10000, burn = 500, odens = 25, plot=TRUE, print = TRUE, gof=TRUE, prior=list())
ame(Y, Xdyad=NULL, Xrow=NULL, Xcol=NULL, family, R=0, rvar = !(family=="rrl") , cvar = TRUE, dcor = !symmetric, nvar=TRUE, intercept=!is.element(family,c("rrl","ord")), symmetric=FALSE, odmax=rep(max(apply(Y>0,1,sum,na.rm=TRUE)),nrow(Y)), seed = 1, nscan = 10000, burn = 500, odens = 25, plot=TRUE, print = TRUE, gof=TRUE, prior=list())
Y |
an n x n square relational matrix of relations. See family below for various data types. |
Xdyad |
an n x n x pd array of covariates |
Xrow |
an n x pr matrix of nodal row covariates |
Xcol |
an n x pc matrix of nodal column covariates |
family |
character: one of "nrm","tob","bin","ord","cbin","frn","rrl" - see the details below |
R |
integer: dimension of the multiplicative effects (can be zero) |
rvar |
logical: fit row random effects (asymmetric case)? |
cvar |
logical: fit column random effects (asymmetric case)? |
dcor |
logical: fit a dyadic correlation (asymmetric case)? |
nvar |
logical: fit nodal random effects (symmetric case)? |
intercept |
logical: fit model with an intercept? |
symmetric |
logical: Is the sociomatrix symmetric by design? |
odmax |
a scalar integer or vector of length n giving the maximum number of nominations that each node may make - used for "frn" and "cbin" families |
seed |
random seed |
nscan |
number of iterations of the Markov chain (beyond burn-in) |
burn |
burn in for the Markov chain |
odens |
output density for the Markov chain |
plot |
logical: plot results while running? |
print |
logical: print results while running? |
gof |
logical: calculate goodness of fit statistics? |
prior |
list: A list of hyperparameters for the prior distribution |
This command provides posterior inference for parameters in AME models of relational data, assuming one of six possible data types/models:
"nrm": A normal AME model.
"tob": A tobit AME model.
"bin": A binary probit AME model.
"ord": An ordinal probit AME model. An intercept is not identifiable in this model.
"cbin": An AME model for censored binary data. The value of 'odmax' specifies the maximum number of links each row may have.
"frn": An AME model for fixed rank nomination networks. A higher value of the rank indicates a stronger relationship. The value of 'odmax' specifies the maximum number of links each row may have.
"rrl": An AME model based on the row ranks. This is appropriate if the relationships across rows are not directly comparable in terms of scale. An intercept, row random effects and row regression effects are not estimable for this model.
BETA |
posterior samples of regression coefficients |
VC |
posterior samples of the variance parameters |
APM |
posterior mean of additive row effects a |
BPM |
posterior mean of additive column effects b |
U |
posterior mean of multiplicative row effects u |
V |
posterior mean of multiplicative column effects v (asymmetric case) |
UVPM |
posterior mean of UV (asymmetric case) |
ULUPM |
posterior mean of ULU (symmetric case) |
L |
posterior mean of L (symmetric case) |
EZ |
estimate of expectation of Z matrix |
YPM |
posterior mean of Y (for imputing missing values) |
GOF |
observed (first row) and posterior predictive (remaining rows) values of four goodness-of-fit statistics |
Peter Hoff
data(YX_frn) fit<-ame(YX_frn$Y,YX_frn$X,burn=5,nscan=5,odens=1,family="frn") # you should run the Markov chain much longer than this
data(YX_frn) fit<-ame(YX_frn$Y,YX_frn$X,burn=5,nscan=5,odens=1,family="frn") # you should run the Markov chain much longer than this
An MCMC routine providing a fit to an additive and multiplicative effects (AME) regression model to replicated relational data of various types.
ame_rep(Y,Xdyad=NULL, Xrow=NULL, Xcol=NULL, family, R=0, rvar = !(family=="rrl"), cvar = TRUE, dcor = !symmetric, nvar=TRUE, intercept=!is.element(family,c("rrl","ord")), symmetric=FALSE, odmax=rep(max(apply(Y>0,c(1,3),sum,na.rm=TRUE)),nrow(Y[,,1])), seed = 1, nscan = 10000, burn = 500, odens = 25, plot=TRUE, print = TRUE, gof=TRUE)
ame_rep(Y,Xdyad=NULL, Xrow=NULL, Xcol=NULL, family, R=0, rvar = !(family=="rrl"), cvar = TRUE, dcor = !symmetric, nvar=TRUE, intercept=!is.element(family,c("rrl","ord")), symmetric=FALSE, odmax=rep(max(apply(Y>0,c(1,3),sum,na.rm=TRUE)),nrow(Y[,,1])), seed = 1, nscan = 10000, burn = 500, odens = 25, plot=TRUE, print = TRUE, gof=TRUE)
Y |
an n x n x T array of relational matrix, where the third dimension correponds to replicates (over time, for example). See family below for various data types. |
Xdyad |
an n x n x pd x T array of covariates |
Xrow |
an n x pr x T array of nodal row covariates |
Xcol |
an n x pc x T array of nodal column covariates |
family |
character: one of "nrm","bin","ord","cbin","frn","rrl" - see the details below |
R |
integer: dimension of the multiplicative effects (can be zero) |
rvar |
logical: fit row random effects (asymmetric case)? |
cvar |
logical: fit column random effects (asymmetric case)? |
dcor |
logical: fit a dyadic correlation (asymmetric case)? |
nvar |
logical: fit nodal random effects (symmetric case)? |
intercept |
logical: fit model with an intercept? |
symmetric |
logical: Is the sociomatrix symmetric by design? |
odmax |
a scalar integer or vector of length n giving the maximum number of nominations that each node may make - used for "frn" and "cbin" families |
seed |
random seed |
nscan |
number of iterations of the Markov chain (beyond burn-in) |
burn |
burn in for the Markov chain |
odens |
output density for the Markov chain |
plot |
logical: plot results while running? |
print |
logical: print results while running? |
gof |
logical: calculate goodness of fit statistics? |
This command provides posterior inference for parameters in AME models of independent replicated relational data, assuming one of six possible data types/models:
"nrm": A normal AME model.
"bin": A binary probit AME model.
"ord": An ordinal probit AME model. An intercept is not identifiable in this model.
"cbin": An AME model for censored binary data. The value of 'odmax' specifies the maximum number of links each row may have.
"frn": An AME model for fixed rank nomination networks. A higher value of the rank indicates a stronger relationship. The value of 'odmax' specifies the maximum number of links each row may have.
"rrl": An AME model based on the row ranks. This is appropriate if the relationships across rows are not directly comparable in terms of scale. An intercept, row random effects and row regression effects are not estimable for this model.
BETA |
posterior samples of regression coefficients |
VC |
posterior samples of the variance parameters |
APM |
posterior mean of additive row effects a |
BPM |
posterior mean of additive column effects b |
U |
posterior mean of multiplicative row effects u |
V |
posterior mean of multiplicative column effects v (asymmetric case) |
UVPM |
posterior mean of UV |
ULUPM |
posterior mean of ULU (symmetric case) |
L |
posterior mean of L (symmetric case) |
EZ |
estimate of expectation of Z matrix |
YPM |
posterior mean of Y (for imputing missing values) |
GOF |
observed (first row) and posterior predictive (remaining rows) values of four goodness-of-fit statistics |
Peter Hoff, Yanjun He
data(YX_bin_long) fit<-ame_rep(YX_bin_long$Y,YX_bin_long$X,burn=5,nscan=5,odens=1,family="bin") # you should run the Markov chain much longer than this
data(YX_bin_long) fit<-ame_rep(YX_bin_long$Y,YX_bin_long$X,burn=5,nscan=5,odens=1,family="bin") # you should run the Markov chain much longer than this
Produce a circular network plot.
circplot( Y, U = NULL, V = NULL, row.names = rownames(Y), col.names = colnames(Y), plotnames = TRUE, vscale = 0.8, pscale = 1.75, mscale = 0.3, lcol = "gray", rcol = "brown", ccol = "blue", pch = 16, lty = 3, jitter = 0.1 * (nrow(Y)/(1 + nrow(Y))), bty = "n", add = FALSE )
circplot( Y, U = NULL, V = NULL, row.names = rownames(Y), col.names = colnames(Y), plotnames = TRUE, vscale = 0.8, pscale = 1.75, mscale = 0.3, lcol = "gray", rcol = "brown", ccol = "blue", pch = 16, lty = 3, jitter = 0.1 * (nrow(Y)/(1 + nrow(Y))), bty = "n", add = FALSE )
Y |
(matrix) m by n relational matrix. |
U |
(matrix) m by 2 matrix of row factors of Y. |
V |
(matrix) n by 2 matrix of column factors of Y. |
row.names |
(character vector) names of the row objects. |
col.names |
(character vector) names of the columns objects. |
plotnames |
(logical) plot row and column names. |
vscale |
(scalar) scaling factor for V coordinates. |
pscale |
(scalar) scaling factor for plotting characters. |
mscale |
(scalar) scaling factor for plotting characters. |
lcol |
(scalar or vector) line color(s) for the nonzero elements of Y. |
rcol |
(scalar or vector) node color(s) for the rows. |
ccol |
(scalar or vector) node color(s) for the columns. |
pch |
(integer) plotting character. |
lty |
(integer) line type. |
jitter |
(scalar) a number to control jittering of nodes. |
bty |
(character) bounding box type. |
add |
(logical) add to existing plot |
This function creates a circle plot of a relational matrix or social network.
If not supplied via U
and V
, two-dimensional row factors and
column factors are computed from the SVD of Y
, scaled versions of
which are used to plot positions on the outside edge (U
) and inside
edge (V
) of the circle plot. The magnitudes of the plotting characters
are determined by the magnitudes of the rows of U
and V
.
Segments are drawn between each row object i
and column object
j
for which Y[i,j]!=0
.
Peter Hoff
data(IR90s) circplot(IR90s$dyadvars[,,1])
data(IR90s) circplot(IR90s$dyadvars[,,1])
Positive and negative relations between countries during the cold war
A list including the following dyadic and nodal variables:
cc
: a socioarray of ordinal levels of military
cooperation (positive) and conflict (negative), every 5 years;
distance
: between-country distance (in thousands of kilometers);
gdp
: country gdp in dollars every 5 years;
polity
: country polity every 5 years.
Xun Cao : https://polisci.la.psu.edu/people/xuc11
Eleven years of import and export data between 229 countries. The data use the SITC Rev. 1 commodity classification, aggregated at the first level (AG1).
A list consisting of a socioarray Trade
and a vector
dollars2010
of inflation rates. The socioarray gives
yearly trade volume (exports and imports)
in dollars for 10 different commodity classes
for eleven years between 229 countries. This gives a five-way
array. The first index is the reporting country, so
Trade[i,j,t,k,1]
is what i
reports for exports to
j
, but in general this is not the same as
Trade[j,i,t,k,2]
, what j
reports as importing from i
.
https://comtrade.un.org/, https://www.measuringworth.com/
Computes the design socioarray of covariate values for an AME fit
design_array(Xrow=NULL,Xcol=NULL,Xdyad=NULL,intercept=TRUE,n)
design_array(Xrow=NULL,Xcol=NULL,Xdyad=NULL,intercept=TRUE,n)
Xrow |
an n x pr matrix of row covariates |
Xcol |
an n x pc matrix of column covariates |
Xdyad |
an n x n x pd array of dyadic covariates |
intercept |
logical |
n |
number of rows/columns |
an n x n x (pr+pc+pd+intercept) 3-way array
Peter Hoff
Longitudinal relational measurements and nodal characteristics of Dutch college students, described in van de Bunt, van Duijn, and Snijders (1999). The time interval between the first four measurements was three weeks, whereas the interval between the last three was six weeks.
A list consisting of a socioarray Y
and a matrix
X
of static nodal attributes. The relational
measurements range from -1 to 4, indicating the following:
-1 a troubled or negative relationship
0 don't know
1 neutral relationship
2 friendly
3 friendship
4 best friends
Linton Freeman
Construction of a sociomatrix from an edgelist
el2sm(el,directed=TRUE,nadiag=all(el[,1]!=el[,2]))
el2sm(el,directed=TRUE,nadiag=all(el[,1]!=el[,2]))
el |
a matrix in which each row contains the indices of an edge and possibly the weight for the edge |
directed |
if FALSE, then a relation is placed in both entry ij and ji of the sociomatrix, for each edge ij (or ji) |
nadiag |
put NAs on the diagonal |
a sociomatrix
Peter Hoff
Y<-matrix(rpois(10*10,.5),10,10) ; diag(Y)<-NA E<-sm2el(Y) el2sm(E) - Y
Y<-matrix(rpois(10*10,.5),10,10) ; diag(Y)<-NA E<-sm2el(Y) el2sm(E) - Y
Goodness of fit statistics evaluating second and third-order dependence patterns
gofstats(Y)
gofstats(Y)
Y |
a relational data matrix |
a vector of gof statistics
Peter Hoff
data(YX_nrm) gofstats(YX_nrm$Y)
data(YX_nrm) gofstats(YX_nrm$Y)
A relational dataset recording a variety of nodal and dyadic variables on countries in the 1990s, including information on conflicts, trade and other variables. Except for the conflict variable, the variables are averages across the decade.
A list consisting of a socioarray dyadvars
of
dyadic variables and matrix nodevars
of nodal variables.
The dyadic variables include
total number of conflicts;
exports (in billions of dollars);
distance (in thousands of kilometers);
number of shared IGOs (averages across the years);
polity interaction.
The nodal variables include
population (in millions);
gdp (in billions of dollars);
polity
Michael Ward.
Several nodal and dyadic variables measured on 71 attorneys in a law firm.
A list consisting of a socioarray Y
and a nodal attribute matrix X
.
The dyadic variables in Y
include three binary networks: advice, friendship
and co-worker status.
The categorical nodal attributes in X
are coded as follows:
status (1=partner, 2=associate)
office (1=Boston, 2=Hartford, 3=Providence)
practice (1=litigation, 2=corporate)
law school (1=Harvard or Yale, 2=UConn, 3=other)
seniority
and age
are given in years, and female
is
a binary indicator.
Linton Freeman
Calculation of the log conditional density of the
latent AMEN matrix Z
given observed data Y
.
ldZgbme(Z, Y, llYZ, EZ, rho, s2 = 1)
ldZgbme(Z, Y, llYZ, EZ, rho, s2 = 1)
Z |
n X n latent relational matrix following an AMEN model |
Y |
n X n observed relational matrix |
llYZ |
a vectorizable function taking two arguments, y and z. See details below. |
EZ |
n X n mean matrix for |
rho |
dyadic correlation in AMEN model for |
s2 |
residual variance in AMEN model for |
This function is used for updating dyadic pairs of
the latent variable matrix Z
based on Y
and
an AMEN model for Z
. The function llYZ
specifies
the log likelihood for each single z[i,j]
based on
y[i,j]
, that is, llYZ
gives the log probability
density (or mass function) of y[i,j]
given z[i,j]
.
a symmetric matrix where entry i,j is proportional
to the log conditional bivariate density of z[i,j],z[j,i]
.
Peter Hoff
## For (overdispersed) Poisson regression, use llYZ<-function(y,z){ dpois(y,z,log=TRUE) }
## For (overdispersed) Poisson regression, use llYZ<-function(y,z){ dpois(y,z,log=TRUE) }
Calculation of the SRM log-likelihood over a grid of rho-values
llsrmRho(Y, Sab, rhos, s2 = 1)
llsrmRho(Y, Sab, rhos, s2 = 1)
Y |
sociomatrix assumed to follow a mean-zero SRM distribution |
Sab |
covariance matrix of additive effects |
rhos |
vector of rho-values at which to calculate the log-likelihood |
s2 |
current value of s2 |
a vector of log-likelihood values
Peter Hoff
Computes the symmetric square root of a positive definite matrix
mhalf(M)
mhalf(M)
M |
a positive definite matrix |
a matrix H
such that H^2
equals M
Peter Hoff
Plot the graph of a sociomatrix
netplot(Y,X=NULL,xaxt="n",yaxt="n",xlab="",ylab="", lcol="gray",ncol="black",lwd=1,lty=1,pch=16,bty="n",plotnames=FALSE, seed=1, plot.iso=TRUE,directed=NULL,add=FALSE,...)
netplot(Y,X=NULL,xaxt="n",yaxt="n",xlab="",ylab="", lcol="gray",ncol="black",lwd=1,lty=1,pch=16,bty="n",plotnames=FALSE, seed=1, plot.iso=TRUE,directed=NULL,add=FALSE,...)
Y |
a sociomatrix |
X |
coordinates for plotting the nodes |
xaxt |
x-axis type |
yaxt |
y-axis type |
xlab |
x-axis label |
ylab |
y-axis label |
lcol |
edge color |
ncol |
node color (can be node-specific) |
lwd |
line width |
lty |
line type |
pch |
plotting character for nodes (can be node-specific) |
bty |
bounding box type |
plotnames |
plot rownames of Y as node labels |
seed |
random seed |
plot.iso |
include isolates in plot |
directed |
draw arrows |
add |
add to an existing plot region |
... |
additional plotting parameters |
Peter Hoff
data(addhealthc3) Y<-addhealthc3$Y X<-xnet(Y) netplot(Y,X)
data(addhealthc3) Y<-addhealthc3$Y X<-xnet(Y) netplot(Y,X)
A set of plots summarizing the MCMC routine for an AME fit, as well as some posterior predictive checks.
## S3 method for class 'ame' plot(x, ...)
## S3 method for class 'ame' plot(x, ...)
x |
the result of fitting an AME model |
... |
additional parameters (not used) |
a series of plots
Peter Hoff
Computation of a variety of quantities from the design array to be used in MCMC model fitting algorithms.
precomputeX(X)
precomputeX(X)
X |
a three way array, the design array for an AME model |
the same three-way array but with derived quantities as attributes.
Peter Hoff
Simulate a and Sab from full conditional distributions under bin likelihood
raSab_bin_fc(Z, Y, a, b, Sab, Sab0=NULL, eta0=NULL, SS = round(sqrt(nrow(Z))))
raSab_bin_fc(Z, Y, a, b, Sab, Sab0=NULL, eta0=NULL, SS = round(sqrt(nrow(Z))))
Z |
a square matrix, the current value of Z |
Y |
square binary relational matrix |
a |
current value of row effects |
b |
current value of column effects |
Sab |
current value of Cov(a,b) |
Sab0 |
prior (inverse) scale matrix for the prior distribution |
eta0 |
prior degrees of freedom for the prior distribution |
SS |
number of iterations |
Z |
new value of Z |
Sab |
new value of Sab |
a |
new value of a |
Peter Hoff
Simulate a and Sab from full conditional distributions under the cbin likelihood
raSab_cbin_fc(Z, Y, a, b, Sab, odmax, odobs, Sab0=NULL, eta0=NULL,SS = round(sqrt(nrow(Z))))
raSab_cbin_fc(Z, Y, a, b, Sab, odmax, odobs, Sab0=NULL, eta0=NULL,SS = round(sqrt(nrow(Z))))
Z |
a square matrix, the current value of Z |
Y |
square matrix of ranked nomination data |
a |
current value of row effects |
b |
current value of column effects |
Sab |
current value of Cov(a,b) |
odmax |
a scalar or vector giving the maximum number of nominations for each individual |
odobs |
observed outdegree |
Sab0 |
prior (inverse) scale matrix for the prior distribution |
eta0 |
prior degrees of freedom for the prior distribution |
SS |
number of iterations |
Z |
new value of Z |
Sab |
new value of Sab |
a |
new value of a |
Peter Hoff
Simulate a and Sab from full conditional distributions under frn likelihood
raSab_frn_fc(Z, Y, YL, a, b, Sab, odmax, odobs, Sab0=NULL, eta0=NULL, SS=round(sqrt(nrow(Z))))
raSab_frn_fc(Z, Y, YL, a, b, Sab, odmax, odobs, Sab0=NULL, eta0=NULL, SS=round(sqrt(nrow(Z))))
Z |
a square matrix, the current value of Z |
Y |
square matrix of ranked nomination data |
YL |
list of ranked individuals, from least to most preferred in each row |
a |
current value of row effects |
b |
current value of column effects |
Sab |
current value of Cov(a,b) |
odmax |
a scalar or vector giving the maximum number of nominations for each individual |
odobs |
observed outdegree |
Sab0 |
prior (inverse) scale matrix for the prior distribution |
eta0 |
prior degrees of freedom for the prior distribution |
SS |
number of iterations |
Z |
new value of Z |
Sab |
new value of Sab |
a |
new value of a |
Peter Hoff
Simulates from the joint full conditional distribution of (beta,a,b) in a social relations regression model
rbeta_ab_fc( Z, Sab, rho, X = NULL, s2 = 1, offset = 0, iV0 = NULL, m0 = NULL, g = length(Z) )
rbeta_ab_fc( Z, Sab, rho, X = NULL, s2 = 1, offset = 0, iV0 = NULL, m0 = NULL, g = length(Z) )
Z |
n X n normal relational matrix |
Sab |
row and column covariance |
rho |
dyadic correlation |
X |
n x n x p covariate array |
s2 |
dyadic variance |
offset |
a matrix of the same dimension as Z. It is assumed that
Z-offset follows a SRRM, so the offset should contain any multiplicative
effects (such as |
iV0 |
prior precision matrix for regression parameters |
m0 |
prior mean vector for regression parameters |
g |
prior variance scale for g-prior when iV0 is unspecified |
beta |
regression coefficients |
a |
additive row effects |
b |
additive column effects |
Peter Hoff
Simulates from the joint full conditional distribution of (a,b,beta), assuming same additive row and column effects and regression coefficient across replicates.
rbeta_ab_rep_fc(Z.T,Sab,rho,X.T,s2=1)
rbeta_ab_rep_fc(Z.T,Sab,rho,X.T,s2=1)
Z.T |
n x n x T array, with the third dimension for replicates. Each slice of the array is a (latent) normal relational matrix, with multiplicative effects subtracted out |
Sab |
row and column covariance |
rho |
dyadic correlation |
X.T |
n x n x p x T covariate array |
s2 |
dyadic variance |
beta |
regression coefficients |
a |
additive row effects |
b |
additive column effects |
Peter Hoff, Yanjun He
Simulates a matrix where the rows are i.i.d. samples from a multivariate normal distribution
rmvnorm(n, mu, Sigma, Sigma.chol = chol(Sigma))
rmvnorm(n, mu, Sigma, Sigma.chol = chol(Sigma))
n |
sample size |
mu |
multivariate mean vector |
Sigma |
covariance matrix |
Sigma.chol |
Cholesky factorization of |
a matrix with n
rows
Peter Hoff
Simulation of dyadic correlation from its approximate full conditional distribution using griddy Gibbs sampling
rrho_fc(Z, Sab, s2 = 1, offset = 0, ngp = 100, asp = NULL)
rrho_fc(Z, Sab, s2 = 1, offset = 0, ngp = 100, asp = NULL)
Z |
n X n normal relational matrix |
Sab |
covariance of additive effects |
s2 |
residual variance |
offset |
matrix of the same dimension as Z. It is assumed that
Z-offset follows an SRM distribution, so the offset should contain any
regression terms and multiplicative effects (such as
|
ngp |
the number of points for an unevenly-spaced grid on which to approximate the full conditional distribution |
asp |
use arc sine prior (TRUE) or uniform prior (FALSE) |
a value of rho
Peter Hoff
Metropolis update for dyadic correlation
rrho_mh(Z, rho, s2 = 1,offset=0, asp=NULL)
rrho_mh(Z, rho, s2 = 1,offset=0, asp=NULL)
Z |
n X n normal relational matrix |
rho |
current value of rho |
s2 |
current value of s2 |
offset |
matrix of the same dimension as Z. It is assumed that
Z-offset is equal to dyadic noise, so the offset should contain any
additive and multiplicative effects (such as
|
asp |
use arc sine prior (TRUE) or uniform prior (FALSE) |
a new value of rho
Peter Hoff
Metropolis update for dyadic correlation with independent replicate data.
rrho_mh_rep(E.T, rho, s2 = 1)
rrho_mh_rep(E.T, rho, s2 = 1)
E.T |
Array of square residual relational matrix series. The third dimension of the array is for different replicates. Each slice of the array according to the third dimension is a square residual relational matrix. |
rho |
current value of rho |
s2 |
current value of s2 |
a new value of rho
Peter Hoff, Yanjun He
Gibbs update for dyadic variance
rs2_fc(Z, rho,offset=0,nu0=NULL,s20=NULL)
rs2_fc(Z, rho,offset=0,nu0=NULL,s20=NULL)
Z |
n X n normal relational matrix |
rho |
current value of rho |
offset |
matrix of the same dimension as Z. It is assumed that Z-offset
is equal to dyadic noise, so the offset should contain any additive and
multiplicative effects (such as |
nu0 |
prior degrees of freedom |
s20 |
prior estimate of s2 |
a new value of s2
Peter Hoff
Gibbs update for dyadic variance with independent replicate relational data
rs2_rep_fc(E.T, rho)
rs2_rep_fc(E.T, rho)
E.T |
Array of square residual relational matrix series. The third dimension of the array is for different replicates. Each slice of the array according to the third dimension is a square residual relational matrix |
rho |
current value of rho |
a new value of s2
Peter Hoff, Yanjun He
Gibbs update for additive effects covariance
rSab_fc(a,b,Sab0=NULL,eta0=NULL)
rSab_fc(a,b,Sab0=NULL,eta0=NULL)
a |
vector of row random effects |
b |
vector of row random effects |
Sab0 |
prior (inverse) scale matrix for the prior distribution |
eta0 |
prior degrees of freedom for the prior distribution |
Peter Hoff
Gibbs update for multiplicative effects covariance
rSuv_fc(U,V, Suv0=NULL,kappa0=NULL)
rSuv_fc(U,V, Suv0=NULL,kappa0=NULL)
U |
matrix of row random effects |
V |
matrix of row random effects |
Suv0 |
prior (inverse) scale matrix for the prior distribution |
kappa0 |
prior degrees of freedom for the prior distribution |
Peter Hoff
A Gibbs sampler for updating the multiplicative effect matrices U and V
rUV_fc(Z, U, V, Suv, rho, s2 = 1, offset = 0)
rUV_fc(Z, U, V, Suv, rho, s2 = 1, offset = 0)
Z |
n X n normal relational matrix |
U |
current value of U |
V |
current value of V |
Suv |
covariance of (U V) |
rho |
dyadic correlation |
s2 |
dyadic variance |
offset |
a matrix of the same dimension as Z. It is assumed that
Z-offset is equal to the multiplicative effects plus dyadic noise, so the
offset should contain any additive effects (such as |
U |
a new value of U |
V |
a new value of V |
Peter Hoff
A Gibbs sampler for updating the multiplicative effect matrices U and V, assuming they are the same across replicates.
rUV_rep_fc(E.T,U,V,rho,s2=1,shrink=TRUE)
rUV_rep_fc(E.T,U,V,rho,s2=1,shrink=TRUE)
E.T |
Array of square residual relational matrix series with additive effects and covariates subtracted out. The third dimension of the array is for different replicates. Each slice of the array according to the third dimension is a square residual relational matrix. |
U |
current value of U |
V |
current value of V |
rho |
dyadic correlation |
s2 |
dyadic variance |
shrink |
adaptively shrink the factors with a hierarchical prior |
U |
a new value of U |
V |
a new value of V |
Peter Hoff, Yanjun He
A Gibbs sampler for updating the multiplicative effect matrices U and V
in the symmetric case. In this case U%*%t(V)
is symmetric, so
this is parameterized as V=U%*%L
where L
is the
diagonal matrix of eigenvalues of U%*%t(V)
.
rUV_sym_fc(E, U, V, s2 = 1, shrink=TRUE)
rUV_sym_fc(E, U, V, s2 = 1, shrink=TRUE)
E |
square residual relational matrix |
U |
current value of U |
V |
current value of V |
s2 |
dyadic variance |
shrink |
adaptively shrink the factors with a hierarchical prior |
U |
a new value of U |
V |
a new value of V |
Peter Hoff
U0<-matrix(rnorm(30,2),30,2) ; V0<-U0%*%diag(c(3,-2)) E<- U0%*%t(V0) + matrix(rnorm(30^2),30,30) rUV_sym_fc
U0<-matrix(rnorm(30,2),30,2) ; V0<-U0%*%diag(c(3,-2)) E<- U0%*%t(V0) + matrix(rnorm(30^2),30,30) rUV_sym_fc
Simulates a random Wishart-distributed matrix
rwish(S0, nu = dim(S0)[1] + 2)
rwish(S0, nu = dim(S0)[1] + 2)
S0 |
a positive definite matrix |
nu |
a positive integer |
a positive definite matrix
Peter Hoff
## The expectation is S0*nu S0<-rwish(diag(3)) SS<-matrix(0,3,3) for(s in 1:1000) { SS<-SS+rwish(S0,5) } SS/s S0*5
## The expectation is S0*nu S0<-rwish(diag(3)) SS<-matrix(0,3,3) for(s in 1:1000) { SS<-SS+rwish(S0,5) } SS/s S0*5
Simulates a random latent matrix Z given its expectation, dyadic correlation and a binary relational matrix Y
rZ_bin_fc(Z, EZ, rho, Y)
rZ_bin_fc(Z, EZ, rho, Y)
Z |
a square matrix, the current value of Z |
EZ |
expected value of Z |
rho |
dyadic correlation |
Y |
square binary relational matrix |
a square matrix , the new value of Z
Peter Hoff
Simulates a random latent matrix Z given its expectation, dyadic correlation and censored binary nomination data
rZ_cbin_fc(Z, EZ, rho, Y, odmax, odobs)
rZ_cbin_fc(Z, EZ, rho, Y, odmax, odobs)
Z |
a square matrix, the current value of Z |
EZ |
expected value of Z |
rho |
dyadic correlation |
Y |
square matrix of ranked nomination data |
odmax |
a scalar or vector giving the maximum number of nominations for each individual |
odobs |
observed outdegree |
simulates Z under the constraints (1) Y[i,j]=1, Y[i,k]=0 => Z[i,j]>Z[i,k] , (2) Y[i,j]=1 => Z[i,j]>0 , (3) Y[i,j]=0 & odobs[i]<odmax[i] => Z[i,j]<0
a square matrix, the new value of Z
Peter Hoff
Simulates a random latent matrix Z given its expectation, dyadic correlation and fixed rank nomination data
rZ_frn_fc(Z, EZ, rho, Y, YL, odmax, odobs)
rZ_frn_fc(Z, EZ, rho, Y, YL, odmax, odobs)
Z |
a square matrix, the current value of Z |
EZ |
expected value of Z |
rho |
dyadic correlation |
Y |
square matrix of ranked nomination data |
YL |
list of ranked individuals, from least to most preferred in each row |
odmax |
a scalar or vector giving the maximum number of nominations for each individual |
odobs |
observed outdegree |
simulates Z under the constraints (1) Y[i,j]>Y[i,k] => Z[i,j]>Z[i,k] , (2) Y[i,j]>0 => Z[i,j]>0 , (3) Y[i,j]=0 & odobs[i]<odmax[i] => Z[i,j]<0
a square matrix, the new value of Z
Peter Hoff
Simulates missing values of a sociomatrix under a normal AME model
rZ_nrm_fc(Z, EZ, rho,s2, Y)
rZ_nrm_fc(Z, EZ, rho,s2, Y)
Z |
a square matrix, the current value of Z |
EZ |
expected value of Z |
rho |
dyadic correlation |
s2 |
dyadic variance |
Y |
square relational matrix |
a square matrix, equal to Y at non-missing values
Peter Hoff
Simulates a random latent matrix Z given its expectation, dyadic correlation and partial rank information provided by W
rZ_ord_fc(Z, EZ, rho, Y)
rZ_ord_fc(Z, EZ, rho, Y)
Z |
a square matrix, the current value of Z |
EZ |
expected value of Z |
rho |
dyadic correlation |
Y |
matrix of ordinal data |
a square matrix, the new value of Z
Peter Hoff
Simulates a random latent matrix Z given its expectation, dyadic correlation and relative rank nomination data
rZ_rrl_fc(Z, EZ, rho, Y, YL)
rZ_rrl_fc(Z, EZ, rho, Y, YL)
Z |
a square matrix, the current value of Z |
EZ |
expected value of Z |
rho |
dyadic correlation |
Y |
square matrix of ranked nomination data |
YL |
list of ranked individuals, from least to most preferred in each row |
simulates Z under the constraints (1) Y[i,j]>Y[i,k] => Z[i,j]>Z[i,k]
a square matrix, the new value of Z
Peter Hoff
Simulates a random latent matrix Z given its expectation, dyadic correlation and a nonnegative relational matrix Y
rZ_tob_fc(Z, EZ,rho,s2,Y)
rZ_tob_fc(Z, EZ,rho,s2,Y)
Z |
a square matrix, the current value of Z |
EZ |
expected value of Z |
rho |
dyadic correlation |
s2 |
dyadic variance |
Y |
square relational matrix with nonnegative entries |
a square matrix, the new value of Z
Peter Hoff
Several dyadic variables measured on 18 members of a monastery.
A socioarray whose dimensions represent nominators, nominatees and relations.
Each monk was asked to rank up to three other monks on a variety of positive
and negative relations. A rank of three indicates the "highest" ranking for
a particular relational variable. The relations like_m2
and like_m1
are evaluations of likeing at one and two timepoints previous to when the
other relations were measured.
Linton Freeman
Number of dominance encounters between 28 female bighorn sheep. Cell (i,j) records the number of times sheep i dominated sheep j. From Hass (1991).
A list consisting of the following:
dom
: a directed socioarray recording the number of
dominance encounters.
age
: the age of each sheep in years.
Linton Freeman
Simulates a network, i.e. a binary relational matrix
simY_bin(EZ, rho)
simY_bin(EZ, rho)
EZ |
square matrix giving the expected value of the latent Z matrix |
rho |
dyadic correlation |
a square binary matrix
Peter Hoff
Simulate an relational matrix based on a fixed rank nomination scheme
simY_frn(EZ, rho, odmax, YO)
simY_frn(EZ, rho, odmax, YO)
EZ |
a square matrix giving the expected value of the latent Z matrix |
rho |
dyadic correlation |
odmax |
a scalar or vector giving the maximum number of nominations for each node |
YO |
a square matrix identifying where missing values should be maintained |
a square matrix, where higher values represent stronger relationships
Peter Hoff
Simulates a normal relational matrix
simY_nrm(EY, rho, s2)
simY_nrm(EY, rho, s2)
EY |
square matrix giving the expected value of the relational matrix |
rho |
dyadic correlation |
s2 |
dyadic variance |
a square matrix
Peter Hoff
Simulates an ordinal relational matrix having a particular marginal distribution
simY_ord(EZ, rho, Y)
simY_ord(EZ, rho, Y)
EZ |
square matrix giving the expected value of the latent Z matrix |
rho |
scalar giving the within-dyad correlation |
Y |
ordinal relational data matrix |
a square matrix
Peter Hoff
Simulate an relational matrix based on a relative rank nomination scheme
simY_rrl(EZ, rho, odobs, YO)
simY_rrl(EZ, rho, odobs, YO)
EZ |
a square matrix giving the expected value of the latent Z matrix |
rho |
dyadic correlation |
odobs |
a scalar or vector giving the observed number of nominations for each node |
YO |
a square matrix identifying where missing values should be maintained |
a square matrix, where higher values represent stronger relationships
Peter Hoff
Simulates a tobit relational matrix
simY_tob(EY, rho, s2)
simY_tob(EY, rho, s2)
EY |
square matrix giving the expected value of the relational matrix |
rho |
dyadic correlation |
s2 |
dyadic variance |
a square matrix
Peter Hoff
Simulate Z given its expectation and covariance
simZ(EZ, rho, s2 = 1)
simZ(EZ, rho, s2 = 1)
EZ |
expected value of Z |
rho |
dyadic correlation |
s2 |
dyadic variance |
a simulated value of Z
Peter Hoff
Construction of an edgelist from a sociomatrix
sm2el(sm,directed=TRUE)
sm2el(sm,directed=TRUE)
sm |
a sociomatrix with possibly valued relations |
directed |
if TRUE, only use the upper triangular part of the matrix to enumerate edges |
an edglist
Peter Hoff
Y<-matrix(rpois(10*10,.5),10,10) ; diag(Y)<-NA E<-sm2el(Y) el2sm(E) - Y
Y<-matrix(rpois(10*10,.5),10,10) ; diag(Y)<-NA E<-sm2el(Y) el2sm(E) - Y
Summary method for an AME object
## S3 method for class 'ame' summary(object, ...)
## S3 method for class 'ame' summary(object, ...)
object |
the result of fitting an AME model |
... |
additional parameters (not used) |
a summary of parameter estimates and confidence intervals for an AME fit
Peter Hoff
Computes a matrix of expected values based on an array X of predictors and a vector beta of regression coefficients.
Xbeta(X, beta)
Xbeta(X, beta)
X |
an n by n by p array |
beta |
a p by 1 vector |
An n by n matrix
Peter Hoff
Compute an embedding of a sociomatrix into a two-dimensional space.
xnet(Y, fm = suppressWarnings(require("network")), seed = 1)
xnet(Y, fm = suppressWarnings(require("network")), seed = 1)
Y |
(square matrix) The sociomatrix. |
fm |
(logical scalar) If TRUE, the Fruchterman-Reingold layout will be used (requires the network package). |
seed |
(integer) The random seed (the FR layout is random). |
Coordinates are obtained using the Fruchterman-Reingold layout if the
package network
is installed, and otherwise uses the first two
eigenvectors the sociomatrix.
(matrix) A matrix of two-dimensional coordinates.
Peter Hoff
data(addhealthc3) Y<-addhealthc3$Y X<-xnet(Y) netplot(Y,X)
data(addhealthc3) Y<-addhealthc3$Y X<-xnet(Y) netplot(Y,X)
a synthetic dataset that includes binary relational data as well as information on eight covariates
data(YX_bin)
data(YX_bin)
The format is: List of 2 $ Y: num [1:100, 1:100] NA 0 0 0 0 0 0 0 0 1 ... $ X: num [1:100, 1:100, 1:8] 1 1 1 1 1 1 1 1 1 1 ... ..- attr(*, "dimnames")=List of 3 .. ..$ : NULL .. ..$ : NULL .. ..$ : chr [1:8] "intercept" "rgpa" "rsmoke" "cgpa" ...
data(YX_bin) gofstats(YX_bin$Y)
data(YX_bin) gofstats(YX_bin$Y)
a synthetic dataset that includes longitudinal binary relational data as well as information on covariates
data(YX_bin_long)
data(YX_bin_long)
a list
data(YX_bin_long) gofstats(YX_bin_long$Y[,,1])
data(YX_bin_long) gofstats(YX_bin_long$Y[,,1])
a synthetic dataset that includes relational data where the number of nominations per row is censored at 10, along with information on eight covariates
data(YX_cbin)
data(YX_cbin)
The format is: List of 2 $ Y: num [1:100, 1:100] NA 0 0 0 1 0 0 0 0 3 ... $ X: num [1:100, 1:100, 1:8] 1 1 1 1 1 1 1 1 1 1 ... ..- attr(*, "dimnames")=List of 3 .. ..$ : NULL .. ..$ : NULL .. ..$ : chr [1:8] "intercept" "rgpa" "rsmoke" "cgpa" ...
data(YX_cbin) gofstats(YX_cbin$Y)
data(YX_cbin) gofstats(YX_cbin$Y)
a synthetic dataset that includes fixed rank nomination data as well as information on eight covariates
data(YX_frn)
data(YX_frn)
The format is: List of 2 $ Y: num [1:100, 1:100] NA 0 0 0 1 0 0 0 0 3 ... $ X: num [1:100, 1:100, 1:8] 1 1 1 1 1 1 1 1 1 1 ... ..- attr(*, "dimnames")=List of 3 .. ..$ : NULL .. ..$ : NULL .. ..$ : chr [1:8] "intercept" "rgpa" "rsmoke" "cgpa" ...
data(YX_frn) gofstats(YX_frn$Y)
data(YX_frn) gofstats(YX_frn$Y)
a synthetic dataset that includes continuous (normal) relational data as well as information on eight covariates
data(YX_nrm)
data(YX_nrm)
The format is: List of 2 $ Y: num [1:100, 1:100] NA -4.05 -0.181 -3.053 -1.579 ... $ X: num [1:100, 1:100, 1:8] 1 1 1 1 1 1 1 1 1 1 ... ..- attr(*, "dimnames")=List of 3 .. ..$ : NULL .. ..$ : NULL .. ..$ : chr [1:8] "intercept" "rgpa" "rsmoke" "cgpa" ...
data(YX_nrm) gofstats(YX_nrm$Y)
data(YX_nrm) gofstats(YX_nrm$Y)
a synthetic dataset that includes ordinal relational data as well as information on seven covariates
data(YX_ord)
data(YX_ord)
The format is: List of 2 $ Y: num [1:100, 1:100] NA 0 3 0 3 1 0 1 1 0 ... $ X: num [1:100, 1:100, 1:7] 1 1 1 1 1 1 1 1 1 1 ... ..- attr(*, "dimnames")=List of 3 .. ..$ : NULL .. ..$ : NULL .. ..$ : chr [1:7] "rgpa" "rsmoke" "cgpa" "csmoke" ...
data(YX_ord) gofstats(YX_ord$Y)
data(YX_ord) gofstats(YX_ord$Y)
a synthetic dataset that includes row-specific ordinal relational data as well as information on five covariates
data(YX_rrl)
data(YX_rrl)
The format is: List of 2 $ Y: num [1:100, 1:100] NA 0 3 0 3 1 0 1 1 0 ... $ X: num [1:100, 1:100, 1:5] 1 1 1 1 1 1 1 1 1 1 ... ..- attr(*, "dimnames")=List of 3 .. ..$ : NULL .. ..$ : NULL .. ..$ : chr [1:5] "cgpa" "csmoke" "igrade" "ismoke" ...
data(YX_rrl) gofstats(YX_rrl$Y)
data(YX_rrl) gofstats(YX_rrl$Y)
Computes the normal scores corresponding to the ranks of a data vector
zscores(y,ties.method="average")
zscores(y,ties.method="average")
y |
a numeric vector |
ties.method |
method for dealing with ties |
a numeric vector
Peter Hoff