[Rsiena-commits] r268 - in pkg: RSiena RSiena/R RSiena/man RSienaTest

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Apr 8 22:21:35 CEST 2014


Author: natalie
Date: 2014-04-08 22:21:33 +0200 (Tue, 08 Apr 2014)
New Revision: 268

Added:
   pkg/RSiena/man/sienaRI.Rd
Modified:
   pkg/RSiena/DESCRIPTION
   pkg/RSiena/NAMESPACE
   pkg/RSiena/R/sienaRIDynamics.r
   pkg/RSiena/changeLog
   pkg/RSienaTest/DESCRIPTION
   pkg/RSienaTest/changeLog
Log:
added Rd-file for sienaRI, bugfix in sienaRIDynamics.r

Modified: pkg/RSiena/DESCRIPTION
===================================================================
--- pkg/RSiena/DESCRIPTION	2014-03-30 21:14:41 UTC (rev 267)
+++ pkg/RSiena/DESCRIPTION	2014-04-08 20:21:33 UTC (rev 268)
@@ -1,8 +1,8 @@
 Package: RSiena
 Type: Package
 Title: Siena - Simulation Investigation for Empirical Network Analysis
-Version: 1.1-267
-Date: 2014-03-30
+Version: 1.1-268
+Date: 2014-04-08
 Author: Ruth Ripley, Krists Boitmanis, Tom A.B. Snijders
 Depends: R (>= 2.15.0)
 Imports: Matrix

Modified: pkg/RSiena/NAMESPACE
===================================================================
--- pkg/RSiena/NAMESPACE	2014-03-30 21:14:41 UTC (rev 267)
+++ pkg/RSiena/NAMESPACE	2014-04-08 20:21:33 UTC (rev 268)
@@ -7,7 +7,7 @@
        varCovar, varDyadCovar, setEffect, includeEffects, includeInteraction,
        effectsDocumentation, sienaDataConstraint, print.xtable.sienaFit,
        installGui, siena08, iwlsm, sienaTimeTest, includeTimeDummy, 
-       sienaGOF, descriptives.sienaGOF, sparseMatrixExtraction,
+       sienaGOF, descriptives.sienaGOF, sienaRI, sienaRIDynamics, sparseMatrixExtraction,
        networkExtraction, behaviorExtraction,
        OutdegreeDistribution, IndegreeDistribution, BehaviorDistribution,
        siena.table, xtable,
@@ -49,4 +49,10 @@
 S3method(summary, sienaGOF)
 S3method(print, sienaGOF)
 S3method(plot, sienaGOF)
+S3method(summary, sienaRI)
+S3method(print, sienaRI)
+S3method(plot, sienaRI)
+S3method(summary, sienaRIDynamics)
+S3method(print, sienaRIDynamics)
+S3method(plot, sienaRIDynamics)
 S3method(print, chains.data.frame)

Modified: pkg/RSiena/R/sienaRIDynamics.r
===================================================================
--- pkg/RSiena/R/sienaRIDynamics.r	2014-03-30 21:14:41 UTC (rev 267)
+++ pkg/RSiena/R/sienaRIDynamics.r	2014-04-08 20:21:33 UTC (rev 268)
@@ -10,20 +10,20 @@
 # *****************************************************************************/
 
 ##@sienaRIDynamics. Use as RSiena:::sienaRIDynamics()
-sienaRIDynamics <- function(data, ans=NULL, algorithm=NULL, effects=NULL, theta=NULL , depvar=NULL, intervalsPerPeriod=NULL)
+sienaRIDynamics <- function(data, ans=NULL, effects=NULL, algorithm=NULL, theta=NULL , depvar=NULL, intervalsPerPeriod=NULL)
 {
 	if(length(data$depvars)>1){
 		if(is.null(depvar)){
+			currentNetName <- attr(data$depvars,"names")[1]
 			warning("If the models contains more than one dependent variables, \n it should be specified by variable 'depvar' for which dependent variable the relative importances should be calculated. \n\n")
 			warning(paste("As 'depvar = NULL', relative importances are calculated for variable ", currentNetName, sep=""))
-			currentNetName <- attr(data$depvars,"names")[1]
 		}else if(!(depvar %in% attr(data$depvars,"names"))){
 			stop("'depvar' is not a name of a dependent variable")
 		}else{
 			currentNetName <- depvar
 		}
 	}else{
-		currentNetName <- depvar
+		currentNetName <- attr(data$depvars,"names")[1]
 	}
 	if (!inherits(data, "siena"))
 	{
@@ -35,15 +35,28 @@
 		{
 			stop("ans is not a legitimate Siena fit object")
 		}
-		if(!is.null(algorithm)||!is.null(theta)||!is.null(effects))
-		{
-			warning("some information are multiply defined \n results will be based on 'theta', 'algorithm', and 'effects' stored in 'ans' (as 'ans$theta', 'ans$x', 'ans$effects')")
-		}
+		if(ans$cconditional){
+			if(is.null(effects))
+			{
+				stop("effects = NULL! In case of conditional estimation, the 'sienaEffects' object has to be given to function sienRIDynamics directly.")
+			}
+			if(!inherits(effects, "sienaEffects"))
+			{
+				stop("effects is not a legitimate Siena effects object")
+			}
+			effs <- effects
+		}else{
+			if(!is.null(algorithm)||!is.null(theta)||!is.null(effects))
+			{
+				warning("some information are multiply defined \n results will be based on 'theta', 'algorithm', and 'effects' stored in 'ans' (as 'ans$theta', 'ans$x', 'ans$effects')")
+			}
+			effs <- ans$effects
+		}	
 		if(!is.null(intervalsPerPeriod))
 		{
 			if(is.numeric(intervalsPerPeriod))
 			{
-				intervalsPerPeriod <- as.integer(intervalsPerPeriods)
+				intervalsPerPeriod <- as.integer(intervalsPerPeriod)
 			}else{
 				intervalsPerPeriod <- NULL
 				warning("'intervalsPerPeriod' has to be of type 'numeric' \n used default settings")
@@ -53,7 +66,7 @@
 		{
 			intervalsPerPeriod <- 10
 		}
-		RIValues <- calculateRIDynamics(data = data, theta= ans$theta, algorithm = ans$x,  effects = ans$effects, depvar = currentNetName, intervalsPerPeriod=intervalsPerPeriod)	
+		RIValues <- calculateRIDynamics(data = data, theta= c(ans$rate,ans$theta), algorithm = ans$x,  effects = effs, depvar = currentNetName, intervalsPerPeriod=intervalsPerPeriod)	
 	}else{
 		if (!inherits(algorithm, "sienaAlgorithm"))
 		{
@@ -82,7 +95,7 @@
 		{
 			if(is.numeric(intervalsPerPeriod))
 			{
-				intervalsPerPeriod <- as.integer(intervalsPerPeriods)
+				intervalsPerPeriod <- as.integer(intervalsPerPeriod)
 			}else{
 				intervalsPerPeriod <- NULL
 				warning("'intervalsPerPeriod' has to be of type 'numeric' \n used default settings")
@@ -264,7 +277,7 @@
 
 
 ##@plot.sienaRIDynamics Methods
-plot.sienaRIDynamics <- function(x, staticValues = NULL, file = NULL, col = NULL, ylim=NULL, width = NULL, height = NULL, legend = TRUE, legendColumns = NULL, legendHeight = NULL, cex.scale = NULL, cex.legend = NULL, cex.axis = NULL, cex.names = NULL, ylab = "", xlab = "", ...)
+plot.sienaRIDynamics <- function(x, staticValues = NULL, file = NULL, col = NULL, ylim=NULL, width = NULL, height = NULL, legend = TRUE, legendColumns = NULL, legendHeight = NULL, cex.legend = NULL, ...)
 { 
 	if (!inherits(x, "sienaRIDynamics"))
 	{
@@ -284,7 +297,7 @@
 		}
 		if(is.null(legendColumns))
 		{
-			legendColumns <- 3
+			legendColumns <- 2
 		}
 		if(!is.null(legendHeight))
 		{
@@ -336,21 +349,6 @@
 		width <- 8
 	}
 	
-	if(!is.null(cex.scale))
-	{
-		if(is.numeric(cex.scale))
-		{
-			cex.scale <- cex.scale
-		}else{
-			cex.scale <- NULL
-			warning("cex.scale has to be of type 'numeric' \n used default settings")
-		}
-	}
-	if(is.null(cex.scale))
-	{
-		cex.scale <- 1
-	}
-	
 	if(!is.null(cex.legend))
 	{
 		if(is.numeric(cex.legend))
@@ -366,36 +364,6 @@
 		cex.legend <- 1
 	}
 	
-	if(!is.null(cex.names))
-	{
-		if(is.numeric(cex.names))
-		{
-			cex.names <- cex.names
-		}else{
-			cex.names <- NULL
-			warning("cex.names has to be of type 'numeric' \n used default settings")
-		}
-	}
-	if(is.null(cex.names))
-	{
-		cex.names <- 1
-	}
-	
-	if(!is.null(cex.axis))
-	{
-		if(is.numeric(cex.axis))
-		{
-			cex.axis <- cex.axis
-		}else{
-			cex.axis <- NULL
-			warning("cex.axis has to be of type 'numeric' \n used default settings")
-		}
-	}
-	if(is.null(cex.axis))
-	{
-		cex.axis <- 1
-	}
-	
 	createPdf = FALSE
 	if(!is.null(file))
 	{
@@ -460,14 +428,14 @@
 	}
 	if(legend)
 	{
-		layout(rbind(1:periods, rep(periods+1,periods)),widths=rep(4, periods),heights=c(3,1))
+		layout(rbind(1:periods, rep(periods+1,periods)),widths=rep(4, periods),heights=c(3,legendHeight))
 	}else{
 		layout(rbind(1:periods),widths=rep(4, periods),heights=c(3))
 	}
 	par( oma = c( 1, 3, 1, 3 ),mar = par()$mar+c(-5,-4.1,-4,-2.1), xpd=T ) 
 	for(period in 1:periods){
 		timeseries<-ts(t(values[[period]]))
-		plot.ts(timeseries, plot.type = "single",  col = cl, lty = lineTypes, lwd = rep(1.5,effectNumber), bty = "n",xaxt = "n",yaxt = "n", ylab = ylab, xlab = xlab, ylim = ylim)
+		plot.ts(timeseries, plot.type = "single",  col = cl, lty = lineTypes, lwd = rep(1.5,effectNumber), bty = "n",xaxt = "n",yaxt = "n", ylab ="", xlab = "", ylim = ylim)
 		for(eff in 1:effectNumber)
 		{
 			points(ts(t(values[[period]]))[,eff], col = cl[eff], type = "p", pch = 20)

Modified: pkg/RSiena/changeLog
===================================================================
--- pkg/RSiena/changeLog	2014-03-30 21:14:41 UTC (rev 267)
+++ pkg/RSiena/changeLog	2014-04-08 20:21:33 UTC (rev 268)
@@ -1,3 +1,9 @@
+2014-04-08 R-Forge Revision 268
+Changes in RSiena:
+   * sienaRI.Rr: added
+   * sienaRIDynamics.r: bugfix
+   * NAMESPACE: added entries sienaRI and sienaRIDynamics with the corresponding print, summary, and plot methods
+
 2014-03-30 R-Forge Revision 267
 Changes in RSiena:
 Added R-files that contain functionalities to calculate, print and plot relative importances of effects

Added: pkg/RSiena/man/sienaRI.Rd
===================================================================
--- pkg/RSiena/man/sienaRI.Rd	                        (rev 0)
+++ pkg/RSiena/man/sienaRI.Rd	2014-04-08 20:21:33 UTC (rev 268)
@@ -0,0 +1,94 @@
+\name{sienaRI}
+\alias{sienaRI}
+\alias{plot.sienaRI}
+\title{Functions to assess the relative importance of effects at observation moments}
+\description{
+ The function \code{sienaRI} returns the relative importance of effects of a SAOM according to the measure of relative importance described in
+ Section 3.2 of Indlekofer and Brandes (2013). 
+ The measure is based on the influence of effects on potential tie change or behavior change
+ decisions of individual actors in network at the given observation moments. It takes the data as well as the complete model specification into account. Therefore, necessary arguments are the analysed data given as a \code{siena} data object as well as the complete model specification represented either by an estimated \code{sienaFit} object or by the triple consisting of a suitable parameter vector \code{theta} and the corresponding \code{sienaAlgorithm} and \code{sienaEffects} objects.
+ }
+\usage{
+sienaRI(data, ans=NULL, theta=NULL, algorithm=NULL, effects=NULL)
+\method{plot}{sienaRI}(x, file = NULL, col = NULL, addPieChart = FALSE, radius = 1, width = NULL, height = NULL, legend = TRUE, legendColumns = NULL, legendHeight = NULL, cex.legend = NULL, cex.names = NULL,\dots)
+}
+\arguments{
+  \item{data}{\code{siena} data object representing the analyzed data and resulting from a call to \code{\link{sienaDataCreate}}.}
+  \item{ans}{\code{sienaFit} object resulting from a call to \code{\link{siena07}}. The \code{sienaFit} object contains all necessary information on the model specification, in particular, the vector of parameter values \code{ans$theta}, the used algorithm for estimation \code{ans$x}, and information on included model effects \code{ans$effects}. If \code{ans} is a valid \code{sienaFit} object, the calculations of relative importances are based on \code{ans$theta}, \code{ans$x}, and \code{ans$effects}. Alternatively, the necessary information can be given directly as a suitable parameter vector \code{theta}, a \code{sienaAlgorithm} object, and a \code{sienaEffects} object. In this case, \code{ans} has to be unspecified (i.e., \code{ans=NULL}).}
+  \item{theta}{Vector of parameter values of effects included in the model. Length of \code{theta} has to be equal to the number of included effects.}
+  \item{algorithm}{\code{sienaAlgorithm} object as resulting from a call to \code{\link{sienaAlgorithmCreate}}. Works only for estimation by Method of Moments (i.e., if  \code{maxlike = FALSE}).}
+  \item{effects}{\code{sienaEffects} object specifying which effects are included the model. Note that \code{sienaRI} does not yet work for endowment or creation effect, i.e., included effects have to be of type \code{eval} (or \code{rate}).}
+  \item{x}{\code{sienaRI} object resulting from a call to \code{sienaRI}.}
+  \item{file}{Name (path) of a pdf-file indicating whether the plot should be stored in a file. If \code{file=NULL}, the plot will be opened in a separate window. Otherwise a pdf with the given name will be created in the working directory or at the given path.}
+  \item{col}{Colors used in the plot. If \code{col=NULL} a default color scheme is used.}
+  \item{addPieChart}{Boolean: If \code{TRUE}, pie charts of aggregated relative importances for the complete network will be added to the plot.}
+  \item{radius}{Radius of pie charts. Only effective if \code{addPieCharts = TRUE}.}
+  \item{width}{Width of the plot. If \code{width=NULL} a default value is used.}
+  \item{height}{Height of the plot. If \code{height=NULL} a default value is used.}
+  \item{legend}{Boolean: if \code{TRUE} a legend is added to the plot. \code{x$effectNames} are used as labels.}
+  \item{legendCol}{Number of columns in legend. If \code{legendCol=NULL} a default value is used. Only effective if \code{legend=TRUE}.}
+  \item{legendHeight}{Height of legend. If \code{legendHeight=NULL} a default value is used. Only effective if \code{legend=TRUE}.}
+  \item{cex.legend}{Specifies the relative font size of legend labels.}
+  \item{cex.names}{Specifies the relative font size of bar graph labels.}
+  \item{\dots}{Other arguments.}
+}
+\details{
+\code{sienaRI} takes the data as well as the complete model specification into account. Therefore, necessary arguments are the analyzed data given as a \code{siena} data object as well as the complete model specification represented either by an estimated \code{sienaFit} object or by the triple consisting of a suitable parameter vector \code{theta} and the corresponding \code{sienaAlgorithm} and \code{sienaEffects} objects.
+
+A \code{sienaFit} object contains all necessary information on the model specification, in particular, the vector of parameter values \code{ans$theta}, the used algorithm for estimation \code{ans$x}, and information on included model effects \code{ans$effects}.
+
+If \code{ans} is a valid \code{sienaFit} object, the calculations of relative importances are based on \code{ans$theta}, \code{ans$x}, and \code{ans$effects}.\\ Alternatively, the necessary information can be given directly as a suitable parameter vector \code{theta}, a \code{sienaAlgorithm} object, and a \code{sienaEffects} object. In this case, \code{ans} has to be unspecified, i.e., \code{ans=NULL}.
+
+Note that \code{sienaRI} works only with Method of Moments (i.e., for \code{sienaAlgorithm} objects with \code{maxlike = FALSE}) and that it does not yet work for endowment or creation effect (i.e., included effects have to be of type \code{eval}).
+}
+\value{
+ If the model contains only one dependent variable, \code{sienaRI} returns an object of class \code{sienaRI}. Otherwise, it returns a list of objects of class \code{sienaRI}, each corresponding to one dependent variable.
+ 
+ A returned \code{sienaRI} object stores the expected relative importances of effects of one dependent variable at observation moments as defined in Section 3.2 of Indlekofer and Brandes (2013).
+
+A \code{sienaRI} object consists of following components:
+    \describe{
+    \item{- \code{dependentVariable}}{the name of the corresponding dependent variable.}
+    \item{- \code{effectNames}}{the names of considered effects.}
+    \item{- \code{RIActors}}{is a list that contains the expected relative importances of effects for each potential actor decision at observation moments.}
+    \item{- \code{expectedRI}}{is a list that contains the expected relative importances of effects aggregated over all actors in each network observations. More precisely, it contains the averages of the actor related values in \code{RIActors}.}
+    \item{- \code{absoluteSumActors}}{is a list that contains the sum of the (unstandardized) L1-differences calculated for each potential actor decision at observation moments. (Cf. Section 3.2 of Indlekofer and Brandes (2013))}
+    \item{- \code{entropyActors}}{is a list that contains the entropy of each potential actor decision at observation moments.}
+    }
+}
+
+\references{
+\itemize{
+Indlekofer, N. and Brandes, U., 
+ \dQuote{Relative Importance of Effects in Stochastic Actor-oriented Models.}
+ Network Science, 1 (3), 2013.
+}
+}
+\author{Natalie Indlekofer}
+\seealso{\code{\link{sienaRIDynamics}}}
+\examples{
+myalgorithm <- sienaAlgorithmCreate(nsub=2, n3=100)
+mynet1 <- sienaDependent(array(c(tmp3, tmp4), dim=c(32, 32, 2)))
+mydata <- sienaDataCreate(mynet1)
+myeff <- getEffects(mydata)
+myeff <- includeEffects(myeff, density, recip, transTies, nbrDist2)
+ans <- siena07(myalgorithm, data=mydata, effects=myeff, batch=TRUE)
+
+RI <- sienaRI(mydata, ans)
+RI
+plot(RI)
+
+myalgorithm <- sienaAlgorithmCreate(nsub=2, n3=100)
+mynet2 <- sienaDependent(array(c(s501, s502, s503), dim=c(50, 50, 3)))
+mybeh <- sienaDependent(s50a, type="behavior")
+mydata <- sienaDataCreate(mynet2, mybeh)
+myeff <- getEffects(mydata)
+myeff <- includeEffects(myeff, density, recip, transTies, nbrDist2)
+ans <- siena07(myalgorithm, data=mydata, effects=myeff, batch=TRUE)
+
+RI <- sienaRI(mydata, theta=ans$theta, algorithm=myalgorithm, effects = myeff)
+RI
+plot(RI[[2]], col = c("red", "green"), legend=FALSE)
+plot(RI[[1]], addPieChart = TRUE)
+}
+\keyword{models}
\ No newline at end of file

Modified: pkg/RSienaTest/DESCRIPTION
===================================================================
--- pkg/RSienaTest/DESCRIPTION	2014-03-30 21:14:41 UTC (rev 267)
+++ pkg/RSienaTest/DESCRIPTION	2014-04-08 20:21:33 UTC (rev 268)
@@ -1,8 +1,8 @@
 Package: RSienaTest
 Type: Package
 Title: Siena - Simulation Investigation for Empirical Network Analysis
-Version: 1.1-267
-Date: 2014-03-30
+Version: 1.1-28
+Date: 2014-04-08
 Author: Ruth Ripley, Krists Boitmanis, Tom A.B. Snijders
 Depends: R (>= 2.15.0)
 Imports: Matrix

Modified: pkg/RSienaTest/changeLog
===================================================================
--- pkg/RSienaTest/changeLog	2014-03-30 21:14:41 UTC (rev 267)
+++ pkg/RSienaTest/changeLog	2014-04-08 20:21:33 UTC (rev 268)
@@ -1,3 +1,9 @@
+2014-04-08 R-Forge Revision 268
+Changes in RSiena:
+   * sienaRI.Rr: added
+   * sienaRIDynamics.r: bugfix
+   * NAMESPACE: added entries sienaRI and sienaRIDynamics with the corresponding print, summary, and plot methods
+
 2014-03-30 R-Forge Revision 267
 Changes in RSiena:
 Added R-files that contain functionalities to calculate, print and plot relative importances of effects



More information about the Rsiena-commits mailing list