ts_estim
is the workhorse function of the package
RsienaTwoStep
. For details on the simulation function see ts_sims()
.
This function aims to estimate the model parameters according to the
Robbins-Monro algorithm as described in
snijders2001statisticalRsienaTwoStep.
Usage
ts_estim(
ans = NULL,
mydata = NULL,
myeff = NULL,
startvalues = NULL,
net1 = NULL,
net2 = NULL,
ccovar = NULL,
statistics = NULL,
b = 0.5,
conv = 0.001,
nite = 1000,
itef1 = 50,
itef3 = 1000,
p2step = c(1, 0, 0),
dist1 = NULL,
dist2 = NULL,
modet1 = "degree",
modet2 = "degree",
verbose = TRUE,
parallel = FALSE,
returnDeps = FALSE,
phase1 = TRUE,
phase3 = TRUE
)
ts_targets(
ans = NULL,
mydata = NULL,
myeff = NULL,
net1 = NULL,
net2 = NULL,
ccovar = NULL,
statistics = NULL
)
ts_phase1(
ans = NULL,
mydata = NULL,
myeff = NULL,
net1 = NULL,
net2 = NULL,
ccovar = NULL,
statistics = NULL,
itef1 = 100,
p2step = c(1, 0, 0),
dist1 = NULL,
dist2 = NULL,
modet1 = NULL,
modet2 = NULL,
verbose = TRUE,
parallel = FALSE
)
ts_phase3(
ans = NULL,
mydata = NULL,
myeff = NULL,
net1 = NULL,
net2 = NULL,
ccovar = NULL,
statistics = NULL,
startvalues = NULL,
itef3 = 1000,
p2step = c(1, 0, 0),
dist1 = NULL,
dist2 = NULL,
modet1 = "degree",
modet2 = "degree",
verbose = TRUE,
parallel = FALSE,
returnDeps = FALSE
)
Arguments
- ans
Results of class sienaFit, produced by a call to
RSiena::siena07()
- mydata
Siena data object created by a call to
RSiena::sienaDataCreate()
- myeff
Siena effects object created by a call to
RSiena::getEffects()
- startvalues
if not provided manually, taken from results of
ans$theta
, or ifans
is not provided fromsummary(myeff)$initialValue
.- net1
adjacency matrix, the adjacency matrix representing the relations between actors at Time=1. Valid values are 0 and 1. If not provided manually, retrieved from
ans
ormydata
.- net2
adjacency matrix, the adjacency matrix representing the relations between actors at Time=2. Valid values are 0 and 1. If not provided manually, retrieved from
ans
ormydata
.- ccovar
data frame with named time-constant covariates. If not provided manually, retrieved from
ans
ormydata
.- statistics
list of statistics of
RsienaTwoStep
, see:ts_degree()
and DETAILS. If not provided manually, retrieved fromans
ormyeff
.- b
numeric between 0.1 and 1 (default =0.5), used in Robbins-Monro algorithm.
- conv
numeric. Robbins-Monro algorithm stops if the mean deviation of parameters after each update steps become smaller than
conv
- nite
number of iterations phase2 (actual estimation of parameters)
- itef1
number of total iterations phase1 (To get to a crude Jacobian matrix, which can be used in phase2) )
- itef3
number of total iterations phase3 (To estimate SE). This phase will take the longest.
- p2step
numeric vector of length 3, setting the ratio of ministep, twostep and twoministeps. This parameter is passed to
ts_sims()
.- dist1
numeric, minimal path length between ego1 and ego2 at time1 in order to be allowed to start a cooperation. If
NULL
all dyads are allowed to start a cooperation. This parameter is passed tots_sims()
.- dist2
numeric, minimal path length between ego1 and ego2 at time2 in order for twostep to be counted as cooperation. This parameter is passed to
ts_sims()
.- modet1
string, indicating the type of ties being evaluated at time1. "degree" considers all ties as undirected. "outdegree" only allows directed paths starting from ego1 and ending at ego2. "indegree" only allows directed paths starting from ego2 and ending at ego2. This parameter is passed to
ts_sims()
.- modet2
string, indicating the type of ties being evaluated at time2. "degree" considers all ties as undirected. "outdegree" only allows directed paths starting from ego1 and ending at ego2. "indegree" only allows directed paths starting from ego2 and ending at ego2. This parameter is passed to
ts_sims()
.- verbose,
TRUE/FALSE. If set to true it shows the iteration steps and some results.
- parallel
Boolean. TRUE/FALSE.
- returnDeps
Boolean. If
TRUE
the simulated dependent variables (networks, behaviour) of phase3 will be returned.- phase1
TRUE/FALSE, If False no Jacobian matrix is calculated.
- phase3
TRUE/FALSE, if FALSE no SE are calculated
Value
If phase3 = FALSE
A dataframe of estimated parameters. The last row are the final
solutions of the Robbins Monro algorithm. If Phase 3 = TRUE
a list with first list element the data frame of estimated parameters and the second element the results of phase 3.
list, containing: estim
, covtheta
, tstat
tconv.max
, zdevs
, and if returnDeps = TRUE
simnets
Details
For examples on how to use ts_estim()
see:
vignette("1.Introduction_RsienaTwoStep", package="RsienaTwoStep")
or
the package website.
Before you set parallel
to TRUE make sure to set-up a cluster with the
package doParallel
(see Examples
).
p2step==c(1,0,0)
: ministepp2step==c(0,1,0)
& dist1==NULL & dist2==NULL: twostep-simultaneityp2step==c(0,1,0)
& dist1!=NULL & dist2==NULL: twostep-strict coordinationp2step==c(0,1,0)
& dist1!=NULL & dist2!=NULL: twostep-weak coordinationp2step==c(0,0,1)
: two-ministeps
Examples
if (FALSE) { # \dontrun{
# It is good practice to check if `RsienaTwoStep` uses the same
# target values as `RSiena`, which can be retrieved like: `ans$targets`.
ts_targets(net1 = s501, net2 = s502, statistics = list(ts_degree, ts_recip))
# In normal use case you do not want to estimate the Jacobian matrix yourself
# for phase 1. We simply use the matrix from `RSiena`. Except if you really
# expect different outcomes from the twostep model and not using a
# Dinv matrix at all does not work.
# Phase 1 only
jac <- ts_phase1(net1 = s501,
net2 = s502,
statistics = list(ts_degree, ts_recip),
ccovar = NULL,
itef1 = 30)
dinv <- solve(jac)
#estimate without the use of RSiena
ts_estim(net1 = s501,
net2 = s502,
statistics = list(ts_degree, ts_recip),
nite = 30,
phase1 = FALSE)
#estimate without the use of RSiena
ts_estim(net1 = s501,
net2 = s502,
statistics = list(ts_degree, ts_recip),
nite = 30,
itef1 = 10,
phase1 = TRUE)
#estimate without the use of RSiena
ts_estim(net1 = s501,
net2 = s502,
statistics = list(ts_degree, ts_recip),
nite = 30,
itef1 = 10,
phase1 = TRUE,
itef3 = 10,
phase3 = TRUE)
# Phase 3 only
startvalues <- c(5.5, -2.2, 2.4)
stat <- list(ts_degree, ts_recip)
ts_phase3(startvalues = startvalues,
net1 = s501,
statistics = stat,
itef3 = 10,
verbose = TRUE)
library(RSiena)
mynet <- sienaDependent(array(c(s501, s502), dim=c(50, 50, 2)))
mydata <- sienaDataCreate(mynet)
myalgorithm <- sienaAlgorithmCreate(cond=FALSE)
#toggle set conditional to retrieve the rate parameter in theta!
myeff <- getEffects(mydata)
ts_estim(mydata = mydata, myeff = myeff)
#warning, this may take a while!
ts_estim(mydata = mydata, myeff = myeff, phase3 = TRUE)
ans1 <- siena07(myalgorithm, data=mydata, effects=myeff)
ts_estim(ans1)
} # }