[Rsiena-commits] r206 - in pkg: RSiena RSienaTest RSienaTest/R RSienaTest/data RSienaTest/src RSienaTest/src/model RSienaTest/src/model/effects RSienaTest/src/model/variables

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 16 16:18:27 CET 2012


Author: cgreenan
Date: 2012-03-16 16:18:27 +0100 (Fri, 16 Mar 2012)
New Revision: 206

Modified:
   pkg/RSiena/DESCRIPTION
   pkg/RSiena/changeLog
   pkg/RSienaTest/DESCRIPTION
   pkg/RSienaTest/R/effects.r
   pkg/RSienaTest/R/effectsDocumentation.r
   pkg/RSienaTest/changeLog
   pkg/RSienaTest/data/allEffects.csv
   pkg/RSienaTest/src/model/StatisticCalculator.cpp
   pkg/RSienaTest/src/model/effects/DiffusionRateEffect.cpp
   pkg/RSienaTest/src/model/effects/DiffusionRateEffect.h
   pkg/RSienaTest/src/model/variables/DependentVariable.cpp
   pkg/RSienaTest/src/model/variables/DependentVariable.h
   pkg/RSienaTest/src/siena07internals.cpp
Log:


Modified: pkg/RSiena/DESCRIPTION
===================================================================
--- pkg/RSiena/DESCRIPTION	2012-03-07 20:07:54 UTC (rev 205)
+++ pkg/RSiena/DESCRIPTION	2012-03-16 15:18:27 UTC (rev 206)
@@ -1,8 +1,8 @@
 Package: RSiena
 Type: Package
 Title: Siena - Simulation Investigation for Empirical Network Analysis
-Version: 1.0.12.205
-Date: 2012-03-07
+Version: 1.0.12.206
+Date: 2012-03-16
 Author: Various
 Depends: R (>= 2.10.0)
 Imports: Matrix

Modified: pkg/RSiena/changeLog
===================================================================
--- pkg/RSiena/changeLog	2012-03-07 20:07:54 UTC (rev 205)
+++ pkg/RSiena/changeLog	2012-03-16 15:18:27 UTC (rev 206)
@@ -1,3 +1,14 @@
+2012-03-16 R-forge revision 206 (RSienaTest only)
+
+	* R/effects.R, R/effectsDocumentation.R: added a new behavior rate
+	effectGroup covarBehaviorOneModeRate
+	* data/allEffects.csv, siena07internals.cpp,
+	StatisticCalculator.cpp, DependentVariable.cpp,
+	DependentVariable.h, DiffusionRateEffect.cpp,
+	DiffusionRateEffect.h: added new diffusion behavior rate effects
+	susceptAvIn, susceptAvCovar, infectIn, infectOut, infectCovar,
+	totExposure
+
 2012-03-07 R-forge revision 205
 
 	* src/model/effects/CovariateDistance2AlterEffect.cpp,

Modified: pkg/RSienaTest/DESCRIPTION
===================================================================
--- pkg/RSienaTest/DESCRIPTION	2012-03-07 20:07:54 UTC (rev 205)
+++ pkg/RSienaTest/DESCRIPTION	2012-03-16 15:18:27 UTC (rev 206)
@@ -1,8 +1,8 @@
 Package: RSienaTest
 Type: Package
 Title: Siena - Simulation Investigation for Empirical Network Analysis
-Version: 1.0.12.205
-Date: 2012-03-07
+Version: 1.0.12.206
+Date: 2012-03-16
 Author: Various
 Depends: R (>= 2.10.0)
 Imports: Matrix

Modified: pkg/RSienaTest/R/effects.r
===================================================================
--- pkg/RSienaTest/R/effects.r	2012-03-07 20:07:54 UTC (rev 205)
+++ pkg/RSienaTest/R/effects.r	2012-03-16 15:18:27 UTC (rev 206)
@@ -812,10 +812,10 @@
                                          netType=netType)
         }
 
-       covRateEffects <- createEffects("covarBehaviorRate", varname, covarname,
+        covRateEffects <- createEffects("covarBehaviorRate", varname, covarname,
                                         name=name,
                                         groupName=groupName, group=group,
-                                         netType=netType)
+                                        netType=netType)
         ## if we have a real covariate, need to add other effects for every
         ## approriate network
         if (!same)
@@ -825,24 +825,33 @@
                 if (types[j] == 'oneMode' &&
                     attr(xx$depvars[[j]], 'nodeSet') == nodeSet)
                 {
-					newEffects <-
-						createEffects("covarBehaviorNetObjective", varname,
-									  covarname, names(xx$depvars)[j],
-									  groupName=groupName, group=group,
-									  netType=netType, name=name)
+                    newEffects <-
+                        createEffects("covarBehaviorNetObjective", varname,
+                                      covarname, names(xx$depvars)[j],
+                                      groupName=groupName, group=group,
+                                      netType=netType, name=name)
 
                     covObjEffects <- rbind(covObjEffects, newEffects)
-				}
+
+                    covOneModeRateEffects <-
+                        createEffects("covarBehaviorOneModeRate", varname,
+                                      yName=names(xx$depvars)[j],
+                                      zName=covarname,
+                                      groupName=groupName, group=group,
+                                      netType=netType, name=name)
+
+                    covRateEffects <- rbind(covRateEffects,covOneModeRateEffects)
+                }
                 if ((types[j] == "bipartite" &&
-                        attr(xx$depvars[[j]], 'nodeSet')[2] == nodeSet))
+                     attr(xx$depvars[[j]], 'nodeSet')[2] == nodeSet))
                 {
-  					newEffects <-
-						createEffects("covarBehaviorBipartiteObjective", varname,
-									  covarname, names(xx$depvars)[j],
-									  groupName=groupName, group=group,
-									  netType=netType, name=name)
-                  covObjEffects <- rbind(covObjEffects, newEffects)
-				}
+                    newEffects <-
+                        createEffects("covarBehaviorBipartiteObjective", varname,
+                                      covarname, names(xx$depvars)[j],
+                                      groupName=groupName, group=group,
+                                      netType=netType, name=name)
+                    covObjEffects <- rbind(covObjEffects, newEffects)
+                }
             }
         }
 

Modified: pkg/RSienaTest/R/effectsDocumentation.r
===================================================================
--- pkg/RSienaTest/R/effectsDocumentation.r	2012-03-07 20:07:54 UTC (rev 205)
+++ pkg/RSienaTest/R/effectsDocumentation.r	2012-03-16 15:18:27 UTC (rev 206)
@@ -35,6 +35,7 @@
 
                  "behaviorRate",
                  "behaviorOneModeRate",
+                 "covarBehaviorOneModeRate",
                  "behaviorBipartiteRate",
                  "covarBehaviorRate",
 

Modified: pkg/RSienaTest/changeLog
===================================================================
--- pkg/RSienaTest/changeLog	2012-03-07 20:07:54 UTC (rev 205)
+++ pkg/RSienaTest/changeLog	2012-03-16 15:18:27 UTC (rev 206)
@@ -1,3 +1,14 @@
+2012-03-16 R-forge revision 206 (RSienaTest only)
+
+	* R/effects.R, R/effectsDocumentation.R: added a new behavior rate
+	effectGroup covarBehaviorOneModeRate
+	* data/allEffects.csv, siena07internals.cpp,
+	StatisticCalculator.cpp, DependentVariable.cpp,
+	DependentVariable.h, DiffusionRateEffect.cpp,
+	DiffusionRateEffect.h: added new diffusion behavior rate effects
+	susceptAvIn, susceptAvCovar, infectIn, infectOut, infectCovar,
+	totExposure
+
 2012-03-07 R-forge revision 205
 
 	* src/model/effects/CovariateDistance2AlterEffect.cpp,

Modified: pkg/RSienaTest/data/allEffects.csv
===================================================================
--- pkg/RSienaTest/data/allEffects.csv	2012-03-07 20:07:54 UTC (rev 205)
+++ pkg/RSienaTest/data/allEffects.csv	2012-03-16 15:18:27 UTC (rev 206)
@@ -36,6 +36,12 @@
 behaviorOneModeRate,indegree effect on rate xxxxxx,Amount of change on xxxxxx x indegree,inRate,NA,yyyyyy,,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,NA,structural,0,0,0,0,
 behaviorOneModeRate,reciprocated effect on rate xxxxxx,Amount of change on xxxxxx x reciprocity,recipRate,NA,yyyyyy,,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,NA,structural,0,0,0,0,
 behaviorOneModeRate,average exposure effect on rate xxxxxx,Amount of change on xxxxxx x average exposure,avExposure,NA,yyyyyy,,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,NA,diffusion,0,0,0,0,
+behaviorOneModeRate,susceptibility to av. exp. by indegree effect on rate xxxxxx,Amount of change on xxxxxx x susceptibility by indegree,susceptAvIn,NA,yyyyyy,,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,NA,diffusion,0,0,0,0,
+behaviorOneModeRate,total exposure effect on rate xxxxxx,Amount of change on xxxxxx x total exposure,totExposure,NA,yyyyyy,,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,NA,diffusion,0,0,0,0,
+behaviorOneModeRate,infection by indegree effect on rate xxxxxx,Amount of change on xxxxxx x infection by indegree,infectIn,NA,yyyyyy,,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,NA,diffusion,0,0,0,0,
+behaviorOneModeRate,infection by outdegree effect on rate xxxxxx,Amount of change on xxxxxx x infection by outdegree,infectOut,NA,yyyyyy,,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,NA,diffusion,0,0,0,0,
+covarBehaviorOneModeRate,susceptibility to av. exp. by zzzzzz effect on rate xxxxxx,Amount of change on xxxxxx x susceptibility by zzzzzz,susceptAvCovar,NA,yyyyyy,zzzzzz,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,NA,diffusion,0,0,0,0,
+covarBehaviorOneModeRate,infection by zzzzzz effect on rate xxxxxx,Amount of change on xxxxxx x infection by zzzzzz,infectCovar,NA,yyyyyy,zzzzzz,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,NA,diffusion,0,0,0,0,
 behaviorBipartiteRate,outdegree effect on rate xxxxxx,Amount of change on xxxxxx x outdegree,outRate,NA,yyyyyy,,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,NA,structural,0,0,0,0,
 behaviorBipartiteRate,reciprocated effect on rate xxxxxx,Amount of change on xxxxxx x reciprocity,recipRate,NA,yyyyyy,,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,NA,structural,0,0,0,0,
 nonSymmetricRate,basic rate parameter xxxxxx,Amount of network change,Rate,NA,,,rate,FALSE,FALSE,FALSE,FALSE,FALSE,",",0,0,rate,1,NA,0,0,0,0,

Modified: pkg/RSienaTest/src/model/StatisticCalculator.cpp
===================================================================
--- pkg/RSienaTest/src/model/StatisticCalculator.cpp	2012-03-07 20:07:54 UTC (rev 205)
+++ pkg/RSienaTest/src/model/StatisticCalculator.cpp	2012-03-16 15:18:27 UTC (rev 206)
@@ -1006,6 +1006,7 @@
 		//	double parameter = pInfo->parameter();
 		string effectName = pInfo->effectName();
 		string interactionName = pInfo->interactionName1();
+		string interactionName2 = pInfo->interactionName2();
 		string rateType = pInfo->rateType();
 
 		if (rateType == "covariate")
@@ -1114,19 +1115,40 @@
 		}
 		else if (rateType == "diffusion")
 		{
-			NetworkLongitudinalData *pNetworkData = this->lpData->
-				pNetworkData(interactionName);
-			const Network * pStructural =
-				pNetworkData->pNetworkLessMissingStart(this->lperiod);
+		    NetworkLongitudinalData *pNetworkData = this->lpData->
+		        pNetworkData(interactionName);
+		    const Network * pStructural =
+		        pNetworkData->pNetworkLessMissingStart(this->lperiod);
 
-			double statistic = 0;
-			for (int i = 0; i < pBehaviorData->n(); i++)
-			{
-				if (effectName == "avExposure")
+		    double statistic = 0;
+		    for (int i = 0; i < pBehaviorData->n(); i++)
+		    {
+		        if (effectName == "avExposure")
 				{
 					double totalAlterValue = 0;
 					double averageAlterValue = 0;
 					if (pStructural->outDegree(i) > 0)
+					{
+						for (IncidentTieIterator iter = pStructural->outTies(i);
+							 iter.valid();
+							 iter.next())
+						{
+							double alterValue = pBehaviorData->
+								value(this->lperiod,iter.actor());
+							totalAlterValue += alterValue;
+						}
+						averageAlterValue = totalAlterValue /
+							pStructural->outDegree(i);
+					}
+
+					statistic += averageAlterValue *
+						difference[i];
+				}
+				else if (effectName == "susceptAvIn")
+				{
+					double totalAlterValue = 0;
+					double averageAlterValue = 0;
+					if (pStructural->outDegree(i) > 0)
 				    {
 						for (IncidentTieIterator iter = pStructural->outTies(i);
 							 iter.valid();
@@ -1140,9 +1162,155 @@
 							pStructural->outDegree(i);
 				    }
 
+					statistic += averageAlterValue * pStructural->inDegree(i) *
+						difference[i];
+				}
+				else if (effectName == "totExposure")
+				{
+					double totalAlterValue = 0;
+					double averageAlterValue = 0;
+					if (pStructural->outDegree(i) > 0)
+				    {
+						for (IncidentTieIterator iter = pStructural->outTies(i);
+							 iter.valid();
+							 iter.next())
+						{
+							double alterValue = pBehaviorData->
+								value(this->lperiod,iter.actor());
+							totalAlterValue += alterValue;
+						}
+						averageAlterValue = totalAlterValue;
+				    }
+
 					statistic += averageAlterValue *
 						difference[i];
 				}
+				else if (effectName == "susceptAvCovar")
+				{
+					ConstantCovariate * pConstantCovariate =
+						this->lpData->pConstantCovariate(interactionName2);
+					ChangingCovariate * pChangingCovariate =
+						this->lpData->pChangingCovariate(interactionName2);
+					double totalAlterValue = 0;
+					double averageAlterValue = 0;
+					if (pStructural->outDegree(i) > 0)
+					{
+					    for (IncidentTieIterator iter = pStructural->outTies(i);
+							 iter.valid();
+							 iter.next())
+						{
+							double alterValue = pBehaviorData->
+								value(this->lperiod,iter.actor());
+							totalAlterValue += alterValue;
+						}
+						averageAlterValue = totalAlterValue /
+							pStructural->outDegree(i);
+					}
+					if (pConstantCovariate)
+					{
+					    statistic += averageAlterValue *
+							pConstantCovariate->value(i) *
+					        difference[i];
+					}
+					else if (pChangingCovariate)
+					{
+					    statistic += averageAlterValue *
+							pChangingCovariate->value(i,this->lperiod) *
+							difference[i];
+					}
+					else
+					{
+						throw logic_error(
+							"No individual covariate named '" +
+							interactionName2 +
+							"'.");
+					}
+				}
+				else if (effectName == "infectIn")
+				{
+					double totalAlterValue = 0;
+					double averageAlterValue = 0;
+					if (pStructural->outDegree(i) > 0)
+				    {
+						for (IncidentTieIterator iter = pStructural->outTies(i);
+							 iter.valid();
+							 iter.next())
+						{
+							double alterValue = pBehaviorData->
+								value(this->lperiod,iter.actor()) *
+								pStructural->inDegree(iter.actor());
+							totalAlterValue += alterValue;
+						}
+						averageAlterValue = totalAlterValue;
+				    }
+
+					statistic += averageAlterValue *
+					    difference[i];
+				}
+				else if (effectName == "infectOut")
+				{
+					double totalAlterValue = 0;
+					double averageAlterValue = 0;
+					if (pStructural->outDegree(i) > 0)
+				    {
+						for (IncidentTieIterator iter = pStructural->outTies(i);
+							 iter.valid();
+							 iter.next())
+						{
+							double alterValue = pBehaviorData->
+								value(this->lperiod,iter.actor()) *
+								pStructural->outDegree(iter.actor());
+							totalAlterValue += alterValue;
+						}
+						averageAlterValue = totalAlterValue;
+				    }
+
+					statistic += averageAlterValue *
+						difference[i];
+				}
+				else if (effectName == "infectCovar")
+				{
+					ConstantCovariate * pConstantCovariate =
+						this->lpData->pConstantCovariate(interactionName2);
+					ChangingCovariate * pChangingCovariate =
+						this->lpData->pChangingCovariate(interactionName2);
+					double totalAlterValue = 0;
+					double averageAlterValue = 0;
+					if (pStructural->outDegree(i) > 0)
+					{
+					    for (IncidentTieIterator iter = pStructural->outTies(i);
+							 iter.valid();
+							 iter.next())
+						{
+							double alterValue = pBehaviorData->
+								value(this->lperiod,iter.actor());
+
+							if (pConstantCovariate)
+							{
+								alterValue *= pConstantCovariate->
+									value(iter.actor());
+							}
+							else if (pChangingCovariate)
+							{
+								alterValue *= pChangingCovariate->
+									value(iter.actor(), this->lperiod);
+							}
+							else
+							{
+								throw logic_error(
+									"No individual covariate named '" +
+									interactionName2 +
+									"'.");
+							}
+							totalAlterValue += alterValue;
+						}
+						averageAlterValue = totalAlterValue;
+					}
+
+					statistic += averageAlterValue *
+						difference[i];
+				}
+
 				else
 				{
 				    throw domain_error("Unexpected rate effect " + effectName);

Modified: pkg/RSienaTest/src/model/effects/DiffusionRateEffect.cpp
===================================================================
--- pkg/RSienaTest/src/model/effects/DiffusionRateEffect.cpp	2012-03-07 20:07:54 UTC (rev 205)
+++ pkg/RSienaTest/src/model/effects/DiffusionRateEffect.cpp	2012-03-16 15:18:27 UTC (rev 206)
@@ -9,12 +9,15 @@
  * DiffusionRateEffect.
  *****************************************************************************/
 
+#include <cmath>
 #include "DiffusionRateEffect.h"
 #include "utils/Utils.h"
 #include "network/OneModeNetwork.h"
 #include "model/variables/NetworkVariable.h"
 #include "model/variables/BehaviorVariable.h"
 #include "model/variables/DiffusionEffectValueTable.h"
+#include "data/ConstantCovariate.h"
+#include "data/ChangingCovariate.h"
 #include "network/IncidentTieIterator.h"
 #include <R_ext/Print.h>
 
@@ -49,11 +52,80 @@
 		possibleDegreeDenom = max(this->lpVariable->n(),
 			this->lpVariable->m());
 	}
+	if (this->ltype == SUSCEPT_AVERAGE_INDEGREE_RATE)
+	{
+		possibleDegreeNumer = (this->lpBehaviorVariable->range()) *
+			max(this->lpVariable->n(),
+				this->lpVariable->m()) *
+			max(this->lpVariable->n(),
+				this->lpVariable->m());
+		possibleDegreeDenom = max(this->lpVariable->n(),
+			this->lpVariable->m());
+	}
+	if (this->ltype == TOTAL_EXPOSURE_RATE)
+	{
+		possibleDegreeNumer = (this->lpBehaviorVariable->range()) *
+			max(this->lpVariable->n(),
+				this->lpVariable->m());
+		possibleDegreeDenom = 1;
+	}
+	if (this->ltype == INFECTION_INDEGREE_RATE)
+	{
+		possibleDegreeNumer = (this->lpBehaviorVariable->range()) *
+			max(this->lpVariable->n(),
+				this->lpVariable->m()) *
+			max(this->lpVariable->n(),
+				this->lpVariable->m());
+		possibleDegreeDenom = 1;
+	}
+	if (this->ltype == INFECTION_OUTDEGREE_RATE)
+	{
+	   	possibleDegreeNumer = (this->lpBehaviorVariable->range()) *
+			max(this->lpVariable->n(),
+				this->lpVariable->m()) *
+			max(this->lpVariable->n(),
+				this->lpVariable->m());
+		possibleDegreeDenom = 1;
+	}
 	this->lpTable = new DiffusionEffectValueTable(possibleDegreeNumer,
 		possibleDegreeDenom);
 	this->lpTable->parameter(parameter);
 }
 
+DiffusionRateEffect::DiffusionRateEffect(const NetworkVariable * pVariable,
+	const BehaviorVariable * pBehaviorVariable,
+	const ConstantCovariate * pConstantCovariate,
+	const ChangingCovariate * pChangingCovariate,
+	DiffusionRateEffectType type,
+	double parameter)
+{
+	this->lpVariable = pVariable;
+	this->lpBehaviorVariable = pBehaviorVariable;
+	this->lpChangingCovariate = pChangingCovariate;
+	this->lpConstantCovariate = pConstantCovariate;
+	this->ltype = type;
+
+	double possibleDegreeNumer = 1;
+	double possibleDegreeDenom = 1;
+
+	if (this->ltype == SUSCEPT_AVERAGE_COVARIATE_RATE)
+	{
+		possibleDegreeNumer = (this->lpBehaviorVariable->range()) *
+			max(this->lpVariable->n(),
+				this->lpVariable->m());
+		possibleDegreeDenom = max(this->lpVariable->n(),
+			this->lpVariable->m());
+	}
+	if (this->ltype == INFECTION_COVARIATE_RATE)
+	{
+		possibleDegreeNumer = 1;
+		possibleDegreeDenom = 1;
+	}
+	this->lpTable = new DiffusionEffectValueTable(possibleDegreeNumer,
+		possibleDegreeDenom);
+	this->lpTable->parameter(parameter);
+}
+
 /**
  * Destructor.
  */
@@ -67,7 +139,7 @@
 /**
  * Returns the contribution of this effect for the given actor.
  */
-double DiffusionRateEffect::value(int i)
+double DiffusionRateEffect::value(int i, int period)
 {
 	Network * pNetwork = this->lpVariable->pNetwork();
 	switch (this->ltype)
@@ -97,6 +169,184 @@
 						pNetwork->outDegree(i)));
 			}
 		}
+		case SUSCEPT_AVERAGE_INDEGREE_RATE:
+		{
+			int totalAlterValue = 0;
+			if (pNetwork->outDegree(i) > 0)
+			{
+				for (IncidentTieIterator iter = pNetwork->outTies(i);
+					 iter.valid();
+					 iter.next())
+				{
+					double alterValue = this->lpBehaviorVariable->
+						value(iter.actor());
+					totalAlterValue += alterValue;
+				}
+			}
+
+			totalAlterValue *= pNetwork->inDegree(i);
+
+			if (totalAlterValue==0)
+			{
+			    return 1;
+			}
+			else
+			{
+			    return this->lpTable->value(totalAlterValue,max(1,
+						pNetwork->outDegree(i)));
+			}
+		}
+		case TOTAL_EXPOSURE_RATE:
+		{
+			int totalAlterValue = 0;
+			if (pNetwork->outDegree(i) > 0)
+			{
+				for (IncidentTieIterator iter = pNetwork->outTies(i);
+					 iter.valid();
+					 iter.next())
+				{
+					double alterValue = this->lpBehaviorVariable->
+						value(iter.actor());
+					totalAlterValue += alterValue;
+				}
+			}
+
+			if (totalAlterValue==0)
+			{
+			    return 1;
+			}
+			else
+			{
+			    return this->lpTable->value(totalAlterValue, 1);
+			}
+		}
+		case SUSCEPT_AVERAGE_COVARIATE_RATE:
+		{
+			int totalAlterValue = 0;
+			if (pNetwork->outDegree(i) > 0)
+			{
+				for (IncidentTieIterator iter = pNetwork->outTies(i);
+					 iter.valid();
+					 iter.next())
+				{
+					double alterValue = this->lpBehaviorVariable->
+						value(iter.actor());
+					totalAlterValue += alterValue;
+				}
+			}
+
+			if (totalAlterValue==0)
+			{
+			    return 1;
+			}
+			else
+			{
+				if (this->lpConstantCovariate)
+				{
+					return pow(this->lpTable->value(totalAlterValue,max(1,
+								pNetwork->outDegree(i))),
+						this->lpConstantCovariate->value(i));
+				}
+				else if (this->lpChangingCovariate)
+				{
+					return pow(this->lpTable->value(totalAlterValue,max(1,
+								pNetwork->outDegree(i))),
+						this->lpChangingCovariate->value(i,period));
+				}
+			   	else
+					throw logic_error(
+						"No individual covariate found.");
+			}
+		}
+		case INFECTION_INDEGREE_RATE:
+		{
+			int totalAlterValue = 0;
+			if (pNetwork->outDegree(i) > 0)
+			{
+				for (IncidentTieIterator iter = pNetwork->outTies(i);
+					 iter.valid();
+					 iter.next())
+				{
+					double alterValue = this->lpBehaviorVariable->
+						value(iter.actor()) *
+						pNetwork->inDegree(iter.actor());
+					totalAlterValue += alterValue;
+				}
+			}
+
+			if (totalAlterValue==0)
+			{
+			    return 1;
+			}
+			else
+			{
+			    return this->lpTable->value(totalAlterValue,1);
+			}
+		}
+		case INFECTION_OUTDEGREE_RATE:
+		{
+			int totalAlterValue = 0;
+			if (pNetwork->outDegree(i) > 0)
+			{
+				for (IncidentTieIterator iter = pNetwork->outTies(i);
+					 iter.valid();
+					 iter.next())
+				{
+					double alterValue = this->lpBehaviorVariable->
+						value(iter.actor()) *
+						pNetwork->outDegree(iter.actor());
+					totalAlterValue += alterValue;
+				}
+			}
+
+			if (totalAlterValue==0)
+			{
+			    return 1;
+			}
+			else
+			{
+				return this->lpTable->value(totalAlterValue,1);
+			}
+		}
+		case INFECTION_COVARIATE_RATE:
+		{
+			int totalAlterValue = 0;
+			if (pNetwork->outDegree(i) > 0)
+			{
+				for (IncidentTieIterator iter = pNetwork->outTies(i);
+					 iter.valid();
+					 iter.next())
+				{
+					double alterValue = this->lpBehaviorVariable->
+						value(iter.actor());
+
+					if (this->lpConstantCovariate)
+					{
+						alterValue *=
+							this->lpConstantCovariate->value(iter.actor());
+					}
+					else if (this->lpChangingCovariate)
+					{
+						alterValue *=
+							this->lpChangingCovariate->value(iter.actor(),
+								period);
+					}
+					else
+						throw logic_error(
+							"No individual covariate found.");
+
+					totalAlterValue += alterValue;
+				}
+			}
+			if (totalAlterValue==0)
+			{
+			    return 1;
+			}
+			else
+			{
+			    return pow(this->lpTable->value(1,1), totalAlterValue);
+			}
+		}
 	}
 
 	throw new logic_error("Unexpected diffusion rate effect type");

Modified: pkg/RSienaTest/src/model/effects/DiffusionRateEffect.h
===================================================================
--- pkg/RSienaTest/src/model/effects/DiffusionRateEffect.h	2012-03-07 20:07:54 UTC (rev 205)
+++ pkg/RSienaTest/src/model/effects/DiffusionRateEffect.h	2012-03-16 15:18:27 UTC (rev 206)
@@ -24,7 +24,13 @@
  */
 enum DiffusionRateEffectType
 {
-	AVERAGE_EXPOSURE_RATE	
+    AVERAGE_EXPOSURE_RATE,
+    SUSCEPT_AVERAGE_INDEGREE_RATE,
+	TOTAL_EXPOSURE_RATE,
+    SUSCEPT_AVERAGE_COVARIATE_RATE,
+    INFECTION_INDEGREE_RATE,
+    INFECTION_OUTDEGREE_RATE,
+    INFECTION_COVARIATE_RATE
 };
 
 
@@ -35,8 +41,9 @@
 class NetworkVariable;
 class BehaviorVariable;
 class DiffusionEffectValueTable;
+class ConstantCovariate;
+class ChangingCovariate;
 
-
 // ----------------------------------------------------------------------------
 // Section: Class definition
 // ----------------------------------------------------------------------------
@@ -45,7 +52,7 @@
  * Encapsulates the information necessary for calculating the contributions
  * of a diffusion rate effect. This includes the effect type,
  * the network variable and the behavior variable
- * the effect depends on, and the statistical parameter of the effect. 
+ * the effect depends on, and the statistical parameter of the effect.
  */
 class DiffusionRateEffect
 {
@@ -54,9 +61,17 @@
 		const BehaviorVariable * pBehaviorVariable,
 		DiffusionRateEffectType type,
 		double parameter);
+	DiffusionRateEffect(const NetworkVariable * pVariable,
+		const BehaviorVariable * pBehaviorVariable,
+		const ConstantCovariate * pCovariate,
+		const ChangingCovariate * pChangingCovariate,
+		DiffusionRateEffectType type,
+		double parameter);
+
+
 	virtual ~DiffusionRateEffect();
 
-	double value(int i);
+	double value(int i, int period);
 	void parameter(double parameterValue);
 	double parameter() const;
 
@@ -67,11 +82,15 @@
 	// The behavior variable this effect depends on
 	const BehaviorVariable * lpBehaviorVariable;
 
+	// The covariates some effects depend on
+	const ConstantCovariate * lpConstantCovariate;
+	const ChangingCovariate * lpChangingCovariate;
+
 	// The type of the effect
 	DiffusionRateEffectType ltype;
 
 	// A table for efficient calculation of contributions. If two actors have
-	// the same effect value, then the table ensures that we don't  
+	// the same effect value, then the table ensures that we don't
 	// calculate the same contribution twice.
 
 	DiffusionEffectValueTable * lpTable;

Modified: pkg/RSienaTest/src/model/variables/DependentVariable.cpp
===================================================================
--- pkg/RSienaTest/src/model/variables/DependentVariable.cpp	2012-03-07 20:07:54 UTC (rev 205)
+++ pkg/RSienaTest/src/model/variables/DependentVariable.cpp	2012-03-16 15:18:27 UTC (rev 206)
@@ -116,6 +116,7 @@
 		double parameter = pEffectInfo->parameter();
 		string effectName = pEffectInfo->effectName();
 		string interactionName = pEffectInfo->interactionName1();
+		string interactionName2 = pEffectInfo->interactionName2();
 		string rateType = pEffectInfo->rateType();
 
 		if (rateType == "covariate")
@@ -305,26 +306,147 @@
 					" refers to a non-existing network variable " +
 					interactionName);
 			}
-
-			if (effectName == "avExposure")
+			if (interactionName2 == "")
 			{
-				if (this->lpActorSet != pVariable->pSenders())
+				if (effectName == "avExposure")
 				{
-					throw std::invalid_argument("Mismatch of actor sets");
+					if (this->lpActorSet != pVariable->pSenders())
+					{
+						throw std::invalid_argument("Mismatch of actor sets");
+					}
+
+					this->ldiffusionRateEffects.push_back(
+						new DiffusionRateEffect(pVariable,
+							pBehaviorVariable,
+							AVERAGE_EXPOSURE_RATE,
+							parameter));
+					this->laverageExposureScores[pVariable] = 0;
+					this->laverageExposureSumTerm[pVariable] = 0;
 				}
+				else if (effectName == "susceptAvIn")
+				{
+					if (this->lpActorSet != pVariable->pSenders())
+					{
+						throw std::invalid_argument("Mismatch of actor sets");
+					}
 
-				this->ldiffusionRateEffects.push_back(
-					new DiffusionRateEffect(pVariable,
-						pBehaviorVariable,
-						AVERAGE_EXPOSURE_RATE,
-						parameter));
-				this->laverageExposureScores[pVariable] = 0;
-				this->laverageExposureSumTerm[pVariable] = 0;
+					this->ldiffusionRateEffects.push_back(
+						new DiffusionRateEffect(pVariable,
+							pBehaviorVariable,
+							SUSCEPT_AVERAGE_INDEGREE_RATE,
+							parameter));
+					this->lsusceptAverageIndegreeScores[pVariable] = 0;
+					this->lsusceptAverageIndegreeSumTerm[pVariable] = 0;
+				}
+				else if (effectName == "totExposure")
+				{
+					if (this->lpActorSet != pVariable->pSenders())
+					{
+						throw std::invalid_argument("Mismatch of actor sets");
+					}
+
+					this->ldiffusionRateEffects.push_back(
+						new DiffusionRateEffect(pVariable,
+							pBehaviorVariable,
+							TOTAL_EXPOSURE_RATE,
+							parameter));
+					this->ltotalExposureScores[pVariable] = 0;
+					this->ltotalExposureSumTerm[pVariable] = 0;
+				}
+				else if (effectName == "infectIn")
+				{
+					if (this->lpActorSet != pVariable->pSenders())
+					{
+						throw std::invalid_argument("Mismatch of actor sets");
+					}
+
+					this->ldiffusionRateEffects.push_back(
+						new DiffusionRateEffect(pVariable,
+							pBehaviorVariable,
+							INFECTION_INDEGREE_RATE,
+							parameter));
+					this->linfectionIndegreeScores[pVariable] = 0;
+					this->linfectionIndegreeSumTerm[pVariable] = 0;
+				}
+				else if (effectName == "infectOut")
+				{
+					if (this->lpActorSet != pVariable->pSenders())
+					{
+						throw std::invalid_argument("Mismatch of actor sets");
+					}
+
+					this->ldiffusionRateEffects.push_back(
+						new DiffusionRateEffect(pVariable,
+							pBehaviorVariable,
+							INFECTION_OUTDEGREE_RATE,
+							parameter));
+					this->linfectionOutdegreeScores[pVariable] = 0;
+					this->linfectionOutdegreeSumTerm[pVariable] = 0;
+				}
+				else
+				{
+					throw domain_error("Unexpected rate effect " + effectName);
+				}
 			}
 			else
 			{
-				throw domain_error("Unexpected rate effect " + effectName);
+				// Covariate-dependent diffusion rate effects
+
+		   		const ConstantCovariate * pConstantCovariate =
+					pData->pConstantCovariate(interactionName2);
+				const ChangingCovariate * pChangingCovariate =
+					pData->pChangingCovariate(interactionName2);
+
+				if (effectName == "susceptAvCovar")
+				{
+					if (this->lpActorSet != pVariable->pSenders())
+					{
+						throw std::invalid_argument("Mismatch of actor sets");
+					}
+
+					this->ldiffusionRateEffects.push_back(
+						new DiffusionRateEffect(pVariable,
+							pBehaviorVariable,
+							pConstantCovariate,
+							pChangingCovariate,
+							SUSCEPT_AVERAGE_COVARIATE_RATE,
+							parameter));
+					this->lsusceptAverageCovariateScores[pVariable] = 0;
+					this->lsusceptAverageCovariateSumTerm[pVariable] = 0;
+					this->lsusceptAverageConstantCovariate
+						[pVariable] = pConstantCovariate;
+					this->lsusceptAverageChangingCovariate
+						[pVariable] = pChangingCovariate;
+
+				}
+				else if (effectName == "infectCovar")
+				{
+					if (this->lpActorSet != pVariable->pSenders())
+					{
+						throw std::invalid_argument("Mismatch of actor sets");
+					}
+
+					this->ldiffusionRateEffects.push_back(
+						new DiffusionRateEffect(pVariable,
+							pBehaviorVariable,
+							pConstantCovariate,
+							pChangingCovariate,
+							INFECTION_COVARIATE_RATE,
+							parameter));
+					this->linfectionCovariateScores[pVariable] = 0;
+					this->linfectionCovariateSumTerm[pVariable] = 0;
+					this->linfectionConstantCovariate
+						[pVariable] = pConstantCovariate;
+					this->linfectionChangingCovariate
+						[pVariable] = pChangingCovariate;
+				}
+				else
+				{
+					throw domain_error("Unexpected rate effect " + effectName);
+				}
+
 			}
+
 		}
 
 	}
@@ -583,7 +705,7 @@
 			sumRatesSquared += this->lrate[i] * this->lrate[i];
 
 		}
-		
+
 		if (this->pSimulation()->pModel()->needScores())
 		  {
 		    this->calculateScoreSumTerms();
@@ -593,7 +715,7 @@
 		    this->ltotalRate = this->totalRate() * this->totalRate() -
 		      sumRatesSquared;
 		  }
-	
+
 		this->lvalidRates = true;
 	}
 
@@ -779,7 +901,7 @@
 
 	for (int effectIndex = 0; effectIndex < effectCount; effectIndex++)
 	{
-		rate *= this->ldiffusionRateEffects[effectIndex]->value(i);
+		rate *= this->ldiffusionRateEffects[effectIndex]->value(i,this->lperiod);
 	}
 
 	return rate;
@@ -991,9 +1113,9 @@
 	// Update scores for diffusion rate parameters
 
 	for (std::map<const NetworkVariable *, double>::iterator iter =
-			this->laverageExposureScores.begin();
-		iter != this->laverageExposureScores.end();
-		iter++)
+			 this->laverageExposureScores.begin();
+		 iter != this->laverageExposureScores.end();
+		 iter++)
 	{
 		const Network * pNetwork = iter->first->pNetwork();
 		const BehaviorVariable * pBehaviorVariable;
@@ -1006,25 +1128,267 @@
 			if (pNetwork->outDegree(selectedActor) > 0)
 			{
 				for (IncidentTieIterator iter2 =
-				       pNetwork->outTies(selectedActor);
-					iter2.valid();
-					iter2.next())
+						 pNetwork->outTies(selectedActor);
+					 iter2.valid();
+					 iter2.next())
 				{
 					double alterValue = pBehaviorVariable->
 						value(iter2.actor());
 					totalAlterValue += alterValue;
 				}
 				averageAlterValue = totalAlterValue /
-				  pNetwork->outDegree(selectedActor);
+					pNetwork->outDegree(selectedActor);
 			}
 
 			iter->second += averageAlterValue;
 		}
 
 		iter->second -= this->laverageExposureSumTerm[iter->first] *
-		  tau;
+			tau;
 	}
 
+	for (std::map<const NetworkVariable *, double>::iterator iter =
+			 this->lsusceptAverageIndegreeScores.begin();
+		 iter != this->lsusceptAverageIndegreeScores.end();
+		 iter++)
+	{
+		const Network * pNetwork = iter->first->pNetwork();
+		const BehaviorVariable * pBehaviorVariable;
+		pBehaviorVariable =
+		    dynamic_cast<const BehaviorVariable *>(pSelectedVariable);
+
+		if (this == pSelectedVariable)
+		{
+			double totalAlterValue = 0;
+			double averageAlterValue = 0;
+			if (pNetwork->outDegree(selectedActor) > 0)
+			{
+				for (IncidentTieIterator iter2 =
+						 pNetwork->outTies(selectedActor);
+					 iter2.valid();
+					 iter2.next())
+				{
+					double alterValue = pBehaviorVariable->
+						value(iter2.actor());
+					totalAlterValue += alterValue;
+				}
+				averageAlterValue = totalAlterValue /
+					pNetwork->outDegree(selectedActor);
+			}
+
+			iter->second += averageAlterValue *
+				pNetwork->inDegree(selectedActor);
+		}
+
+		iter->second -= this->lsusceptAverageIndegreeSumTerm[iter->first] *
+			tau;
+	}
+	for (std::map<const NetworkVariable *, double>::iterator iter =
+			 this->ltotalExposureScores.begin();
+		 iter != this->ltotalExposureScores.end();
+		 iter++)
+	{
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rsiena -r 206


More information about the Rsiena-commits mailing list