Skip to content

Commit

Permalink
Merge pull request #60 from snlab-nl/develop
Browse files Browse the repository at this point in the history
Version 1.3.17
  • Loading branch information
TomSnijders authored Jan 7, 2023
2 parents 11c45af + aefd551 commit c601de7
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 38 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Encoding: UTF-8
Package: RSiena
Type: Package
Title: Siena - Simulation Investigation for Empirical Network Analysis
Version: 1.3.16
Date: 2023-01-02
Version: 1.3.17
Date: 2023-01-06
Authors@R: c(person("Tom A.B.", "Snijders", role = c("cre", "aut"), email = "tom.snijders@nuffield.ox.ac.uk", comment = c(ORCID = "0000-0003-3157-4157")),
person("Ruth", "Ripley", role = "aut"),
person("Krists", "Boitmanis", role = c( "aut","ctb")),
Expand Down Expand Up @@ -38,7 +38,8 @@ Description: The main purpose of this package is to perform simulation-based
There are also functions for testing parameters and checking goodness of fit.
An overview of these models is given in Tom A.B. Snijders (2017), "Stochastic
Actor-Oriented Models for Network Dynamics", Annual Review of Statistics and
Its Application, 4, 343-363 <doi:10.1146/annurev-statistics-060116-054035>.
Its Application, 4, 343-363
<https://doi.org/10.1146/annurev-statistics-060116-054035>.
An extensive manual, scripts, and much further information is at the Siena
website <https://www.stats.ox.ac.uk/~snijders/siena/>.
License: GPL-2 | GPL-3 | file LICENSE
Expand Down
16 changes: 15 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# RSiena 1.3.17

##

2023-01-06

## Changes in RSiena:

### Improvements of functionality:
* `sienaGOF` now accepts simulated auxiliary statistics containing missing
values. If there are any, this will be reported with a warning
if `giveNAWarning` is `TRUE`.
* `sienaDataCreate` now also accepts, as "...", a list of such objects.

# RSiena 1.3.16

##
Expand All @@ -10,7 +24,7 @@

### Effects:
`inPopIntnX`, `inActIntnX`, `outPopIntnX`, `outActIntnX`, `sameXInPopIntn`,
`sameXOutPopIntn`, sameXInActIntn`, `sameXOutActIntn` restored
`sameXOutPopIntn`, `sameXInActIntn`, `sameXOutActIntn` restored
(these had got lost in some way...).
### Updates:
* All occurrences of `http` in `R` and `Rd` files changed to `https`.
Expand Down
26 changes: 24 additions & 2 deletions R/sienaDataCreate.r
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,22 @@ sienaDataCreate<- function(..., nodeSets=NULL, getDocumentation=FALSE)
dots <- as.list(substitute(list(...)))[-1] ##first entry is the word 'list'
if (length(dots) == 0)
{
stop('need some networks')
stop('need some objects')
}
if (length(dots) == 1)
{
ldots <- list(...)
dotsIsList <- (is.list(ldots[[1]]))
# If dotsIsList, it needs to be a list of variables
if (dotsIsList)
{
dots <- as.list(substitute(...))[-1]
narg <- length(ldots)
}
}
else
{
dotsIsList <- FALSE
}
nm <- names(dots)
if (is.null(nm))
Expand All @@ -255,7 +270,14 @@ sienaDataCreate<- function(..., nodeSets=NULL, getDocumentation=FALSE)
{
nm[fixup] <- dep
}
dots <- list(...)
if (!dotsIsList)
{
dots <- list(...)
}
else
{
dots <- (...)
}
names(dots) <- nm
if (any(duplicated(nm)))
{
Expand Down
36 changes: 29 additions & 7 deletions R/sienaGOF.r
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ sienaGOF <- function(
sienaFitObject, auxiliaryFunction,
period=NULL, verbose=FALSE, join=TRUE, twoTailed=FALSE,
cluster=NULL, robust=FALSE,
groupName="Data1", varName, tested=NULL, ...)
groupName="Data1", varName, tested=NULL,
giveNAWarning=TRUE, ...)
{
## require(MASS)
## require(Matrix)
Expand Down Expand Up @@ -88,7 +89,7 @@ sienaGOF <- function(
period <- 1:(attr(sienaFitObject$f[[1]]$depvars[[1]], "netdims")[3] - 1)
}

obsStatsByPeriod <- lapply(period, function (j) {
obsStatsByPeriod <- lapply(period, function (j) {
matrix(
auxiliaryFunction(NULL,
sienaFitObject$f,
Expand Down Expand Up @@ -170,6 +171,18 @@ sienaGOF <- function(
)
}

## Give a warning in case of missings.
nmissings <- vapply(simStatsByPeriod,
function(sp){apply(sp, 2, function(x){sum(is.na(x))})},
FUN.VALUE=rep(0,dim(simStatsByPeriod[[1]])[2]))
rownames(nmissings) <- plotKey
if ((sum(nmissings) > 0) & giveNAWarning)
{
cat("Number of missing values in the simulated functions:\n")
print(t(nmissings))
warning("Some simulated values are missing.")
}

## Aggregate by period if necessary to produce simStats
if (join)
{
Expand Down Expand Up @@ -213,11 +226,12 @@ sienaGOF <- function(
}
else
{
a <- cov(simulated)
a <- cov(simulated, use="pairwise.complete.obs")
a[is.na(a)] <- 0
}
ainv <- ginv(a)
arank <- rankMatrix(a)
expectation <- colMeans(simulated);
expectation <- colMeans(simulated)
centeredSimulations <- scale(simulated, scale=FALSE)
if (variates==1)
{
Expand Down Expand Up @@ -285,8 +299,10 @@ sienaGOF <- function(
}
else
{
covInvByPeriod <- lapply(period, function(i) ginv(
cov(simStatsByPeriod[[i]]) ))
covInvByPeriod <- lapply(period, function(i){
b <- cov(simStatsByPeriod[[i]], use="pairwise.complete.obs")
b[is.na(b)] <- 0
ginv(b)})
}

obsMhd <- sapply(period, function (i) {
Expand Down Expand Up @@ -327,7 +343,7 @@ sienaGOF <- function(
t(sienaFitObject$targets2[effectsToInclude, , drop=FALSE])
G <- sienaFitObject$sf2[, , effectsToInclude, drop=FALSE] -
rep(obsSuffStats, each=nSims)
sigma <- cov(apply(G, c(1, 3), sum))
sigma <- cov(apply(G, c(1, 3), sum), use="pairwise.complete.obs")
SF <- sienaFitObject$ssc[ , , effectsToInclude, drop=FALSE]
dimnames(SF)[[3]] <- effectsObject$effectName[effectsToInclude]
dimnames(G) <- dimnames(SF)
Expand Down Expand Up @@ -440,6 +456,7 @@ sienaGOF <- function(
attr(res, "simTime") <- attr(simStats,"time")
attr(res, "twoTailed") <- twoTailed
attr(res, "joined") <- join
attr(res, "nmissings") <- nmissings
res
}

Expand Down Expand Up @@ -509,6 +526,11 @@ print.sienaGOF <- function (x, ...) {
summary.sienaGOF <- function(object, ...) {
x <- object
print(x)
if (sum(attr(x, "nmissings"))> 0){
cat("\nThere were missing values in the simulated statistics.\n")
cat("Their number (by period):\n")
print(t(attr(x, "nmissings")))
}
if (attr(x, "scoreTest")) {
oneStepSpecs <- attr(x, "oneStepSpecs")
oneStepMhd <- attr(x, "oneStepMahalanobisDistances")
Expand Down
Binary file modified docs/manual/RSiena_Manual.pdf
Binary file not shown.
29 changes: 25 additions & 4 deletions docs/manual/RSiena_Manual.tex
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
by Mark Huisman, Michael Schweinberger, and Christian Steglich.

This manual is frequently updated, mostly only in a minor way.
This version was renewed for \RS version 1.3.15.
This version was renewed for \RS version 1.3.17.
\end{abstract}


Expand Down Expand Up @@ -1129,7 +1129,7 @@ \subsection{Getting help with problems}
of \rs. Details of the latest version available can
be found at the `Downloads' page.
The version is
identified by a version number (e.g.\ 1.3.15).
identified by a version number (e.g.\ 1.3.17).
You can find the number of your current installed version by
opening \R, and typing\\
\verb|packageVersion("RSiena")| \\
Expand Down Expand Up @@ -15575,12 +15575,12 @@ \section{For programmers: Building, installing and checking the package}
them to the repository.
\item [Check] Checking is a process designed to ensure that packages are likely
to work correctly when installed. Type\\
\verb|R CMD check RSiena_1.3.15.tar.gz|\\
\verb|R CMD check RSiena_1.3.17.tar.gz|\\
(where the version number is adjusted to match the tar ball name.)
\item[zip file] To make a zip file that can be used in Windows for
`installing from a local zip file', and therefore is easy for distribution
to others, type\\
\verb|R CMD INSTALL --build RSiena_1.3.15.tar.gz| \\
\verb|R CMD INSTALL --build RSiena_1.3.17.tar.gz| \\
(where again the version number is adjusted to match the tar ball name.)
\end{description}

Expand Down Expand Up @@ -16627,6 +16627,27 @@ \section{Changes compared to earlier versions}
\fi


\item 2023-01-06 GitHub, package version 1.3.17

Changes in RSiena (including those for version 1.3.16):
\begin{itemize}
\item Effects:
\begin{itemize}
\item \texttt{inPopIntnX}, \texttt{inActIntnX}, \texttt{outPopIntnX},
\texttt{outActIntnX}, \texttt{sameXInPopIntn},\\
\texttt{sameXOutPopIntn}, \texttt{sameXInActIntn}, \texttt{sameXOutActIntn} restored
(these had got lost in some way...).
\end{itemize}
\item Improvements of functionality:
\begin{itemize}
\item \sfn{sienaGOF} now accepts simulated auxiliary statistics containing missing
values. If there are any, this will be reported with a warning
if \texttt{giveNAWarning} is \texttt{TRUE}.
\item \sfn{sienaDataCreate} now also accepts, as "...", a list of such objects.
\end{itemize}
\end{itemize}


\item 2022-11-27 GitHub, package version 1.3.15

Changes in RSiena:
Expand Down
4 changes: 2 additions & 2 deletions man/RSiena-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ see \url{https://github.com/snlab-nl/rsiena/ }.
\tabular{ll}{
Package: \tab RSiena\cr
Type: \tab Package\cr
Version: \tab 1.3.16\cr
Date: \tab 2023-01-02\cr
Version: \tab 1.3.17\cr
Date: \tab 2023-01-06\cr
Depends: \tab R (>= 3.5.0)\cr
Imports: \tab Matrix, lattice, parallel, MASS, methods, xtable\cr
Suggests: \tab network, tools, codetools, tcltk\cr
Expand Down
16 changes: 10 additions & 6 deletions man/sienaDataCreate.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
\title{Function to create a Siena data object}
\description{
Creates a Siena data object from input dependent variables
(networks and possibly behavioural variables), covariates, and
composition change objects.}
(networks and possibly behavioural variables), covariates, and
composition change objects.}
\usage{
sienaDataCreate(..., nodeSets=NULL, getDocumentation=FALSE)
}
\arguments{
\item{\dots}{objects of class \code{\link{sienaDependent}},
\code{\link{coCovar}}, \code{\link{varCovar}}, \code{\link{coDyadCovar}},
\code{\link{varDyadCovar}}, and/or \code{\link{sienaCompositionChange}}.
\code{\link{varDyadCovar}}, and/or \code{\link{sienaCompositionChange}};
or a list of such objects, of which the first element must not be
a \code{\link{sienaCompositionChange}} object.
There should be at least one \code{\link{sienaDependent}} object.}
\item{nodeSets}{list of Siena node sets. Default is the single node
set named "Actors", length equal to the number of rows in the first
Expand All @@ -23,15 +25,15 @@ sienaDataCreate(..., nodeSets=NULL, getDocumentation=FALSE)
functions, not for use by users.}
}
\details{
The function checks that the objects fit, that there is at least one network,
and adds various attributes to each dependent variable describing the
The function checks that the objects fit, that there is at least one dependent
variable, and adds various attributes to each dependent variable describing the
data. If there is more than one nodeSet they must all be specified.
Function \code{\link{print01Report}} will give a basic description of the data
object and is a check useful, e.g., for diagnosing problems.
}
\value{
An object of class "siena" which is designed to be used in a siena
model fit. The components of the object are.
model fit by \code{link{siena07}}. The components of the object are:
\item{nodeSets}{List of node sets involved}
\item{observations}{Integer indicating number of waves of data}
\item{depvars}{List of networks and behavior variables}
Expand All @@ -55,6 +57,8 @@ model fit. The components of the object are.
mynet <- sienaDependent(array(c(s501, s502, s503), dim=c(50, 50, 3)))
mybeh <- sienaDependent(s50a, type="behavior")
mydata <- sienaDataCreate(mynet, mybeh)
# This gives the same result as
mydata <- sienaDataCreate(list(mynet, mybeh))
## And for a two-mode network
mynet1 <- sienaDependent(array(c(s501, s502), dim=c(50, 50, 2)), nodeSet="senders")
senders <- sienaNodeSet(50, nodeSetName="senders")
Expand Down
26 changes: 15 additions & 11 deletions man/sienaGOF.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
sienaGOF(sienaFitObject, auxiliaryFunction,
period=NULL, verbose=FALSE, join=TRUE, twoTailed=FALSE,
cluster=NULL, robust=FALSE, groupName="Data1",
varName, tested=NULL, \dots)
varName, tested=NULL, giveNAWarning=TRUE, \dots)
\method{plot}{sienaGOF}(x, center=FALSE, scale=FALSE, violin=TRUE, key=NULL,
perc=.05, period=1, position=4, fontsize=12, \dots)
descriptives.sienaGOF(x, center=FALSE, scale=FALSE, perc=.05, key=NULL,
Expand Down Expand Up @@ -55,29 +55,32 @@ descriptives.sienaGOF(x, center=FALSE, scale=FALSE, perc=.05, key=NULL,
peace of mind to the user because calculations can take some time.}
\item{join}{Boolean: should sienaGOF do tests on all of the periods
individually (\code{FALSE}), or sum across periods (\code{TRUE})?}
\item{twoTailed}{Whether to use two tails for calculating \eqn{p}-values on the
Monte Carlo test. Recommended for advanced users only,
\item{twoTailed}{Whether to use two tails for calculating \eqn{p}-values on
the Monte Carlo test. Recommended for advanced users only,
as it is probably only applicable in rare cases.}
\item{cluster}{Optionally, a \code{parallel} or \code{snow} cluster to execute
the auxiliary function calculations on.}
\item{robust}{ Whether to use robust estimation of the covariance matrix.}
\item{groupName}{ Name of group; relevant for multi-group data sets.}
\item{varName}{ Name of dependent variable.}
\item{tested}{ A logical vector of length \code{sienaFitObject$pp} (number of parameters),
indicating a subset of tested parameters;
\item{tested}{ A logical vector of length \code{sienaFitObject$pp}
(number of parameters), indicating a subset of tested parameters;
or \code{NULL}, indicating all tested parameters; or \code{FALSE},
indicating nothing is to be tested.}
\item{giveNAWarning}{If \code{TRUE}, a warning is given if any simulated
values are missing.}
\item{x}{ Result from a call to sienaGOF. }
\item{center}{ Whether to center the statistics by median during plotting.}
\item{scale}{ Whether to scale the statistics by range during plotting.
scale=TRUE makes little sense without also center=TRUE.}
scale=\code{TRUE} makes little sense without also
center=\code{TRUE}.}
\item{violin}{ Use violin plots (vs. box plots only)? }
\item{key}{ Keys in the plot for the levels of the auxiliary statistic
(as given by parameter \code{levls} in the examples). }
\item{perc}{ 1 minus confidence level for the confidence bands (two sided). }
\item{position}{ Position where the observed value is plotted: 1=under,
2=to the left, 3=above, 4=to the right of the red dot. Can be a single number
from 1 to 4, or a vector with positions for each statistic
2=to the left, 3=above, 4=to the right of the red dot. Can be a single
number from 1 to 4, or a vector with positions for each statistic
(possibly recycled).}
\item{fontsize}{ Font size for the observed values plotted.}
\item{\dots}{Other arguments; for \code{sienaGOF()}, e.g., \code{levls} as a
Expand All @@ -86,7 +89,8 @@ descriptives.sienaGOF(x, center=FALSE, scale=FALSE, perc=.05, key=NULL,
for \code{plot.sienaGOF()}, e.g., the usual plotting parameters
\code{main}, \code{xlab}, \code{ylab}, \code{cex}, \code{cex.main},
\code{cex.lab}, and \code{cex.axis}.}
\item{showAll}{If FALSE, drops statistics with variance 0, like in the plot.}
\item{showAll}{If \code{FALSE}, drops statistics with variance 0,
like in the plot.}
}
\details{
This function is used to assess the goodness of fit of an estimated stochastic
Expand All @@ -95,10 +99,10 @@ descriptives.sienaGOF(x, center=FALSE, scale=FALSE, perc=.05, key=NULL,
of the periods, with the simulated values for the ends of the periods.
The differences are assessed by combining the components of the auxiliary
statistic using the Mahalanobis distance.

For \code{sienaFitObject}s that were made for a multi-group data set,
if you are not sure about the \code{groupName}s to use, these can be retrieved
by the command \code{'names(dataObject)'} (where \code{dataObject} is
by the command \code{"names(dataObject)"} (where \code{dataObject} is
the data used to produce the \code{sienaFitObject}).
Mostly they are \code{"Data1", "Data2"}, etc.

Expand Down
4 changes: 2 additions & 2 deletions man/simstats0c.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
\title{Versions of FRAN}
\description{
The functions to be called as "FRAN" by \code{\link{siena07}}.
They call compiled C++.
They call compiled C++. Not for general users' use.
}
\usage{
simstats0c(z, x, data=NULL, effects=NULL, fromFiniteDiff=FALSE,
Expand Down Expand Up @@ -65,7 +65,7 @@ terminateFRAN(z, x)
\details{
Not for general users' use.\cr
The name of \code{simstats0c} or \code{maxlikec}
should be used for the element FRAN of the model object, the former when using
should be used for the element FRAN of the model object, the former when using
estimation by forward simulation, the latter for maximum likelihood estimation.
The arguments with no defaults must be passed in on the call to
\code{\link{siena07}}.
Expand Down

0 comments on commit c601de7

Please sign in to comment.