[Rsiena-commits] r353 - in pkg/RSienaTest: . R man tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 14 17:46:25 CEST 2021


Author: tomsnijders
Date: 2021-04-14 17:46:25 +0200 (Wed, 14 Apr 2021)
New Revision: 353

Modified:
   pkg/RSienaTest/ChangeLog
   pkg/RSienaTest/DESCRIPTION
   pkg/RSienaTest/R/sienaBayes.r
   pkg/RSienaTest/man/RSiena-package.Rd
   pkg/RSienaTest/man/sienaBayes.Rd
   pkg/RSienaTest/tests/parallel.R
   pkg/RSienaTest/tests/parallel.Rout.save
Log:
Version RSienaTest 1.2-29, very small changes.

Modified: pkg/RSienaTest/ChangeLog
===================================================================
--- pkg/RSienaTest/ChangeLog	2021-03-18 17:31:26 UTC (rev 352)
+++ pkg/RSienaTest/ChangeLog	2021-04-14 15:46:25 UTC (rev 353)
@@ -1,4 +1,13 @@
+2021-04-14 R-Forge Revision 353, package version 1.2-29.
+Changes in RSienaTest:
+   * sienaBayes: break out of prewarming if in 2 consecutive steps
+     there are no acceptances.
+   * sienaBayes: if nrunMHBatches is odd, 1 is added to it.
+   * ThinBayesAcceptances mentioned in help page for sienaBayes.
+   * Test16 omitted.
+
 2021-03-18 R-Forge Revision 352, package version 1.2-28.
+Changes in RSienaTest:
    * New effect homXTransRecTrip
    * Added rateParameterPosition	to glueBayes, which results
      in correct effect names for extract.posteriorMeans.

Modified: pkg/RSienaTest/DESCRIPTION
===================================================================
--- pkg/RSienaTest/DESCRIPTION	2021-03-18 17:31:26 UTC (rev 352)
+++ pkg/RSienaTest/DESCRIPTION	2021-04-14 15:46:25 UTC (rev 353)
@@ -2,8 +2,8 @@
 Package: RSienaTest
 Type: Package
 Title: Siena - Simulation Investigation for Empirical Network Analysis
-Version: 1.2-28
-Date: 2021-03-18
+Version: 1.2-29
+Date: 2021-04-14
 Authors at R: c(person("Tom", "Snijders", role = c("cre", "aut"), email = "tom.snijders at nuffield.ox.ac.uk", comment = c(ORCID = "0000-0003-3157-4157")),
               person("Christian", "Steglich", role = c("aut","ctb"), comment = c(ORCID = "0000-0002-9097-0873")),
               person("Johan", "Koskinen", role = c("aut","ctb"), comment = c(ORCID = "0000-0002-6860-325X")),

Modified: pkg/RSienaTest/R/sienaBayes.r
===================================================================
--- pkg/RSienaTest/R/sienaBayes.r	2021-03-18 17:31:26 UTC (rev 352)
+++ pkg/RSienaTest/R/sienaBayes.r	2021-04-14 15:46:25 UTC (rev 353)
@@ -916,6 +916,11 @@
 		zsmall <- list()
 
 		z$nImproveMH <- nImproveMH
+		if  (nrunMHBatches%%2 == 1) # meaning that it is odd
+		{
+			cat("nrunMHBatches should be even. 1 is added to it.\n")
+			nrunMHBatches <- nrunMHBatches + 1
+		}
 		if (nrunMHBatches >= 2)
 		{
 			z$nrunMHBatches <- nrunMHBatches
@@ -950,6 +955,7 @@
 
 		# Pre-warming phase
 		bgain <- initfgain
+		accepts.earlier <- 10
 		for (ii in 1:nprewarm)
 		{
 			MCMCcycle(nrunMH=nrunMHBatches, nSampVar=nSampVarying,
@@ -956,8 +962,14 @@
 								nSampCons=nSampConst, nSampRate=nSampRates,
 								bgain=bgain)
 			cat('Pre-warming step',ii,'(',nprewarm,')\n')
-			cat("Accepts ",sum(zm$BayesAcceptances),"/",
+			accepts <- sum(zm$BayesAcceptances)
+			cat("Accepts ",sum(accepts),"/",
 				z$nGroup*nrunMHBatches,"\n")
+			if (max(accepts, accepts.earlier) <= 0)
+			{
+				break
+			}
+			accepts.earlier <- accepts
 			flush.console()
 		}
 		print('end of pre-warming')

Modified: pkg/RSienaTest/man/RSiena-package.Rd
===================================================================
--- pkg/RSienaTest/man/RSiena-package.Rd	2021-03-18 17:31:26 UTC (rev 352)
+++ pkg/RSienaTest/man/RSiena-package.Rd	2021-04-14 15:46:25 UTC (rev 353)
@@ -49,8 +49,8 @@
   \tabular{ll}{
     Package: \tab RSienaTest\cr
     Type: \tab Package\cr
-    Version: \tab 1.2-28\cr
-    Date: \tab 2021-03-18\cr
+    Version: \tab 1.2-29\cr
+    Date: \tab 2021-04-14\cr
     Depends: \tab R (>= 2.15.0)\cr
     Imports: \tab Matrix, lattice, parallel, MASS, methods\cr
     Suggests: \tab xtable, network, tools, codetools, utils, tcltk\cr
@@ -80,7 +80,7 @@
       The statistical evaluation of social network dynamics.
       \emph{Sociological Methodology} \bold{31}, 361-395.
     \item Snijders, Tom A.B. (2017). Stochastic Actor-Oriented Models for Network
-      Dynamics. 
+      Dynamics.
       \emph{Annual Review of Statistics and Its Application} \bold{4}, 343--363.
     \item  Snijders, Tom A.B., van de Bunt, Gerhard G., and
       Steglich, Christian E.G. (2010).

Modified: pkg/RSienaTest/man/sienaBayes.Rd
===================================================================
--- pkg/RSienaTest/man/sienaBayes.Rd	2021-03-18 17:31:26 UTC (rev 352)
+++ pkg/RSienaTest/man/sienaBayes.Rd	2021-04-14 15:46:25 UTC (rev 353)
@@ -43,7 +43,7 @@
     are saved after each multiple of saveFreq iterations in the main phase,
     in a file with name PartialBayesResult.RData (if a file with this name
     exists, it will be overwritten).
-    This file contains an object z of class "sienaBayesFit",
+    This file contains an object \code{z} of class \code{\link{sienaBayesFit}},
     with the provisional results.
     This is to guard against crashes or power failure.
     It can be used as value for \code{prevBayes} as indicated below.}
@@ -63,22 +63,22 @@
      groupwise initial estimation.}
   \item{priorSigEta}{Vector of length equal to the number of fixed parameters,
      or \code{NULL}. If not \code{NULL}, values that are not \code{NA} are prior
-     variances of eta (fixed effects); these must all be positive.}
+     variances of \code{eta} (fixed effects); these must all be positive.}
   \item{priorMu}{Vector of length equal to the number of randomly varying
      parameters, or \code{NULL}.
-     Prior mean of mu (global population mean for varying parameters);
+     Prior mean of \code{mu} (global population mean for varying parameters);
      default: 0.
      For the basic rate parameters the defaults are data-dependent,
      but if ((\code{priorRatesFromData = 0}) and \code{priorMu=NULL}),
      for these parameters the prior mean will be 2.}
-  \item{priorSigma}{Square matrix of dimension equal to length of priorMu,
+  \item{priorSigma}{Square matrix of dimension equal to length of \code{priorMu},
      or \code{NULL}.
-     Prior global population covariance matrix Sigma for the varying parameters;
+     Prior global population covariance matrix \code{Sigma} for the varying parameters;
      default: identity matrix.}
-  \item{priorDf}{Prior degrees of freedom for Sigma (global population
+  \item{priorDf}{Prior degrees of freedom for \code{Sigma} (global population
     covariance matrix); default: number of randomly varying parameters + 2.}
   \item{priorKappa}{Proportionality constant between prior covariance matrix
-    and covariance matrix of prior distribution for mu; default: 1.}
+    and covariance matrix of prior distribution for \code{mu}; default: 1.}
   \item{priorRatesFromData}{-1, 0, 1, or 2. Determines the prior distribution
      for the rate parameters.\cr
      -1: all basic rate parameters are fixed; this must correspond to
@@ -88,13 +88,13 @@
         from initialization phase;\cr
      2: prior is defined by robust estimates for location and multivariate scale
         of estimated rate parameters from initialization phase.}
-  \item{frequentist}{Currently only frequentist=FALSE works.
+  \item{frequentist}{Currently only \code{frequentist=FALSE} works.
     Boolean: chooses between frequentist or Bayesian
     estimation of the global parameters.
     Frequentist estimation is possible only for at least 2 groups.}
-  \item{incidentalBasicRates}{Boolean. If this is TRUE, the basic rate
+  \item{incidentalBasicRates}{Boolean. If this is \code{TRUE}, the basic rate
     parameters are defined specifically for each group, and estimated
-    using a Robbins Monro algorithm; if FALSE, they have a
+    using a Robbins Monro algorithm; if \code{FALSE}, they have a
     common prior for all groups.}
   \item{reductionFactor}{Positive number.
    If \code{priorRatesFromData} = 1 or 2, the prior distribution for the rate
@@ -110,35 +110,38 @@
     during iterations, it is changed so that
    all correlations are at least delta.}
   \item{nprewarm}{Number of iterations in the pre-warm-up phase,
-    before improveMH.}
+    before \code{improveMH}.}
   \item{nwarm}{Number of iterations in the warm-up phase.
     Used only if \code{prevBayes} is \code{NULL}.
     Then it should be at least 5.}
   \item{nmain}{Number of iterations in the main phase.
      Should be at least 10.}
-  \item{nrunMHBatches}{Thinning ratio in MCMC process;
-     but thinning is further determined by parameter \code{mult} in \code{algo},
-     see \code{\link{sienaAlgorithmCreate}}.}
+  \item{nrunMHBatches}{Integer: thinning ratio in MCMC process;
+     but thinning at the lowest level is further determined by parameter
+     \code{mult} in \code{algo},
+     see \code{\link{sienaAlgorithmCreate}}. Should be even.}
   \item{nSampVarying}{Number of samples of varying parameters
         for each chain sample.}
-  \item{nSampConst}{Number of samples of constant parameters ("eta")
+  \item{nSampConst}{Number of samples of constant parameters ("\code{eta}")
         for each chain sample.}
   \item{nSampRates}{Number of extra samples of basic rate parameters
         for each chain sample.}
-  \item{nImproveMH}{Number of iterations per improveMH step.
-        If \code{nImproveMH=0}, no improveMH steps at all.}
+  \item{nImproveMH}{Number of iterations per \code{improveMH} step.
+        If \code{nImproveMH=0}, no \code{improveMH} steps at all.}
   \item{targetMHProb}{Desired proportion of acceptances in MH steps.
        This can be one number, or a vector of two numbers. In the latter case,
        the first number applies to the MH steps per group (for each group),
-       the second to the MH steps for the constant parameters ("eta").}
+       the second to the MH steps for the constant parameters ("\code{eta}").}
   \item{lengthPhase1}{Only used for frequentist estimation or
       \code{incidentalBasicRates}:
       length of the first phase of the Robbins Monro algorithm.
-      lengthPhase1 + lengthPhase3 should be strictly less than nmain.}
+      \code{lengthPhase1 + lengthPhase3} should be strictly 
+	  less than \code{nmain}.}
    \item{lengthPhase3}{Only used for frequentist estimation or
       \code{incidentalBasicRates}:
       length of the third phase of the Robbins Monro algorithm.
-      lengthPhase1 + lengthPhase3 should be strictly less than nmain.}
+      \code{lengthPhase1 + lengthPhase3} should be strictly 
+	  less than \code{nmain}.}
   \item{storeAll}{Boolean: whether to store parameters for all MCMC iterations,
       i.e., before thinning. \code{storeAll=TRUE} may lead to producing
       very large objects and is not recommended for usual operation.}
@@ -162,7 +165,7 @@
   \item{usePrevOnly}{Boolean: see immediately above.}
   \item{prevBayes}{An object of class \code{sienaBayes} as returned by function
       \code{sienaBayes}, on which the current function will continue.
-      For example, the object z contained in the intermediate saved result
+      For example, the object \code{z} contained in the intermediate saved result
       \code{PartialBayesResult.RData} as mentioned above.
       Initialization and warming phases are skipped. \cr
       If these are given, the values of \code{nrunMHBatches},
@@ -208,13 +211,14 @@
   For the groupwise parameters normal distributions are assumed with conjugate
   priors.
   The conjugate prior is an inverse Wishart distribution for the covariance
-  matrix Sigma, with parameters \code{Lambda^{-1}} and \code{priorDf},
-  where \eqn{Lambda = priorDf \times priorSigma}{Lambda = priorDf * priorSigma};
-  and, conditional on Sigma, for the expected value a multivariate normal with
+  matrix \code{Sigma}, with parameters \code{Lambda^{-1}} and \code{priorDf},
+  where \code{Lambda = priorDf*priorSigma};
+  and, conditional on \code{Sigma}, for the expected value a multivariate normal with
   mean \code{priorMu} and covariance matrix \code{Sigma/priorKappa}.\cr
   For the fixed parameters, if \code{priorSigEta=NULL}, the improper constant
   prior is used.
-  Else, for the components of eta for which \code{priorEta} is \code{NA},
+  Else, for the components of \code{eta} (fixed effects parameter) for which
+  \code{priorEta} is \code{NA},
   the improper constant prior is used, and for other components,
   independent normal priors with mean 0 and variances given by \code{priorEta}.
   \cr
@@ -243,23 +247,25 @@
   estimate, with step size \code{initgain}.
   This is skipped if \code{initgain=0}.\cr
   If the \code{prevBayes} object is supplied, this initialization phase is
-  skipped, and if \code{newProposalFromPrev} the proposal covariance matrices are
-  calculated from the simulated chains in this object.\cr
-  From this basis, \code{nprewarm} Metropolis Hastings steps are taken.
+  skipped, and if \code{newProposalFromPrev} the proposal covariance matrices
+  are calculated from the simulated chains in this object.\cr
+  From this basis, \code{nprewarm} Metropolis Hastings steps are taken;
+  however, if no acceptances occur in two consecutive steps, the prewarming
+  phase is ended.
   The proposal covariance matrices then are scaled, in the
-  function 'improveMH', to achieve a proportion of accepted MH proposals
+  function '\code{improveMH}', to achieve a proportion of accepted MH proposals
   approximately equal to \code{target}.\cr
   After initialization and scaling of the proposal covariance matrices,
   a warming phase is done of \code{nwarm} Bayesian proposals
-  each with a number of MH steps, followed again by the function 'improveMH'.
+  each with a number of MH steps, followed again by the function '\code{improveMH}'.
   If the \code{prevBayes} object is supplied, the warming phase is skipped.
   \cr
-  Finally \code{nmain} repeats (of \code{nrunMHBatches} are performed of a
+  Finally \code{nmain} repeats of \code{nrunMHBatches} are performed of a
   number of MH steps sampling chains, plus \code{nSampVarying} MH steps
-  sampling the varying parameters ('theta_j') plus \code{nSampConst} MH steps
-  sampling the non-varying parameters ('eta') plus one Gibbs
+  sampling the varying parameters ('\code{theta_j}') plus \code{nSampConst}
+  MH steps sampling the non-varying parameters ('\code{eta}') plus one Gibbs
   step sampling the global mean and covariance matrix of the varying parameters
-  ('mu' and 'Sigma').
+  ('\code{mu}' and '\code{Sigma}').
   In the warming as well as the final phase, the number of MH steps
   within each run is determined by parameter \code{mult}
   ("multiplication factor") in the algorithm object \code{algo}.
@@ -312,30 +318,36 @@
   \item{initialResults}{sienaFit object: result of initial MoM estimation
   under the assumption of same parameters across groups}
   \item{ThinParameters}{array of dimensions (\code{nwarm+nmain} iterations
-  by parameters by groups): sampled groupwise parameters}
+    by parameters by groups): sampled groupwise parameters}
   \item{ThinPosteriorMu}{array of dimensions (\code{nwarm+nmain} iterations
-  by parameters): sampled global means of varying parameters}
+    by parameters): sampled global means of varying parameters}
   \item{ThinPosteriorEta}{array of dimensions (\code{nwarm+nmain} iterations
-  by fixed parameters): sampled fixed parameters}
+    by fixed parameters): sampled fixed parameters}
   \item{ThinPosteriorSigma}{array of dimensions (\code{nwarm+nmain} iterations
-  by parameters by parameters): sampled global covariance matrix
-  of varying parameters}
-  \item{nrunMH}{vector (by groups * waves) of number of MH steps in the innermost loop
-  of the likelihood simulations of the SAOM; this is a data-dependent
-   multiple of the value of \code{mult} set in \code{\link{sienaAlgorithmCreate}}.}
+    by parameters by parameters): sampled global covariance matrix
+    of varying parameters}
+  \item{nrunMH}{vector (by groups * waves) of number of MH steps in the
+   innermost loop of the likelihood simulations of the SAOM;
+   this is a data-dependent multiple of the value of \code{mult}
+   set in \code{\link{sienaAlgorithmCreate}}}
+  \item{ThinBayesAcceptances}{matrix of number of acceptances
+   in the \code{nrunMHBatches} MH steps in each iteration,
+   and summed over dependent variables,
+   for each group and (duplicated) for the vector of fixed effects}
   \item{acceptances}{if \code{storeAll=TRUE}: matrix of booleans:
-   whether the corresponding change to the parameters was accepted, by group}
+   whether the corresponding change to the parameters was accepted
+   in each step, by group}
   \item{MHacceptances}{if \code{storeAll=TRUE}:
    array of acceptances of the MH steps, by step type and group
    but summed over dependent variables}
   \item{MHrejections}{if \code{storeAll=TRUE}:
-   array of rejections of the ML steps}
+   array of rejections of the MH steps}
   \item{MHproportions}{if \code{storeAll=TRUE}:
    array of proportions of the MH steps accepted}
 }
 \references{See \url{http://www.stats.ox.ac.uk/~snijders/siena/}
 
-  Koskinen, J. H. and T. A. B. Snijders (2007).
+  Koskinen, J.H. and T.A.B. Snijders (2007).
   Bayesian inference for dynamic social network data.
   \emph{Journal of Statistical Planning and Inference}, 13, 3930-3938.
 }

Modified: pkg/RSienaTest/tests/parallel.R
===================================================================
--- pkg/RSienaTest/tests/parallel.R	2021-03-18 17:31:26 UTC (rev 352)
+++ pkg/RSienaTest/tests/parallel.R	2021-04-14 15:46:25 UTC (rev 353)
@@ -149,7 +149,7 @@
 (mydata <- sienaDataCreate(friend, behavior))
 (myeff <- getEffects(mydata, onePeriodSde = TRUE))
 algorithmMoM <- sienaAlgorithmCreate(nsub=1, n3=20, seed=321)
-(ans <- siena07(algorithmMoM, data = mydata, effects = myeff, batch=TRUE))
+#(ans <- siena07(algorithmMoM, data = mydata, effects = myeff, batch=TRUE))
 ##test17
 print('test17')
 Group1 <- sienaDependent(array(c(N3401, HN3401), dim=c(45, 45, 2)))

Modified: pkg/RSienaTest/tests/parallel.Rout.save
===================================================================
--- pkg/RSienaTest/tests/parallel.Rout.save	2021-03-18 17:31:26 UTC (rev 352)
+++ pkg/RSienaTest/tests/parallel.Rout.save	2021-04-14 15:46:25 UTC (rev 353)
@@ -555,76 +555,7 @@
 7 behavior intercept                   TRUE    FALSE FALSE   -0.86402   0
 > algorithmMoM <- sienaAlgorithmCreate(nsub=1, n3=20, seed=321)
 If you use this algorithm object, siena07 will create/use an output file Siena.txt .
-> (ans <- siena07(algorithmMoM, data = mydata, effects = myeff, batch=TRUE))
-SDE init parameters:  -0.1519645 -1.175127 0.7355777
-SDE par stand errors: 0.06428706 0.2889378 0.1507865
-
-Start phase 0
-theta:  4.696 -1.489  0.000  0.858 -0.112 -0.864  1.000
-
-Start phase 1
-Phase 1 Iteration 1 Progress: 0%
-Phase 1 Iteration 2 Progress: 0%
-Phase 1 Iteration 3 Progress: 0%
-Phase 1 Iteration 4 Progress: 1%
-Phase 1 Iteration 5 Progress: 1%
-Phase 1 Iteration 10 Progress: 2%
-Phase 1 Iteration 15 Progress: 2%
-Phase 1 Iteration 20 Progress: 3%
-Phase 1 Iteration 25 Progress: 4%
-Phase 1 Iteration 30 Progress: 5%
-Phase 1 Iteration 35 Progress: 5%
-Phase 1 Iteration 40 Progress: 6%
-Phase 1 Iteration 45 Progress: 7%
-Phase 1 Iteration 50 Progress: 8%
-theta:  4.4035 -1.6238  0.4253  0.8458 -0.0955 -0.8137  1.0000
-
-Start phase 2.1
-Phase 2 Subphase 1 Iteration 1 Progress: 61%
-Phase 2 Subphase 1 Iteration 2 Progress: 61%
-theta  4.1817 -1.7327  0.9256  0.8373 -0.0868 -0.7741  1.0000
-ac -1.142  3.277  1.128  0.733  0.761  0.598  0.685
-Phase 2 Subphase 1 Iteration 3 Progress: 62%
-Phase 2 Subphase 1 Iteration 4 Progress: 62%
-theta  3.896 -2.082  2.188  0.796 -0.068 -0.735  1.000
-ac 0.119 1.570 1.088 0.356 0.525 0.969 0.330
-Phase 2 Subphase 1 Iteration 5 Progress: 62%
-Phase 2 Subphase 1 Iteration 6 Progress: 62%
-theta  4.6429 -2.2035  2.6826  0.7857 -0.0835 -0.8061  1.0000
-ac 0.482 0.457 1.096 0.529 0.669 1.010 0.495
-Phase 2 Subphase 1 Iteration 7 Progress: 62%
-Phase 2 Subphase 1 Iteration 8 Progress: 62%
-theta  5.710 -2.093  2.611  0.825 -0.111 -0.878  1.000
-ac 0.473 0.676 1.174 0.452 0.608 1.004 0.433
-Phase 2 Subphase 1 Iteration 9 Progress: 62%
-Phase 2 Subphase 1 Iteration 10 Progress: 63%
-theta  6.171 -1.994  2.282  0.860 -0.131 -0.931  1.000
-ac 0.521 0.829 1.222 0.358 0.599 0.965 0.367
-theta  5.533 -2.264  2.476  0.854 -0.112 -0.865  1.000
-ac 0.4621 0.6521 0.2814 0.0807 0.1639 0.5790 0.0822
-theta:  5.533 -2.264  2.476  0.854 -0.112 -0.865  1.000
-
-Start phase 3
-Estimates, standard errors and convergence t-ratios
-
-                                      Estimate   Standard   Convergence
-                                                   Error      t-ratio
-Network Dynamics
-  1. rate basic rate parameter friend  5.5328  ( 9.6387   )   -0.4357
-  2. eval outdegree (density)         -2.2642  ( 0.1852   )   -0.5525
-  3. eval reciprocity                  2.4763  ( 0.2954   )   -0.2053
-
-Continuous Behavior Dynamics
-  4. eval wiener (behavior.behavior)   0.8540  ( 0.0861   )   -0.1574
-  5. eval feedback from behavior      -0.1119  ( 0.1616   )    0.0890
-  6. eval intercept                   -0.8645  ( 0.4628   )    0.0616
-  7. rate scale parameter period 1     1.0000  (     NA   )   -0.1574
-
-Overall maximum convergence ratio:    0.9060
-
-
-Total of 305 iteration steps.
-
+> # (ans <- siena07(algorithmMoM, data = mydata, effects = myeff, batch=TRUE))
 > ##test17
 > print('test17')
 [1] "test17"



More information about the Rsiena-commits mailing list