Description Usage Arguments Details See Also Examples
Fit (temporal) network autocorrelation models.
1 2 3 4 5 |
formula |
A formula where the left-hand side specifies either a vector containing the outcome variable (for a cross-sectional model) or a list of such vectors (for modeling the outcome at multiple time steps) or a data frame with one time step per column (also for longitudinal models of behavior). The right-hand side of the formula consists of tnam-specific model terms like |
family |
The link function for fitting the generalized linear model or the mixed effects model, for example |
re.node |
If multiple time steps are present: should a random effect for the nodes be added to the model? This results in the estimation of a mixed effects model. |
re.time |
If multiple time steps are present: should a random effect for the time steps be added to the model? This results in the estimation of a mixed effects model. |
time.linear |
If multiple time steps are present: should a linear effect for time be added to the model? This can be estimated in the standard GLM framework. |
time.quadratic |
If multiple time steps are present: should a squared effect for time be added to the model? This can be estimated in the standard GLM framework. |
center.y |
Center the dependent variable by subtracting the mean from the actual value within each time step? |
na.action |
How should missing values be treated? By default, they are omitted. See the |
... |
Further arguments that should be passed to the |
The tnam
function serves to estimate temporal or cross-sectional network autocorrelation models. Model terms such as spatial lags, temporal lags, spatio-temporal lags, centrality etc. can be specified in the formula
argument. Details on the model terms can be found on the tnam-terms
help page.
The tnamdata
function accepts a formula (like in the tnam
function) and returns a data frame with the response variable and the covariates for estimation with any estimation function. tnam
first calls tnamdata
internally and then hands over the resulting data structure to a glm
, lmer
, or nlmer
call. If models such as tobit, multinomial or multilevel models should be estimated, one can leave out the estimation step and feed the results of tnamdata
manually into any type of model.
tnam-package tnam-terms knecht
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | # The following example models delinquency among adolescents at
# multiple time steps as a function of (1) their nodal attributes
# like sex or religion, (2) their peers' delinquency levels, (3)
# their own and their peers' past delinquency behavior, and (4)
# their structural position in the network. See ?knecht for
# details on the dataset. Before estimating the model, all data
# should be labeled with the names of the nodes such that tnam
# is able to merge the information on multiple nodes across time
# points.
library("tnam")
data("knecht")
# prepare the dependent variable y
delinquency <- as.data.frame(delinquency)
rownames(delinquency) <- letters
# replace structural zeros (denoted as 10) and add row labels
friendship[[3]][friendship[[3]] == 10] <- NA
friendship[[4]][friendship[[4]] == 10] <- NA
for (i in 1:length(friendship)) {
rownames(friendship[[i]]) <- letters
}
# prepare the covariates sex and religion
sex <- demographics$sex
names(sex) <- letters
sex <- list(t1 = sex, t2 = sex, t3 = sex, t4 = sex)
religion <- demographics$religion
names(religion) <- letters
religion <- list(t1 = religion, t2 = religion, t3 = religion,
t4 = religion)
# Estimate the model. The first term is the sex of the respondent,
# the second term is the religion of the respondent, the third
# term is the previous delinquency behavior of the respondent,
# the fourth term is the delinquency behavior of direct friends,
# the fifth term is the delinquency behavior of indirect friends
# at a path distance of 2, the sixth effect is the past delinquency
# of direct friends, the seventh term indicates whether the
# respondent has any contacts at all, and the last term captures
# the effect of the betweenness centrality of the respondent on
# his or her behavior. Apparently, previous behavior, being an
# isolate, and religion seem to have an effect on delinquency in
# this dataset. There is also a slight positive trend over time,
# and direct friends exert a minor effect (not significant).
# Note that a linear model may not be the best specification for
# modeling the ordered categorical delinquency variable, but it
# suffice here for illustration purposes.
model1 <- tnam(
delinquency ~
covariate(sex, coefname = "sex") +
covariate(religion, coefname = "religion") +
covariate(delinquency, lag = 1, exponent = 1) +
netlag(delinquency, friendship) +
netlag(delinquency, friendship, pathdist = 2, decay = 1) +
netlag(delinquency, friendship, lag = 1) +
degreedummy(friendship, deg = 0, reverse = TRUE) +
centrality(friendship, type = "betweenness"),
re.node = TRUE, time.linear = TRUE
)
summary(model1)
# for nice table output, use the texreg package
library("texreg")
screenreg(model1)
|
Loading required package: xergm.common
Loading required package: ergm
Loading required package: network
network: Classes for Relational Data
Version 1.13.0.1 created on 2015-08-31.
copyright (c) 2005, Carter T. Butts, University of California-Irvine
Mark S. Handcock, University of California -- Los Angeles
David R. Hunter, Penn State University
Martina Morris, University of Washington
Skye Bender-deMoll, University of Washington
For citation information, type citation("network").
Type help("network-package") to get started.
ergm: version 3.9.4, created on 2018-08-15
Copyright (c) 2018, Mark S. Handcock, University of California -- Los Angeles
David R. Hunter, Penn State University
Carter T. Butts, University of California -- Irvine
Steven M. Goodreau, University of Washington
Pavel N. Krivitsky, University of Wollongong
Martina Morris, University of Washington
with contributions from
Li Wang
Kirk Li, University of Washington
Skye Bender-deMoll, University of Washington
Based on "statnet" project software (statnet.org).
For license and citation information see statnet.org/attribution
or type citation("ergm").
NOTE: Versions before 3.6.1 had a bug in the implementation of the bd()
constriant which distorted the sampled distribution somewhat. In
addition, Sampson's Monks datasets had mislabeled vertices. See the
NEWS and the documentation for more details.
Attaching package: 'xergm.common'
The following object is masked from 'package:ergm':
gof
Package: tnam
Version: 1.6.5
Date: 2017-03-31
Authors: Philip Leifeld (University of Glasgow)
Skyler J. Cranmer (The Ohio State University)
Linear mixed model fit by REML ['lmerMod']
Formula: response ~ . - node + (1 | node)
Data: dat
REML criterion at convergence: 218.8
Scaled residuals:
Min 1Q Median 3Q Max
-1.93553 -0.56697 0.00562 0.60984 2.48124
Random effects:
Groups Name Variance Std.Dev.
node (Intercept) 0.08961 0.2994
Residual 0.58600 0.7655
Number of obs: 78, groups: node, 26
Fixed effects:
Estimate Std. Error t value
(Intercept) -1.097840 0.807657 -1.359
time 0.251027 0.131140 1.914
covariate.sex -0.005484 0.228464 -0.024
covariate.religion 0.333390 0.134749 2.474
covariate.lag1 0.253887 0.124285 2.043
netlag.pathdist1 0.029634 0.019358 1.531
netlag.pathdist2 -0.014362 0.012393 -1.159
netlag.lag1.pathdist1 -0.024469 0.016389 -1.493
indegree.degree0 1.437989 0.679151 2.117
betweenness -0.007367 0.004559 -1.616
Correlation of Fixed Effects:
(Intr) time cvrt.s cvrt.r cvrt.1 ntlg.1 ntlg.2 nt.1.1 indg.0
time -0.573
covariat.sx -0.322 0.096
covart.rlgn -0.035 0.092 0.010
covarit.lg1 0.016 -0.193 -0.126 -0.307
ntlg.pthds1 0.173 -0.182 -0.142 -0.144 0.026
ntlg.pthds2 0.243 -0.404 -0.031 0.001 0.106 -0.219
ntlg.lg1.p1 0.011 -0.133 -0.090 -0.084 -0.160 -0.035 -0.210
indegr.dgr0 -0.783 0.225 -0.046 -0.221 -0.044 -0.082 -0.246 0.066
betweenness -0.171 0.206 0.067 0.041 0.046 -0.643 0.055 0.009 0.017
Version: 1.36.23
Date: 2017-03-03
Author: Philip Leifeld (University of Glasgow)
Please cite the JSS article in your publications -- see citation("texreg").
================================
Model 1
--------------------------------
(Intercept) -1.10
(0.81)
time 0.25
(0.13)
covariate.sex -0.01
(0.23)
covariate.religion 0.33 *
(0.13)
covariate.lag1 0.25 *
(0.12)
netlag.pathdist1 0.03
(0.02)
netlag.pathdist2 -0.01
(0.01)
netlag.lag1.pathdist1 -0.02
(0.02)
indegree.degree0 1.44 *
(0.68)
betweenness -0.01
(0.00)
--------------------------------
AIC 242.77
BIC 271.05
Log Likelihood -109.38
Num. obs. 78
Num. groups: node 26
Var: node (Intercept) 0.09
Var: Residual 0.59
================================
*** p < 0.001, ** p < 0.01, * p < 0.05
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.