[Rsiena-commits] r228 - in pkg/RSiena: . inst/doc man src/model/variables
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Apr 20 14:55:09 CEST 2013
Author: tomsnijders
Date: 2013-04-20 14:55:08 +0200 (Sat, 20 Apr 2013)
New Revision: 228
Added:
pkg/RSiena/man/sienaGOF-auxiliary.Rd
pkg/RSiena/man/sienaGOF.Rd
pkg/RSiena/src/model/variables/DiffusionEffectValueTable.cpp
pkg/RSiena/src/model/variables/DiffusionEffectValueTable.h
Modified:
pkg/RSiena/changeLog
pkg/RSiena/inst/doc/effects.pdf
Log:
Changes only in RSiena:
Files
\pkg\RSiena\src\model\variables\DiffusionEffectValueTable.cpp
\pkg\RSiena\src\model\variables\DiffusionEffectValueTable.h
\pkg\RSiena\man\sienaGOF-auxiliary.Rd
\pkg\RSiena\man\sienaGOF.Rd
were erroneously not committed in revision 227.
Therefore this was done now. Also, file
\pkg\RSiena\inst\doc\effects.pdf
was updated.
Modified: pkg/RSiena/changeLog
===================================================================
--- pkg/RSiena/changeLog 2013-04-19 17:29:01 UTC (rev 227)
+++ pkg/RSiena/changeLog 2013-04-20 12:55:08 UTC (rev 228)
@@ -1,3 +1,15 @@
+2013-04-20 R-forge revision 228
+Changes only in RSiena:
+Files
+\pkg\RSiena\src\model\variables\DiffusionEffectValueTable.cpp
+\pkg\RSiena\src\model\variables\DiffusionEffectValueTable.h
+\pkg\RSiena\man\sienaGOF-auxiliary.Rd
+\pkg\RSiena\man\sienaGOF.Rd
+were erroneously not committed in revision 227.
+Therefore this was done now. Also, file
+\pkg\RSiena\inst\doc\effects.pdf
+was updated.
+
2013-04-19 R-forge revision 227
Changes in RSiena as well as RSienaTest;
both now are very similar; sienaBayes, algorithms, and profileLikelihoods
Modified: pkg/RSiena/inst/doc/effects.pdf
===================================================================
(Binary files differ)
Added: pkg/RSiena/man/sienaGOF-auxiliary.Rd
===================================================================
--- pkg/RSiena/man/sienaGOF-auxiliary.Rd (rev 0)
+++ pkg/RSiena/man/sienaGOF-auxiliary.Rd 2013-04-20 12:55:08 UTC (rev 228)
@@ -0,0 +1,286 @@
+\name{sienaGOF-auxiliary}
+\alias{sienaGOF-auxiliary}
+\alias{sparseMatrixExtraction}
+\alias{networkExtraction}
+\alias{behaviorExtraction}
+\alias{OutdegreeDistribution}
+\alias{IndegreeDistribution}
+\alias{BehaviorDistribution}
+
+\title{Auxiliary functions for goodness of fit assessment by \code{\link{sienaGOF}}}
+\description{
+ The functions given here are auxiliary to function \code{\link{sienaGOF}}
+ which assesses goodness of fit for actor-oriented models.
+
+ The auxiliary functions are, first, some functions of networks or behavior
+ (i.e., statistics) for which the simulated values for the fitted model
+ are compared to the observed value; second, some extraction functions
+ to extract the observed and simulated networks and/or behavior
+ from the \code{\link{sienaFit}} object produced by \code{\link{siena07}}
+ with \code{returnDeps=TRUE}.
+
+ These functions are exported here mainly to enable users to write
+ their own versions. At the end of this help page some non-exported functions
+ are listed. These are not exported because they depend on packages that
+ are not in the R base distribution; and to show templates for readers
+ wishing to contruct their own functions.
+ }
+
+\usage{
+OutdegreeDistribution(i, obsData, sims, period, groupName, varName,
+ levls=0:8, cumulative=TRUE)
+
+IndegreeDistribution(i, obsData, sims, period, groupName, varName,
+ levls=0:8, cumulative=TRUE)
+
+BehaviorDistribution(i, obsData, sims, period, groupName, varName,
+ levls=NULL, cumulative=TRUE)
+
+sparseMatrixExtraction(i, obsData, sims, period, groupName, varName)
+
+networkExtraction(i, obsData, sims, period, groupName, varName)
+
+behaviorExtraction(i, obsData, sims, period, groupName, varName)
+}
+\arguments{
+ \item{i}{ Index number of simulation to be extracted, ranging from 1 to
+ \code{length(sims)}; if NULL, the data observation will be extracted.}
+ \item{obsData}{ The observed data set to which the model was fitted; normally
+ this is \code{x$f} where \code{x} is the \code{\link{sienaFit}}
+ object for which the fit is being assessed.}
+ \item{sims}{ The simulated data sets to be compared with the observed data;
+ normally this is
+ \code{x$sims} where \code{x} is the \code{\link{sienaFit}}
+ object for which the fit is being assessed.}
+ \item{period}{ Period for which data and simulations are used (may run from
+ 1 to number of waves - 1).}
+ \item{groupName}{ Name of group; relevant for multi-group data sets;
+ defaults in \code{\link{sienaGOF}} to "\code{Data1}".}
+ \item{varName}{ Name of dependent variable. }
+ \item{levls}{ Levels used as values of the auxiliary statistic.
+ For \code{BehaviorDistribution}, this defaults to the observed
+ range of values.}
+ \item{cumulative}{ Are the distributions to be considered as raw or
+ cumulative (<=) distributions?}
+}
+\details{
+ The statistics should be chosen to represent features of the network
+ that are not explicitly fit by the estimation procedure but can be
+ considered important properties that the model at hand should represent well.
+ The three given here are far from a complete set;
+ they will be supplemented in due time by statistics depending on networks and
+ behavior jointly.
+
+ The method signature for the auxiliary statistics generally is
+ \code{function(i, obsData, sims, period, groupName, varName, \dots)}.
+ For constructing new auxiliary statistics, it is helpful to
+ study the code of \code{OutdegreeDistribution}, \code{IndegreeDistribution},
+ and \code{BehaviorDistribution} and of the example functions below.
+ }
+
+\value{
+ \code{OutdegreeDistribution} returns a named vector, the distribution
+ of the observed or simulated outdegrees for the values in \code{levls}.
+
+ \code{IndegreeDistribution} returns a named vector, the distribution
+ of the observed or simulated indegrees for the values in \code{levls}.
+
+ \code{BehaviorDistribution} returns a named vector, the distribution of the
+ observed or simulated behavioral variable for the values in \code{levls}.
+
+ \code{sparseMatrixExtraction} returns the simulated network as a
+ \code{dgCMatrix};
+ this is the "standard" class for sparse numeric matrices in the
+ \code{Matrix} package. See the help file for \code{\link{dgCMatrix-class}}.
+ Tie variables for ordered pairs with a missing value for wave=period or
+ period+1 are zeroed;
+ note that this also is done in RSiena for calculation of target statistics.
+
+\code{networkExtraction} returns the network as an edge list of class "network"
+ according to the network package (used for package sna).
+ Tie variables for ordered pairs with a missing value for wave=period or
+ period+1 are zeroed;
+ note that this also is done in RSiena for calculation of target statistics.
+
+\code{behaviorExtraction} returns the dependent behavior
+ variable as an integer vector.
+ Values for actors with a missing value for wave=period or period+1 are
+ transformed to NA.
+}
+
+\references{
+\itemize{
+\item See \url{http://www.stats.ox.ac.uk/~snijders/siena/}
+ for general information on RSiena.
+\item Lospinoso, J.A. and Snijders, T.A.B., \dQuote{Goodness of fit for
+Stochastic Actor Oriented Models.} Presentation given at Sunbelt XXXI,
+ St. Pete's Beach, Fl. 2011.
+\item Lospinoso, J.A. (2012). \dQuote{Statistical Models for Social Network Dynamics.}
+Ph.D. Thesis. University of Oxford: U.K.
+}
+}
+\author{Josh Lospinoso, Tom Snijders}
+\seealso{\code{\link{siena07}}, \code{\link{sienaGOF}} }
+\examples{
+\dontrun{
+ ### For use out of the box:
+
+ mynet1 <- sienaDependent(array(c(s501, s502, s503), dim=c(50, 50, 3)))
+ mybeh <- sienaDependent(s50a, type='behavior')
+ mydata <- sienaDataCreate(mynet1, mybeh)
+ myeff <- getEffects(mydata)
+ myeff <- includeEffects(myeff, transTies, cycle3)
+ myalgorithm <- sienaAlgorithmCreate(n3=500) # Shorter phase 3, just for example.
+ ans <- siena07(myalgorithm, data=mydata, effects=myeff, returnDeps=TRUE)
+
+ OutdegreeDistribution(NULL, ans$f, ans$sims, period=1, groupName="Data1",
+ levls=0:7, varName="mynet1")
+ IndegreeDistribution(5, ans$f, ans$sims, period=1, groupName="Data1",
+ varName="mynet1")
+ BehaviorDistribution(20, ans$f, ans$sims, period=1, groupName="Data1",
+ varName="mybeh")
+ sparseMatrixExtraction(50, ans$f, ans$sims, period=1, groupName="Data1",
+ varName="mynet1")
+ networkExtraction(100, ans$f, ans$sims, period=1, groupName="Data1",
+ varName="mynet1")
+ behaviorExtraction(200, ans$f, ans$sims, period=1, groupName="Data1",
+ varName="mybeh")
+
+ (gofi <- sienaGOF(ans, IndegreeDistribution, verbose=TRUE, join=TRUE,
+ varName="mynet1"))
+ gofi
+ plot(gofi)
+
+ (gofo <- sienaGOF(ans, OutdegreeDistribution, verbose=TRUE, join=TRUE,
+ varName="mynet1", cumulative=FALSE))
+ # cumulative is an example of "\dots".
+ plot(gofo)
+
+ (gofb <- sienaGOF(ans, BehaviorDistribution, varName = "mybeh",
+ verbose=TRUE, join=TRUE))
+ plot(gofb)
+
+ ### Here come some useful functions for building your own auxiliary statistics:
+ ### First an extraction function.
+
+ # igraphNetworkExtraction extracts simulated and observed networks
+ # from the results of a siena07 run.
+ # It returns the network as an edge list of class "graph"
+ # according to the igraph package.
+ # Ties for ordered pairs with a missing value for wave=period or period+1
+ # are zeroed;
+ # note that this also is done in RSiena for calculation of target statistics.
+ igraphNetworkExtraction <- function(i, data, sims, period, groupName, varName){
+ require(igraph)
+ dimsOfDepVar<- attr(data[[groupName]]$depvars[[varName]], "netdims")
+ missings <- is.na(data[[groupName]]$depvars[[varName]][,,period]) |
+ is.na(data[[groupName]]$depvars[[varName]][,,period+1])
+ if (is.null(i)) {
+ # sienaGOF wants the observation:
+ original <- data[[groupName]]$depvars[[varName]][,,period+1]
+ original[missings] <- 0
+ returnValue <- graph.adjacency(original)
+ }
+ else
+ {
+ missings <- graph.adjacency(missings)
+ #sienaGOF wants the i-th simulation:
+ returnValue <- graph.difference(
+ graph.edgelist(sims[[i]][[groupName]][[varName]][[period]][,1:2]),
+ missings)
+ }
+ returnValue
+ }
+
+ ### Then some auxiliary statistics.
+
+ # GeodesicDistribution calculates the distribution of directed
+ # geodesic distances; see ?sna::geodist
+ # The default for \code{levls} reflects that geodesic distances larger than 5
+ # do not differ appreciably with respect to interpretation.
+ # Note that the levels of the result are named;
+ # these names are used in the \code{plot} method.
+ GeodesicDistribution <- function (i, data, sims, period, groupName,
+ varName, levls=c(1:5,Inf), cumulative=TRUE, ...) {
+ x <- networkExtraction(i, data, sims, period, groupName, varName)
+ require(sna)
+ a <- sna::geodist(x)$gdist
+ if (cumulative)
+ {
+ gdi <- sapply(levls, function(i){ sum(a<=i) })
+ }
+ else
+ {
+ gdi <- sapply(levls, function(i){ sum(a==i) })
+ }
+ names(gdi) <- as.character(levls)
+ gdi
+ }
+
+ # Holland and Leinhardt Triad Census; see ?sna::triad.census.
+ TriadCensus <- function(i, data, sims, wave, groupName, varName, levls=1:16){
+ unloadNamespace("igraph") # to avoid package clashes
+ require(sna)
+ require(network)
+ x <- networkExtraction(i, data, sims, wave, groupName, varName)
+ tc <- sna::triad.census(x)[1,levls]
+ # names are transferred automatically
+ tc
+ }
+
+ # Distribution of Burt's constraint values; see ?igraph::constraint
+ # the maximum finite value is 9/8 (see Buskens and van de Rijt, AJS 2008).
+ ConstraintDistribution <- function (i, data, sims, period, groupName, varName,
+ levls=c(seq(0,1.125,by=0.125)), cumulative=TRUE){
+ require(igraph)
+ x <- igraphNetworkExtraction(i, data, sims, period, groupName, varName)
+ a <- igraph::constraint(x)
+ a[is.na(a)] <- Inf
+ lel <- length(levls)
+ if (cumulative)
+ {
+ cdi <- sapply(2:lel, function(i){sum(a<=levls[i])})
+ }
+ else
+ {
+ cdi <- sapply(2:lel, function(i){
+ sum(a<=levls[i]) - sum(a <= levls[i-1])})
+ }
+ names(cdi) <- as.character(levls[2:lel])
+ cdi
+ }
+
+ ## Finally some examples of the three auxiliary statistics constructed above.
+
+ mynet1 <- sienaDependent(array(c(s501, s502, s503), dim=c(50, 50, 3)))
+ mybeh <- sienaDependent(s50a, type='behavior')
+ mydata <- sienaDataCreate(mynet1, mybeh)
+ myeff <- getEffects(mydata)
+ myeff <- includeEffects(myeff, transTrip, cycle3, nbrDist2)
+ myeff <- includeEffects(myeff, outdeg, name="mybeh",
+ interaction1="mynet1")
+ myeff <- includeEffects(myeff, outdeg, name="mybeh",
+ interaction1="mynet1")
+ myalgorithm <- sienaAlgorithmCreate(n3=500)
+ # Short phase 3, just for example.
+ (ans2 <- siena07(myalgorithm, data=mydata, effects=myeff, returnDeps=TRUE))
+
+ gofc <- sienaGOF(ans2, ConstraintDistribution, varName="mynet1",
+ verbose=TRUE, join=TRUE)
+ plot(gofc)
+
+ goftc <- sienaGOF(ans2, TriadCensus, varName="mynet1", verbose=TRUE, join=TRUE)
+ plot(goftc, center=TRUE, scale=TRUE)
+ # For this type of auxiliary statistics it is advisable to center and scale.
+ # note the keys at the x-axis; these names are given by sna::triad.census
+
+ gofgd <- sienaGOF(ans2, GeodesicDistribution, varName="mynet1",
+ verbose=TRUE, join=TRUE, cumulative=FALSE)
+ plot(gofgd)
+ # and without infinite distances:
+ gofgdd <- sienaGOF(ans2, GeodesicDistribution, varName="mynet1",
+ verbose=TRUE, join=TRUE, levls=1:7, cumulative=FALSE)
+ plot(gofgdd)
+ }
+}
+\keyword{models}
Added: pkg/RSiena/man/sienaGOF.Rd
===================================================================
--- pkg/RSiena/man/sienaGOF.Rd (rev 0)
+++ pkg/RSiena/man/sienaGOF.Rd 2013-04-20 12:55:08 UTC (rev 228)
@@ -0,0 +1,198 @@
+\name{sienaGOF}
+\alias{sienaGOF}
+\alias{plot.sienaGOF}
+\title{Functions to assess goodness of fit for SAOMs}
+\description{
+ The function \code{sienaGOF} assesses goodness of fit
+ for a model specification as represented by an estimated
+ \code{sienaFit} object. This is done by simulations of auxiliary
+ statistics, that differ from the statistics used for estimating
+ the parameters. The auxiliary statistics must be given explicitly.
+ The fit is good if the average values
+ of the auxiliary statistics over many simulation runs are close
+ to the values observed in the data.
+ A Monte Carlo test based on the Mahalanobis
+ distance is used to calculate frequentist \eqn{p}-values.
+ Plotting functions can be used to diagnose bad fit. There are basic
+ functions for calculating auxiliary statistics available out of the
+ box, and the user is also permitted to create custom functions.
+ }
+
+\usage{
+sienaGOF(sienaFitObject, auxiliaryFunction,
+ period=NULL, verbose=FALSE, join=TRUE, twoTailed=FALSE,
+ cluster=NULL, robust=FALSE, groupName="Data1",
+ varName, \dots)
+\method{plot}{sienaGOF}(x, center=FALSE, scale=FALSE, violin=TRUE, key=NULL,
+ perc=.05, period=1, main=main, ylab=ylab, \dots)
+}
+\arguments{
+ \item{sienaFitObject}{Results from a call to \code{\link{siena07}}
+ with \code{returnDeps = TRUE}.}
+ \item{auxiliaryFunction}{Function to be used to calculate
+ the auxiliary statistics;
+ this can be a user-defined function, e.g. depending on the \code{sna}
+ or \code{igraph} packages.
+
+ See \code{Examples} and \code{\link{sienaGOF-auxiliary}}
+ for more information on the signature of this function.
+ The basic signature is
+ \code{function(index, data, sims, period, groupName, varName, \dots)},
+ where \code{index} is the index of the simulated network,
+ or \code{NULL} if the observed variable is needed;
+ \code{data} is the observed data object from which
+ the relevant variables are extracted; \code{sims} is the list of simulations
+ returned from \code{siena07}; \code{period} is the index of the period;
+ and \dots are further arguments (like \code{levls} in the examples below
+ and in \code{\link{sienaGOF-auxiliary}}).}
+ \item{period}{Vector of period(s) to be used (may run from 1 to
+ number of waves - 1). Has an effect only if \code{join=FALSE}.}
+ \item{verbose}{Whether to print intermediate results. This may give some
+ 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,
+ as it is probably only applicable in rare cases.}
+ \item{cluster}{Optionally, a \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{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.}
+ \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{main}{ Main title of the plot. }
+ \item{ylab}{ The y-axis label for the plot. }
+ \item{\dots}{Other arguments.}
+}
+\details{
+ This function is used to assess the goodness of fit of a stochastic actor
+ oriented model for an arbitrarily defined multidimensional auxiliary statistic.
+ The auxiliary statistics are calculated for the simulated dependent
+ variables in Phase 3 of the estimation algorithm,
+ returned in \code{sienaFitObject} because of having used
+ \code{returnDeps = TRUE} in the call to \code{\link{siena07}}.
+ These statistics should be chosen to represent features of the network
+ that are not explicitly fit by the estimation procedure but can be
+ considered important properties that the model at hand should represent well.
+ Some examples are:
+ \itemize{
+ \item Outdegree distribution
+ \item Indegree distribution
+ \item Distribution of the dependent behavior variable (if any).
+ \item Distribution of geodesic distances
+ \item Triad census
+ \item Edgewise homophily counts
+ \item Edgewise shared partner counts
+ \item Statistics depending on the combination of network
+ and behavioral variables.
+}
+The function is written so that the user can easily define other functions to
+capture some other relevant aspects of the network, behaviors, etc.
+This is further illustrated in the help page \code{\link{sienaGOF-auxiliary}}.
+
+We recommend the following heuristic approach to model checking:
+\enumerate{
+ \item Check convergence of the estimation.
+ \item Assess time heterogeneity by \code{\link{sienaTimeTest}}
+ and if there is evidence for time heterogeneity
+ either modify the base effects or include time dummy terms.
+ \item Assess goodness of fit (primarily using \code{join=TRUE}) on
+ auxiliary statistics, and if necessary refine the model.
+}
+
+ The \code{print} function will display some useful information
+ to help with model selection if some effects are set to FIX and
+ TEST on the effects object. A rough estimator for the Mahalanobis
+ distance that would be obtained at each proposed specification
+ is given in the output. This can help guide model selection.
+ This estimator is called the modified Mahalanobis distance (MMD).
+ See Lospinoso (2012), the manual, or the references for more information.
+
+ The following functions are pre-fabricated for ease of use, and can
+ be passed in as the \code{auxiliaryFunction} with no extra effort;
+ see \code{\link{sienaGOF-auxiliary}} and the examples below.
+\itemize{
+ \item \code{\link{IndegreeDistribution}}
+ \item \code{\link{OutdegreeDistribution}}
+ \item \code{\link{BehaviorDistribution}}
+}
+
+}
+\value{
+ \code{sienaGOF} returns a result of class \code{sienaGOF};
+ this is a list of elements of class \code{sienaGofTest};
+ if \code{join=TRUE}, the list has length 1; if \code{join=FALSE},
+ each list element corresponds to a period analyzed;
+ the list elements are themselves lists again, including the
+ following elements:
+ \describe{
+ \item{* Observations}{The observed values for the auxiliary statistics.}
+ \item{* Simulations}{The simulated auxiliary statistics.}
+ \item{* ObservedTestStat}{The observed Mahalobis distance in the data.}
+ \item{* SimulatedTestStat}{The Mahalobis distance for the simulations.}
+ \item{* TwoTailed}{Whether the \eqn{p}-value corresponds to a one- or
+ two-tailed Monte Carlo test.}
+ \item{* p}{The \eqn{p}-value for the observed Mahalanobis distance in the
+ permutation distribution of the simulated Mahalanobis distances.}
+ \item{* Rank}{ Rank of the covariance matrix of the simulated auxiliary
+ statistics.}
+ }
+}
+
+\references{
+\itemize{
+\item See \url{http://www.stats.ox.ac.uk/~snijders/siena/}
+ for general information on RSiena.
+\item Lospinoso, J.A. and Snijders, T.A.B., \dQuote{Goodness of fit for
+ Stochastic Actor Oriented Models.} Presentation given at Sunbelt XXXI,
+ St. Pete's Beach, Fl. 2011.
+\item Lospinoso, J.A. (2012).
+ \dQuote{Statistical Models for Social Network Dynamics.}
+ Ph.D. Thesis. University of Oxford: U.K.
+}
+}
+\author{Josh Lospinoso, modifications by Ruth Ripley and Tom Snijders}
+\seealso{\code{\link{siena07}}, \code{\link{sienaGOF-auxiliary}},
+ \code{\link{sienaTimeTest}} }
+\examples{
+\dontrun{
+ mynet1 <- sienaDependent(array(c(s501, s502, s503), dim=c(50, 50, 3)))
+ mynet2 <- sienaDependent(array(c(s503, s502, s501), dim=c(50, 50, 3)))
+ mybeh <- sienaDependent(s50a, type='behavior')
+ mydata <- sienaDataCreate(mynet1, mynet2, mybeh)
+ myeff <- getEffects(mydata)
+ myeff <- includeEffects(myeff, transTrip)
+ myeff <- includeEffects(myeff, recip, name="mynet2")
+ myeff <- setEffect(myeff, cycle3, fix=TRUE, test=TRUE, include=TRUE)
+ myeff <- setEffect(myeff, nbrDist2, fix=TRUE, test=TRUE, include=TRUE)
+ myeff <- setEffect(myeff, transTies, fix=TRUE, test=TRUE, include=TRUE)
+ myalgorithm <- sienaAlgorithmCreate(n3=200) # Shorter phase 3, just for example.
+ ans <- siena07(myalgorithm, data=mydata, effects=myeff, returnDeps=TRUE)
+ gofi <- sienaGOF(ans, IndegreeDistribution, verbose=TRUE, join=TRUE,
+ varName="mynet1")
+ gofi
+ plot(gofi)
+
+ gofi2 <- sienaGOF(ans, IndegreeDistribution, verbose=TRUE, join=TRUE,
+ varName="mynet2")
+ gofi2
+ plot(gofi2)
+
+ gofb <- sienaGOF(ans, BehaviorDistribution, varName = "mybeh",
+ verbose=TRUE, join=TRUE)
+ plot(gofb)
+
+ gofo <- sienaGOF(ans, OutdegreeDistribution, verbose=TRUE, join=TRUE,
+ varName="mynet1", cumulative=FALSE)
+ # cumulative is an example of "...".
+ gofo
+ plot(gofo)
+}
+}
+\keyword{models}
Added: pkg/RSiena/src/model/variables/DiffusionEffectValueTable.cpp
===================================================================
--- pkg/RSiena/src/model/variables/DiffusionEffectValueTable.cpp (rev 0)
+++ pkg/RSiena/src/model/variables/DiffusionEffectValueTable.cpp 2013-04-20 12:55:08 UTC (rev 228)
@@ -0,0 +1,96 @@
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
+ *
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: DiffusionEffectValueTable.cpp
+ *
+ * Description: This file contains the implementation of the
+ * DiffusionEffectValueTable class.
+ *****************************************************************************/
+using namespace std;
+#include <cmath>
+#include "DiffusionEffectValueTable.h"
+
+namespace siena
+{
+
+/**
+ * Creates a new look-up table for <i>n</i> actors.
+ */
+
+DiffusionEffectValueTable::DiffusionEffectValueTable(int numeratorRange,
+ int denominatorRange)
+{
+ this->lvalues = new double[numeratorRange * denominatorRange];
+ this->lparameterValues = new double[numeratorRange * denominatorRange];
+
+ // Calculate the table for parameter 0
+
+ this->lparameter = 0;
+ this->ldenominatorRange = denominatorRange;
+ this->lnumeratorRange = numeratorRange;
+
+ for (int i = 0; i < numeratorRange * denominatorRange; i++)
+ {
+ // exp(0) = 1
+
+ this->lvalues[i] = 1;
+ this->lparameterValues[i] = 0;
+ }
+}
+
+/**
+ * Deallocates this look-up table.
+ */
+DiffusionEffectValueTable::~DiffusionEffectValueTable()
+{
+ delete[] this->lvalues;
+ delete[] this->lparameterValues;
+
+ this->lvalues = 0;
+ this->lparameterValues = 0;
+}
+
+
+/**
+ * Returns the current value of the effect parameter.
+ */
+double DiffusionEffectValueTable::parameter() const
+{
+ return this->lparameter;
+}
+
+
+/**
+ * Stores the effect parameter.
+ */
+void DiffusionEffectValueTable::parameter(double value)
+{
+ this->lparameter = value;
+}
+
+
+/**
+ * Returns the value of the effect.
+ */
+
+double DiffusionEffectValueTable::value(int numerator, int denominator)
+{
+ int arrayIndex = ((numerator - 1) * this->ldenominatorRange) +
+ (denominator - 1);
+
+ if (this->lparameterValues[arrayIndex] != this->lparameter)
+ {
+ // The value stored in the table was calculated for a different
+ // parameter, hence we must recalculate the value.
+
+ this->lvalues[arrayIndex] = exp(this->lparameter *
+ (double)numerator / (double)denominator);
+ this->lparameterValues[arrayIndex] = this->lparameter;
+ }
+
+ return this->lvalues[arrayIndex];
+}
+
+}
Added: pkg/RSiena/src/model/variables/DiffusionEffectValueTable.h
===================================================================
--- pkg/RSiena/src/model/variables/DiffusionEffectValueTable.h (rev 0)
+++ pkg/RSiena/src/model/variables/DiffusionEffectValueTable.h 2013-04-20 12:55:08 UTC (rev 228)
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
+ *
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: DiffusionEffectValueTable.h
+ *
+ * Description: This file contains the definition of the
+ * DiffusionEffectValueTable class.
+ *****************************************************************************/
+
+#ifndef DIFFUSIONEFFECTVALUETABLE_H_
+#define DIFFUSIONEFFECTVALUETABLE_H_
+
+namespace siena
+{
+
+/**
+ * This class provides a look-up table supporting effective calculation of
+ * diffusion effects on rate functions. The value of the effect for an
+ * argument <i>i</i> in [0, <i>n</i>) is defined as
+ * exp(alpha <i>f</i>(<i>i</i>)), where alpha is a parameter associated
+ * with this effect and <i>f</i> is an arbitrary function. Since calculating
+ * exponentials is expensive, the values are stored for each <i>i</i> for
+ * later reuse as long as the parameter remains unchanged.
+ */
+class DiffusionEffectValueTable
+{
+public:
+ DiffusionEffectValueTable(int numeratorRange, int denominatorRange);
+ virtual ~DiffusionEffectValueTable();
+
+ double parameter() const;
+ void parameter(double value);
+ double value(int i);
+ double value(int numerator, int denominator);
+
+private:
+ // The look-up table for effect values
+ double * lvalues;
+
+ // Here we remember the parameter value whenever we store a value
+ // in the table.
+
+ double * lparameterValues;
+
+ // The actual value of the effect parameter
+ double lparameter;
+
+ // The range of the denominator;
+ int ldenominatorRange;
+
+ // The range of the numerator;
+ int lnumeratorRange;
+
+};
+
+}
+
+#endif /*DIFFUSIONEFFECTVALUETABLE_H_*/
More information about the Rsiena-commits
mailing list