diff --git a/DESCRIPTION b/DESCRIPTION index 6b3ef2c..40215d1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,8 +2,8 @@ Encoding: UTF-8 Package: RSiena Type: Package Title: Siena - Simulation Investigation for Empirical Network Analysis -Version: 1.6.10 -Date: 2026-06-14 +Version: 1.6.11 +Date: 2026-07-16 Authors@R: c(person("Tom A.B.", "Snijders", role = c("aut", "ctb"), comment = c(ORCID = "0000-0003-3157-4157")), person("Ruth M.", "Ripley", role = "aut"), person("Krists", "Boitmanis", role = c( "aut","ctb")), diff --git a/NAMESPACE b/NAMESPACE index 3029b16..d51105f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,6 +18,7 @@ export( networkExtraction, behaviorExtraction, OutdegreeDistribution, IndegreeDistribution, BehaviorDistribution, TriadCensus, mixedTriadCensus, dyadicCov, egoAlterCombi, egoAlterCovarComb, + AC_Moran, AC_Geary, siena_table, xtable, score.Test, Wald.RSiena, Multipar.RSiena, testSame.RSiena, funnelPlot, meta.table, influenceTable, selectionTable, @@ -66,8 +67,10 @@ S3method(write_report, sienadata) S3method(print, sienaGroup) S3method(print, sienaDependent) S3method(print, sienaFit) +S3method(print, coef_siena) S3method(summary, sienaFit) S3method(coef, sienaFit) +S3method(coefficients, sienaFit) S3method(vcov, sienaFit) S3method(test_parameter, sienaFit) S3method(write_result, sienaFit) diff --git a/NEWS.md b/NEWS.md index 2ad0452..a388ff2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,21 @@ +2026-07-16 + +# RSiena 1.6.11 + +## Changes in RSiena: +### Effects +### Functionality + * New auxiliary functions `AC_Moran` and `AC_Geary`. + * In `transformScript`, the replacement for `sienaCompositionChangeFromFile` + was put before the replacement for `sienaCompositionChange`. + * The component `theta` of results of function `siena`, the result of + functions `coef`, and `estimate_onestep` have got a class `coef_siena`, + which has its own `print` method (to allow vertical printing). + * Function `coef` now has default `shortenNames=FALSE`. + * Alias `coefficients` for `coef`. + * Remark to console about output file for `siena` only when + `silent=FALSE`. + 2026-06-14 # RSiena 1.6.10 diff --git a/R/TransformScript.R b/R/TransformScript.R index 096a96c..0072b25 100644 --- a/R/TransformScript.R +++ b/R/TransformScript.R @@ -73,8 +73,8 @@ namePairs <- list(c("sienaDependent", "as_dependent_rsiena"), c("sienaNet", "as_dependent_rsiena"), c("coCovar", "as_covariate_rsiena"), c("varDyadCovar", "as_covariate_rsiena"), - c("sienaCompositionChange", "as_composition_rsiena"), c("sienaCompositionChangeFromFile", "as_composition_file_rsiena"), + c("sienaCompositionChange", "as_composition_rsiena"), c("sienaNodeSet", "as_nodeset_rsiena"), c("sienaDataCreate", "make_data_rsiena"), c("sienaModelCreate", "sienaAlgorithmCreate"), diff --git a/R/initializeFRAN.r b/R/initializeFRAN.r index b8bd867..4943b7c 100644 --- a/R/initializeFRAN.r +++ b/R/initializeFRAN.r @@ -271,20 +271,23 @@ initializeFRAN <- function(z, x, data, effects, prevAns=NULL, initC, { if (!is.null(prevAns) && inherits(prevAns, "sienaFit")) { - if (is.null(x$useOneStep)) + if (is.null(x$useOneStep)) # undocumented feature; probably meaningless { x$useOneStep <- FALSE } if (x$useOneStep) - { - keepStill <- which(prevAns$fixed) - if (length(keepStill) == 0) + { + if (is.null(x$keepStill)) + { + x$keepStill <- which(prevAns$fixed) + } + if (length(x$keepStill) == 0) { - keepStill <- 0 + x$keepStill <- 0 } } effects <- update_theta(effects, prevAns, - onestep=x$useOneStep, keepUnchanged=keepStill) + onestep=x$useOneStep, keepUnchanged=x$keepStill) } } ## add any effects needed for settings model diff --git a/R/phase3.r b/R/phase3.r index 3d2ca1e..7a6586a 100644 --- a/R/phase3.r +++ b/R/phase3.r @@ -167,7 +167,7 @@ phase3.2 <- function(z, x, ...) toosmall2 <- abs(sf) < 1e-10 * z$scale dmsf[toosmall] <- 1e-20 * z$scale[toosmall] * z$scale[toosmall] tstat <- rep(NA, z$pp) - tstat[!toosmall]<- sf[!toosmall] / sqrt(dmsf[!toosmall]) + tstat[!toosmall] <- sf[!toosmall] / sqrt(dmsf[!toosmall]) tstat[toosmall & toosmall2] <- 0 tstat[toosmall & !toosmall2] <- NA z$tstat <- tstat diff --git a/R/siena07.r b/R/siena07.r index 3e634cf..8e21f71 100644 --- a/R/siena07.r +++ b/R/siena07.r @@ -81,8 +81,11 @@ siena <- function(data = NULL, effects = NULL, stop("For piped data, you need to give an outputName in the output control object.") } control_out$outputName <- paste(dataName, "_out", sep="") - cat('siena will create/use an output file', - paste(control_out$outputName,'.txt',sep=''),'.\n') + if (!silent) + { + cat('siena will create/use an output file', + paste(control_out$outputName,'.txt',sep=''),'.\n') + } } control_out$projname <- control_out$outputName } @@ -256,7 +259,7 @@ siena <- function(data = NULL, effects = NULL, ## need to reset the random number type to the normal one assign(".Random.seed", z$oldRandomNumbers, pos=1) } - + class(z$theta) <- "coef_siena" class(z) <- "sienaFit" attr(z, "version") <- packageDescription(pkgname, fields = "Version") z$tkvars <- NULL @@ -281,7 +284,8 @@ estimate_onestep <- function(x, fixed=x$fixed, r=1, shortenNames=FALSE) bfixed <- (1:x$pp) %in% fixed } else # it should be logical - { if (length(fixed) != x$pp) + { + if (length(fixed) != x$pp) { stop(paste('The length of the boolean vector is ', length(fixed), ', but it should be ', x$pp, '.', sep='')) @@ -292,6 +296,7 @@ estimate_onestep <- function(x, fixed=x$fixed, r=1, shortenNames=FALSE) dfrac <- x$dfra[!bfixed, !bfixed] meandev <- colMeans(x$sf[ , !bfixed]) onestep <- x$theta + dinv <- matrix(NA, x$pp, x$pp) # This will keep the bfixed parameter values if (!all(bfixed)) { @@ -307,6 +312,7 @@ estimate_onestep <- function(x, fixed=x$fixed, r=1, shortenNames=FALSE) { names(onestep) <- fromObjectToText(names(onestep)) } + class(onestep) <- "coef_siena" onestep } @@ -820,7 +826,7 @@ errorHandler <- function() } ##@coef.sienaFit method for sienaFit -coef.sienaFit <- function(object, dropRates=TRUE, shortenNames=TRUE, ...) +coef.sienaFit <- function(object, dropRates=TRUE, shortenNames=FALSE, ...) { result <- object$theta if (shortenNames) @@ -833,16 +839,23 @@ coef.sienaFit <- function(object, dropRates=TRUE, shortenNames=TRUE, ...) } if (dropRates) { - return(result[!object$requestedEffects$basicRate]) - } - else - { - return(result) + result <- result[!object$requestedEffects$basicRate] } + class(result) <- "coef_siena" + result } + +coefficients <- function(object, ...) UseMethod("coefficients", object) + +coefficients.sienaFit <- function(object, dropRates=TRUE, shortenNames=FALSE, ...) +{ + coef(object, dropRates, shortenNames, ...) +} + + ##@vcov.sienaFit method for sienaFit -vcov.sienaFit <- function(object, dropRates=TRUE, shortenNames=TRUE, ...) +vcov.sienaFit <- function(object, dropRates=TRUE, shortenNames=FALSE, ...) { result <- object$covtheta if (shortenNames) @@ -864,6 +877,13 @@ vcov.sienaFit <- function(object, dropRates=TRUE, shortenNames=TRUE, ...) } } +##@print.coef_siena Methods +print.coef_siena <- function(x, digits=4, ...) +{ + print(round(matrix(x,dimnames=list(names(x), "coef ")), digits)) + invisible(x) +} + fromObjectToText <- function(a, type='notex'){ # This is an extended version of the function in sienatable.r b <- as.character(a) diff --git a/R/sienaGOF.r b/R/sienaGOF.r index aea55cc..fd80739 100644 --- a/R/sienaGOF.r +++ b/R/sienaGOF.r @@ -1657,3 +1657,83 @@ egoAlterCovarComb <- function (i, obsData, sims, period, groupName, varName, attr(teax, "EgoAlter") <- TRUE teax } + +# define spatial autocorrelation functions: +Moran <- function(x,z) { + n <- length(z) + z.ave <- mean(z,na.rm=TRUE) + numerator <- n*sum(x*outer(z-z.ave,z-z.ave),na.rm=TRUE) + denominator <- sum(x,na.rm=TRUE)*sum((z-z.ave)^2,na.rm=TRUE) + return(numerator/denominator) +} + +Geary <- function(x,z) { + n <- length(z) + z.ave <- mean(z,na.rm=TRUE) + numerator <- (n-1)*sum(x*(outer(z,z,FUN='-')^2),na.rm=TRUE) + denominator <- 2*sum(x,na.rm=TRUE)*sum((z-z.ave)^2,na.rm=TRUE) + return(numerator/denominator) +} + + + +AC_Moran <- function (i, obsData, sims, period, groupName, varName, depth=3) +{ +# An auxiliary function calculating the Moran autocorrelations +# and rounding to 3 decimals + if (length(varName) != 2){ + stop("AC_Moran expects two varName parameters") + } + varName1 <- varName[1] + varName2 <- varName[2] + m <- as.matrix(sparseMatrixExtraction(i, obsData, sims, period, groupName, + varName1)) + x <- behaviorExtraction(i, obsData, sims, period, groupName, + varName2) +# Construct a list of powers 1:depth of m + if (depth >= 2){ + mList <- lapply(1:(depth-1), function(i){m}) + mPowList <- Reduce(function(x,y){pmin(x %*% y,1)}, mList, init=m,accumulate=TRUE) + mPowList <- lapply(mPowList, function(mat){mat[!is.na(x), !is.na(x)]}) + x <- x[!is.na(x)] + Morans <- vapply(mPowList, function(mat){Moran(mat,x)}, FUN.VALUE=0) + } + else { + m <- m[!is.na(x), !is.na(x)] + x <- x[!is.na(x)] + Morans <- Moran(m,x) + } + names(Morans) <- paste("d=", 1:depth, sep="") + round(Morans, 3) +} + +AC_Geary <- function (i, obsData, sims, period, groupName, varName, depth=3) +{ +# An auxiliary function calculating the Geary autocorrelations +# and rounding to 3 decimals + if (length(varName) != 2){ + stop("AC_Geary expects two varName parameters") + } + varName1 <- varName[1] + varName2 <- varName[2] + m <- as.matrix(sparseMatrixExtraction(i, obsData, sims, period, groupName, + varName1)) + x <- behaviorExtraction(i, obsData, sims, period, groupName, + varName2) + if (depth >= 2){ +# Construct a list of powers 1:depth of m + mList <- lapply(1:(depth-1), function(i){m}) + mPowList <- Reduce(function(x,y){pmin(x %*% y,1)}, mList, init=m,accumulate=TRUE) + mPowList <- lapply(mPowList, function(mat){mat[!is.na(x), !is.na(x)]}) + x <- x[!is.na(x)] + Gearys <- vapply(mPowList, function(mat){Geary(mat,x)}, FUN.VALUE=0) + } + else { + m <- m[!is.na(x), !is.na(x)] + x <- x[!is.na(x)] + Gearys <- Geary(m,x) + } + names(Gearys) <- paste("d=", 1:depth, sep="") + round(Gearys, 3) +} + diff --git a/docs/manual/RSiena.bib b/docs/manual/RSiena.bib index 2527236..d75b24a 100644 --- a/docs/manual/RSiena.bib +++ b/docs/manual/RSiena.bib @@ -3660,6 +3660,8 @@ @incollection{HannekeXing2007 title={Discrete temporal models of social networks}, author={Hanneke, Steve and Xing, Eric P.}, booktitle={Statistical network analysis: Models, issues, and new directions}, + editor={Airoldi, Edoardo, Blei, David M., Fienberg, Stephen E., + Goldenberg, Anna, Xing, Eric P., and Zheng, Alice X.}, pages={115--125}, year={2007}, publisher={Springer} @@ -4881,7 +4883,7 @@ @article{Kindermann98 {U}sing composite social maps to identify peer networks and to study their influences}, author={Kindermann, Thomas}, journal={New directions for child development}, - number={80}, + volume={81}, pages={55--82}, year={1998} } @@ -6163,6 +6165,7 @@ @article{Lyons2011 journal={Statistics, Politics, and Policy}, volume={2}, number={1}, + pages={1--27}, year={2011} } diff --git a/docs/manual/RSiena_Manual.pdf b/docs/manual/RSiena_Manual.pdf index 5638ce1..889b986 100644 Binary files a/docs/manual/RSiena_Manual.pdf and b/docs/manual/RSiena_Manual.pdf differ diff --git a/docs/manual/RSiena_Manual.tex b/docs/manual/RSiena_Manual.tex index b176633..b245843 100644 --- a/docs/manual/RSiena_Manual.tex +++ b/docs/manual/RSiena_Manual.tex @@ -216,7 +216,7 @@ and Viviana Amati. This manual is frequently updated, mostly only in a minor way. -This version was renewed for \RS version1.6.9. +This version was renewed for \RS version1.6.11. In version 1.6, the names of \RS functions have undergone important changes. This manual is for the new names. @@ -1187,7 +1187,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.6.9). + identified by a version number (e.g., 1.6.11). You can find the number of your current installed version by opening \R, and typing\\ \verb|packageVersion("RSiena")| \\ @@ -1376,16 +1376,11 @@ \subsection{Function \sfn{transformScript}} \sfn{siena07} or \sfn{sienaBayes}. These algorithm objects constructed always have the names, respectively, \texttt{alg\_model}, \texttt{alg\_alg}, and \texttt{alg\_out}. -\medskip - -Function \sfn{transformScript} also produces a log file. -If it leads to an error, it may be helpful to use\\ -\texttt{traceback()}\\ -immediately after the error occurs; and to look at -the log file, which will have line numbers until the last -line that was treated. \bigskip +The function \sfn{transformScript} also produces a log file; +its use is discussed below. + If you want to transform to the new names all files in the working directory with extension name \texttt{.R}, you could use the following script. @@ -1414,6 +1409,7 @@ \subsection{Function \sfn{transformScript}} \newpage + If and when errors in a newly created script occur, it is good to understand how the function \sfn{transformScript} operates. @@ -1435,7 +1431,38 @@ \subsection{Function \sfn{transformScript}} without being a function call (i.e., without being followed by "(")), they are replaced with the new names. \end{enumerate} +These three passes are documented in the log file.m + + +If in the algorithm used for \sfn{siena07} or \sfn{sienaBayes} +(or its call) a variable occurs, +then this variable may be unknown to \sfn{transformScript} +which will lead to an error. +For example: +\medskip + +\noindent +\texttt{\small Error in eval(parse(text = newcommand1)) : object 'nodes' not found} +\medskip + +\noindent +Just create the missing object and give it a value, +and run \sfn{transformScript} again. +In the generated script you probably will have to modify this object. + +If you cannot easily make sense of the error, + it may be helpful to look at +the log file, which will have line numbers until the last +line that was treated.\\ +If this does not help, you could use +\medskip + +\noindent +\texttt{traceback()} +\medskip +\noindent +immediately after the error occurs; and try to understand. \clearpage @@ -6093,14 +6120,14 @@ \subsubsection{Collinearity check} In this case the covariance matrix is as follows. {\footnotesize -\begin{verbatim} -Covariance matrix of estimates (correlations below diagonal):) + \begin{verbatim} +Covariance matrix of estimates (correlations below diagonal): 0.021 -0.018 -0.010 0.006 -0.008 -0.468 0.069 0.008 -0.034 -0.002 -0.395 0.180 0.032 -0.049 0.003 0.130 -0.378 -0.795 0.117 -0.001 -0.223 -0.037 0.074 -0.007 0.062 -\end{verbatim} + \end{verbatim} } The diagonal values are the variances, i.e., the squares of the standard errors (e.g., for the reciprocity effect, @@ -6625,7 +6652,7 @@ \subsubsection{Treatment of missing data} variables with a simple prior distribution, given by the distribution of the non-missing entries for this wave. (For Maximum Likelihood estimation, this is a Bayesian incursion -in an otherwise frequentist approach...) +in an otherwise frequentist approach...) The missing data at the end of the wave are modeled as random variables with the distribution implied by the Markov chain model with the estimated parameters. @@ -8899,7 +8926,7 @@ \subsection{Random coefficient multilevel Siena analysis} determined by parameter \texttt{mult} (`multiplication factor') in the call of \textsf{set\_algorithm\_saom} that created the algorithm object. \end{enumerate} - The function \textsf{multi\_siena} is time-consuming. When starting to use it, + The function \textsf{multi\_siena} is time-consuming. When starting to use it, it is advisable to start with low values of \texttt{nmain} to explore computing time. When the procedure seems to diverge, and for very small groups, it is @@ -8909,7 +8936,7 @@ \subsection{Random coefficient multilevel Siena analysis} \subsubsection{Treatment of missing data} -For missing data in the dependent variables (not in the covariates!), +For missing data in the dependent variables (not in the covariates!), a different procedure is used than the one in the Methods of Moments estimation procedure. The missing data at the beginning of the wave are modeled as random @@ -10540,9 +10567,11 @@ \subsubsection{Network evaluation function} this is left out in later versions of \si; \item {\em sum of (1/(out-degree + $p$)} \texttt{(outInv)}, - where $p$ is some constant, defined by \\ - $s^{\rm net}_{i\vit}(x) = 1/(x_{i+} + p)$;\\ - endowment effect only likelihood-based; + where $p$ is some constant, $ p \geq 1$, defined by +$ s^{\rm net}_{i\vit}(x) \,=\, 1/(x_{i+} + p) \ $ ;\\ + endowment effect only likelihood-based;\\ + also see \texttt{divOut\_ego}, which is similar but + suitable for interacting with other effects; \item {\em sum of (1/(out-degree + $p$)(out-degree + $p+1$))} \texttt{(outSqInv)}, where $p$ is some constant, defined by \\ @@ -16743,9 +16772,9 @@ \subsection{Ego -- alter selection tables} This is called the \emph{selection table}. It can be calculated by the \RS function \sfn{interpret\_selection}. -Given that this script is available in the working directory, -the data set is called \texttt{G129\_Data}, the answer -(\sfn{sienaFit}) object is called \texttt{ans5}, the network \texttt{"friendship"}, +Given that the data set is called \texttt{G129\_Data}, the answer +(\sfn{sienaFit}) object is called \texttt{ans5}, +the network \texttt{"friendship"}, and the actor variable \texttt{"drinking"}, the following command can be used. @@ -16753,7 +16782,7 @@ \subsection{Ego -- alter selection tables} \begin{verbatim} st_dr <- interpret_selection(ans5, G129_Data, "friendship", "drinking") # It can be displayed -sm.drink +st_dr # and if package xtable is loaded, also be written # to a latex or html file. For example, tab.drink <- xtable(st_dr) @@ -17765,12 +17794,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.6.9.tar.gz|\\ +\verb|R CMD check RSiena_1.6.11.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.6.9.tar.gz| \\ +\verb|R CMD INSTALL --build RSiena_1.6.11.tar.gz| \\ (where again the version number is adjusted to match the tar ball name.) \end{description} @@ -18255,15 +18284,15 @@ \subsection{Notes on effectGroups and two-mode networks} For two-mode networks the difference between the two node sets implies some peculiarities. -Recall that effectGroups define combinations of dependent variable, -effect type, and covariates (if any). +Recall that effectGroups define combinations of dependent variable, +effect type, and covariates (if any). They are used in the file \texttt{allEffects.csv} and in function \sfn{effects.r}. -In the output of \sfn{effectsDocumentation()} -(mentioning no effects object), the effectGroups are +In the output of \sfn{effectsDocumentation()} +(mentioning no effects object), the effectGroups are given as categories of the effects. -In the function \textsf{make\_specification} in file \sfn{effects.r}, +In the function \textsf{make\_specification} in file \sfn{effects.r}, some additional measures are taken for effects in effectGroup \sfn{covarBipartiteObjective}, because this effect group does not differentiate between effects of covariates @@ -18330,7 +18359,7 @@ \subsection{Notes on effectGroups and two-mode networks} \item \sfn{covarNetNetObjective} is for effects where both networks are one-mode; \item \sfn{covarANetNetObjective} is for effects where - $X$ is one-mode, and if $W$ is two-mode, + $X$ is one-mode, and if $W$ is two-mode, $V$ is defined for the first mode; \item \sfn{covarAWNetNetObjective} is for effects where $W$ is one-mode, and $V$ is defined for the first mode; @@ -18437,6 +18466,33 @@ \section{Appendix: Changes compared to earlier versions} \fi +\item 2026-07-16 GitHub, package version 1.6.11. + +Changes in RSiena: +\begin{itemize} + \item Functionality + \begin{itemize} + \item New auxiliary functions \sfn{AC\_Moran} and \sfn{AC\_Geary}. + \item In \sfn{transformScript}, the replacement for \texttt{sienaCompositionChangeFromFile} + was put before the replacement for \texttt{sienaCompositionChange}. + \item The component \texttt{theta} of results of function \sfn{siena}, the result of + functions \sfn{coef}, and \sfn{estimate\_onestep} have got a class \sfn{coef\_siena}, + which has its own \sfn{print} method (to allow vertical printing). + \item Function \sfn{coef} now has default \texttt{shortenNames=FALSE}. + \item Alias \sfn{coefficients} for \sfn{coef}. + \item Remark to console about output file for \sfn{siena} only when + \texttt{silent=FALSE}. + \item Undo sorting of returned data frames for \texttt{returnChains=TRUE}\\ + (in \texttt{siena07models.cpp}). + \end{itemize} + \item Bug corrections: + \begin{itemize} + \item Running \sfn{siena} with \texttt{returnChains = TRUE, returnDataFrame = TRUE} + corrected. + \end{itemize} +\end{itemize} + + \item 2026-06-10 GitHub, package version 1.6.9. Changes in RSiena: @@ -18452,9 +18508,9 @@ \section{Appendix: Changes compared to earlier versions} \begin{itemize} \item New function \sfn{estimate\_onestep}. \item Option \texttt{onestep} for \sfn{update\_theta.sienaEffects} changed. - \item Hidden option to use the one-step estimator with + \item Hidden option to use the one-step estimator with \texttt{prevAns} in \sfn{siena} (experimental). - \item \sfn{print.sienadata} and \sfn{print.sienaGroup} now specify + \item \sfn{print.sienadata} and \sfn{print.sienaGroup} now specify the node sets for covariates and restricts printed line lengths to 64. \item More informative error message in \sfn{make\_data\_rsiena} if the number of elements of the second node set for bipartite networks is not correct. @@ -18467,7 +18523,7 @@ \section{Appendix: Changes compared to earlier versions} of two dependent networks and an actor covariate: these now are \texttt{covarNetNetObjective}, \\ \texttt{covarANetNetObjective}, \texttt{covarAWNetNetObjective},\\ - \texttt{covarADNetNetObjective}, + \texttt{covarADNetNetObjective}, \texttt{covarBNetNetObjective},\\ \texttt{covarBXNetNetObjective}. See Section~\ref{S_notestwomode}. diff --git a/man/RSiena-package.Rd b/man/RSiena-package.Rd index 0027a12..926e09d 100644 --- a/man/RSiena-package.Rd +++ b/man/RSiena-package.Rd @@ -52,8 +52,8 @@ Bug reports can be submitted at \tabular{ll}{ Package: \tab RSiena\cr Type: \tab Package\cr - Version: \tab 1.6.10\cr - Date: \tab 2026-06-14\cr + Version: \tab 1.6.11\cr + Date: \tab 2026-07-16\cr Depends: \tab R (>= 4.5.0)\cr Imports: \tab Matrix, lattice, parallel, MASS, methods, xtable\cr Suggests: \tab network, tools, codetools, tcltk\cr diff --git a/man/interpret_size_dynamics.Rd b/man/interpret_size_dynamics.Rd index 0a28953..23769e0 100644 --- a/man/interpret_size_dynamics.Rd +++ b/man/interpret_size_dynamics.Rd @@ -169,7 +169,7 @@ A \code{interpret_size_dynamics} object consists of following components: Relative Importance of Effects in Stochastic Actor-oriented Models. \emph{Network Science}, \bold{1 (3)}, 275--297. } -\author{Natalie Indlekofer} +\author{Natalie Indlekofer, Tom Snijders, Daniel Gotthardt } \examples{ myalgo <- set_algorithm_saom(nsub=1, n3=32, seed=1777, cond=FALSE) @@ -184,10 +184,8 @@ mymodel <- set_effect(mymodel, list(inPop, outAct, transTrip)) RIDynamics1 <- interpret_size_dynamics(mydata, ans=ans, useChangeContributions=TRUE) RIDynamics1 -\dontrun{ plot(RIDynamics1) - myalgo2 <- set_algorithm_saom(nsub=1, n3=32, seed=1777, cond=TRUE) (ans2 <- siena(mydata, effects=mymodel, control_algo=myalgo2, control_out=myout, batch=TRUE)) @@ -195,13 +193,15 @@ myalgo2 <- set_algorithm_saom(nsub=1, n3=32, seed=1777, cond=TRUE) RIDynamics2 <- interpret_size_dynamics(mydata, ans=ans2, effects=mymodel) RIDynamics2 - myalgo3 <- sienaAlgorithmCreate(nsub=1, n3=32, seed=1777, cond=TRUE) RIDynamics3 <- interpret_size_dynamics(data=mydata, theta=c(ans2$rate,ans2$theta), algorithm=myalgo3, effects=mymodel, intervalsPerPeriod=4) RIDynamics3 + +\dontrun{ + myalgo4 <- set_algorithm_saom(nsub=1, n3=32) mynet2 <- as_dependent_rsiena(array(c(s501, s502, s503), dim=c(50, 50, 3))) mybeh <- as_dependent_rsiena(s50a, type="behavior") diff --git a/man/siena.Rd b/man/siena.Rd index aafcbf6..a61c4fc 100644 --- a/man/siena.Rd +++ b/man/siena.Rd @@ -1,6 +1,7 @@ \name{siena} \alias{siena} \alias{siena07} +\alias{coef_siena} \alias{estimate_onestep} \concept{estimation} \title{Function to estimate parameters in a Siena model} @@ -109,13 +110,14 @@ estimate_onestep(x, fixed=x$fixed, r=1, shortenNames=FALSE) change statistics (contributions) should be returned; this may produce a very big file.} \item{x}{Object of class \code{sienaFit}.} - \item{fixed}{One number or a vector of numbers between 1 and \code{p}, + \item{fixed}{One number or a vector of numbers between 0 and \code{p}, where \code{p = x$pp}, the number of parameters in \code{x} excluding the basic rate parameters used for conditional estimation; these indicate the fixed parameters. Can also be a logical vector, of length \code{p} indicating - these by their numbers as given in the print of \code{x}.} - \item{r}{Real number, preferably in \code{(0.1]}.} + these by their numbers as given in the print of \code{x}. + If 0, nothing will be fixed.} + \item{r}{Real number, preferably in \code{(0,1]}.} \item{shortenNames}{Logical. Should the effect names be shortened?} } @@ -240,7 +242,7 @@ estimate_onestep(x, fixed=x$fixed, r=1, shortenNames=FALSE) is multiplied by \code{r}. } \value{ - Returns an object of class \code{\link{sienaFit}}, some parts of which are: + \code{siena} returns an object of class \code{\link{sienaFit}}, some parts of which are: \item{OK}{Boolean indicating successful termination} \item{termination }{Character string, values: "OK", "Error", or "UserInterrupt". "UserInterrupt" indicates that the user asked for early @@ -250,7 +252,7 @@ estimate_onestep(x, fixed=x$fixed, r=1, shortenNames=FALSE) \item{effects}{The included effects in the effects object to which are added the main effects of the requested interaction effects, if any.} \item{theta}{Estimated value of theta, if \code{simOnly=FALSE} - in \code{control_algo}.} + in \code{control_algo}. Is of class \code{coef_siena}.} \item{thetas}{Matrix, returned if \code{returnThetas} and \code{x$nsub >= 1}. First column is subphase; further columns are values of theta as generated during this subphase of Phase 2.} @@ -314,6 +316,10 @@ estimate_onestep(x, fixed=x$fixed, r=1, shortenNames=FALSE) of parameter values actually used in the simulations of Phase 3.} Writes text output to the file indicated for \code{siena} in \code{control_output} and for \code{siena07} in \code{alg}. + + \code{estimate_onestep} returns the one-step estimate in which + the parameters indiated in \code{fixed} are fixed. This is a vector + of class \code{coef_siena}. } \references{ Amati, V., Schoenenberger, F., and Snijders, T.A.B. (2015), diff --git a/man/sienaFit.Rd b/man/sienaFit.Rd index 1d56ea3..57ec660 100644 --- a/man/sienaFit.Rd +++ b/man/sienaFit.Rd @@ -10,7 +10,10 @@ \alias{write_result.sienaFit} \alias{write_result} \alias{coef} +\alias{print.coef_siena} \alias{coef.sienaFit} +\alias{coefficients} +\alias{coefficients.sienaFit} \alias{vcov} \alias{vcov.sienaFit} \title{Methods for processing sienaFit objects, @@ -23,9 +26,13 @@ \method{print}{summary.sienaFit}(x, matrices=TRUE, ...) -\method{coef}{sienaFit}(object, dropRates=TRUE, shortenNames=TRUE, ...) +\method{coef}{sienaFit}(object, dropRates=TRUE, shortenNames=FALSE, ...) -\method{vcov}{sienaFit}(object, dropRates=TRUE, shortenNames=TRUE, ...) +\method{coefficients}{sienaFit}(object, dropRates=TRUE, shortenNames=FALSE, ...) + +\method{print}{coef_siena}(x, digits=4, ...) + +\method{vcov}{sienaFit}(object, dropRates=TRUE, shortenNames=FALSE, ...) \method{write_result}{sienaFit}(x, type="tex", fileName=NULL, @@ -41,7 +48,8 @@ siena_table(x, type="tex", \arguments{ \item{x}{An object of class \code{sienaFit}, or \code{summary.sienaFit} as appropriate. For \code{siena_table}, - objects of class \code{sienaBayes} are also permitted.} + objects of class \code{sienaBayes} are also permitted. + For \code{print.coef_siena}, an object of class \code{coef_siena}. } \item{object}{An object of class \code{\link{sienaFit}}, produced by \code{\link{siena}}. For \code{siena_table}, objects of class \code{sienaBayes} are also permitted.} @@ -72,7 +80,8 @@ siena_table(x, type="tex", \item{align}{ See documentation for \code{\link[xtable]{xtable}}.} \item{digits}{ - See documentation for \code{\link[xtable]{xtable}}.} + Number of digits to be printed. Also see documentation + for \code{\link[xtable]{xtable}}.} \item{display}{ See documentation for \code{\link[xtable]{xtable}}} \item{nfirst}{Only relevant for the \code{multiSiena} package.} @@ -82,16 +91,25 @@ siena_table(x, type="tex", \code{type}, \code{file}.} } \description{ - \code{print}, \code{summary}, and \code{xtable} methods for - \code{sienaFit} objects. + \code{print}, \code{summary}, \code{coef}, + \code{vcov}, and \code{xtable} methods for \code{sienaFit} + and \code{coef_siena} objects. } \value{ Function \code{coef.sienaFit} gives the estimated parameters, and \code{vcov.sienaFit} their estimated variance-covariance matrix. + Function \code{coefficients.sienaFit} is an alias for \code{coef.sienaFit}. The function \code{print.sienaFit} prints a table containing estimated parameter values, standard errors and (optionally) - t-statistics for convergence. + \code{t}-statistics for convergence. + + Function \code{print.coef_siena} is used to print estimates from + \code{\link{siena}} or \code{\link{estimate_onestep}}. + + Function \code{print.coef_sienaFit} gives the estimated parameters, + and \code{vcov.sienaFit} their estimated variance-covariance matrix. + Function \code{coefficients.sienaFit} is an alias for \code{coef.sienaFit}. The function \code{summary.sienaFit} prints a table containing estimated parameter values, standard errors and t-statistics for diff --git a/man/test_gof_auxiliary.Rd b/man/test_gof_auxiliary.Rd index 228fd7c..9cc1c95 100644 --- a/man/test_gof_auxiliary.Rd +++ b/man/test_gof_auxiliary.Rd @@ -12,6 +12,8 @@ \alias{dyadicCov} \alias{egoAlterCombi} \alias{egoAlterCovarComb} +\alias{AC_Moran} +\alias{AC_Geary} \title{Auxiliary functions for goodness of fit assessment by \code{\link{test_gof}}} \description{ @@ -52,6 +54,10 @@ egoAlterCombi(i, obsData, sims, period, groupName, varName, trafo=NULL) egoAlterCovarComb(i, obsData, sims, period, groupName, varName, covar) +AC_Moran(i, obsData, sims, period, groupName, varName, depth=3) + +AC_Geary(i, obsData, sims, period, groupName, varName, depth=3) + sparseMatrixExtraction(i, obsData, sims, period, groupName, varName) networkExtraction(i, obsData, sims, period, groupName, varName) @@ -72,7 +78,8 @@ behaviorExtraction(i, obsData, sims, period, groupName, varName) 1 to number of waves - 1).} \item{groupName}{ Name of group; relevant for multi-group data sets; defaults in \code{\link{test_gof}} to "\code{Data1}".} - \item{varName}{ Name of dependent variable. } + \item{varName}{ String, name of dependent variable. For auxiliary statistics + that are for two dependent variables it should be a vector of two strings. } \item{levls}{ Levels used as values of the auxiliary statistic. For \code{BehaviorDistribution}, this defaults to the observed range of values.} @@ -88,6 +95,8 @@ behaviorExtraction(i, obsData, sims, period, groupName, varName) Default: identity function. } \item{covar}{ For \code{egoAlterCovarComb}: arbitrary monadic variable, vector of length \eqn{n}, the number of actors. } + \item{depth}{Positive integer, specifying the maximum directed path length + used for the network autocorrelation measures} } \details{ The statistics should be chosen to represent features of the network @@ -140,7 +149,7 @@ behaviorExtraction(i, obsData, sims, period, groupName, varName) \code{egoAlterCovarComb} does the same, for arbitrary monadic variables; e.g., transformed or untransformed covariates.\cr Here also, the range of \code{covar} should preferably have 5 or fewer values. - Missing values are allowed. + Missing values are allowed. } \value{ @@ -169,7 +178,13 @@ behaviorExtraction(i, obsData, sims, period, groupName, varName) existence of other ties is not considered. \code{dyadicCov} returns a named vector, the frequencies of the non-missing - non-zero values dc(ego,alter) of the observed or simulated (ego,alter) ties. + non-zero values dc(ego,alter) of the observed or simulated (ego,alter) ties. + + \code{AC_Moran} returns the Moran network autocorrelation coefficients + for directed distances \code{1, 2, ..., depth}, rounded to 3 decimals. + + \code{AC_Geary} returns the Geary network autocorrelation coefficients + for directed distances \code{1, 2, ..., depth}, rounded to 3 decimals. \code{egoAlterCombi} and \code{egoAlterCovarComb} return a named vector with the frequencies of realized ties for ego-alter combinations @@ -269,6 +284,19 @@ plot(gofi) # cumulative is an example of "\dots". plot(gofo) +(gofb <- test_gof(ans, BehaviorDistribution, varName = "mybeh", + verbose=TRUE, join=TRUE, cumulative=FALSE)) +plot(gofb) + +(gof_moran <- test_gof(ans, AC_Moran, verbose=TRUE, join=TRUE, + varName=c("mynet1","mybeh"))) +plot(gof_moran) + +(gof_geary <- test_gof(ans, AC_Geary, verbose=TRUE, join=TRUE, + varName=c("mynet1","mybeh"))) +plot(gof_geary) + + traf <- function(z){pmax(pmin(z,4),2)} (gofea <- test_gof(ans, egoAlterCombi, verbose=TRUE, join=TRUE, varName=c("mynet1","mybeh"), trafo=traf)) @@ -284,10 +312,6 @@ plot(gofea) dc=mydycov, varName="mynet1")) plot(gofdc) -(gofb <- test_gof(ans, BehaviorDistribution, varName = "mybeh", - verbose=TRUE, join=TRUE, cumulative=FALSE)) -plot(gofb) - (goftc <- test_gof(ans, TriadCensus, verbose=TRUE, join=TRUE, varName="mynet1")) plot(goftc, center=TRUE, scale=TRUE) diff --git a/src/model/effects/InverseOutdegreeEffect.cpp b/src/model/effects/InverseOutdegreeEffect.cpp index 4b90280..08b0e70 100644 --- a/src/model/effects/InverseOutdegreeEffect.cpp +++ b/src/model/effects/InverseOutdegreeEffect.cpp @@ -24,9 +24,9 @@ namespace siena * Constructor. */ InverseOutdegreeEffect::InverseOutdegreeEffect( - const EffectInfo * pEffectInfo) : NetworkEffect(pEffectInfo) + const EffectInfo * pEffectInfo) : NetworkEffect(pEffectInfo) { - this->lc = pEffectInfo->internalEffectParameter(); + this->lc = pEffectInfo->internalEffectParameter(); if (this->lc < 1) { @@ -41,19 +41,19 @@ InverseOutdegreeEffect::InverseOutdegreeEffect( */ double InverseOutdegreeEffect::calculateContribution(int alter) const { - double sum = - this->pNetwork()->outDegree(this->ego()) + this->lc; + double sum = + this->pNetwork()->outDegree(this->ego()) + this->lc; - if (this->outTieExists(alter)) - { - // Tie withdrawal - return -1.0 / ((sum - 1) * sum); - } - else - { - // Tie introduction - return -1.0 / ((sum + 1) * sum); - } + if (this->outTieExists(alter)) + { + // Tie withdrawal + return -1.0 / ((sum - 1) * sum); + } + else + { + // Tie introduction + return -1.0 / ((sum + 1) * sum); + } } @@ -63,9 +63,9 @@ double InverseOutdegreeEffect::calculateContribution(int alter) const * of this kind. */ double InverseOutdegreeEffect::egoStatistic(int ego, - const Network * pNetwork) + const Network * pNetwork) { - return 1.0 / (pNetwork->outDegree(ego) + this->lc); + return 1.0 / (pNetwork->outDegree(ego) + this->lc); } }