Search code examples
rsocial-networkingnetwork-analysis

Setting group-level covariate in RSiena


I'm having a terrible time trying to set a group-level variable in RSiena. My data are complicated, but I'm modeling 8 classrooms of 24 students over six periods. I am modeling how teacher behavior and student personality influence friendships. I am using a measure of teacher behavior as a group-level covariate.

The code is complicated enough that it really isn't feasible to provide a minimal reproducible example. But, I've uploaded data objects and linked them below so the code can be run.

https://drive.google.com/drive/folders/1FXf3DWfIE23IkEChMoulXjzqxRy7HYko?usp=sharing

I'm attempting to use sienaBayes from the multiSiena package. The problem I'm having is that I get the following error when testing time homogeneity.

TimeTest constructed a null hypothesis with 3 estimated parameters and 117 dummy variables to be tested. However, there are 40 linear dependencies between these.

This may be because some of the parameters are already interactions with time dummies or other time variables. Automatic discovery of dependencies yielded the exclusion of effects Error in row(fitEffects)[baseInFit, drop = FALSE][extraExclusions, drop = FALSE][, : incorrect number of dimensions

Installing multiSiena requires a windows machine and is kind of a chore, but you can get through this part just using RSiena:

library(multiSiena) #optional
library(RSiena)

dataObjList <- list()
for(z in 1:8){
  
  currentArray <- sienaDependent(friendshipObjectArrayList[[z]])
  extraversion <- coCovar((attribute_list[[z]]$extra))
  neuroticism <- coCovar((attribute_list[[z]]$neur))
  teacherBehave <- coCovar(rep(((teacher_df[z, ]$behavior)), 24))
  gender <- coCovar(attribute_list[[z]]$gender)

  dataObjList[[z]] <- sienaDataCreate(currentArray, extraversion, teacherBehave, 
                                      neuroticism, gender)
}

sienaObjList <- sienaGroupCreate(dataObjList)

testAlgo <- sienaAlgorithmCreate(projname = NULL,
                                 n3=500)

##Effects
basicEffects <- getEffects(sienaObjList, nintn = 200)


basicEffects <- setEffect(basicEffects, inPop)
basicEffects <- setEffect(basicEffects, transTrip)
basicEffects <- setEffect(basicEffects, outAct)
basicEffects <- setEffect(basicEffects, cycle3)
basicEffects <- setEffect(basicEffects, transTies)
basicEffects <- setEffect(basicEffects, simX,
                          interaction1 = "extraversion")
basicEffects <- setEffect(basicEffects, egoSqX,
                          interaction1 = "extraversion")

basicEffects <- setEffect(basicEffects, inPopX,
                          interaction1 = c("neuroticism"))

##group-level effect
basicEffects <- includeEffects(basicEffects, egoX, name = "currentArray",
                               interaction1 = "teacherBehave")


##Model
testAns <- siena07(testAlgo, data = sienaObjList, effects = basicEffects,
                   useCluster = TRUE, nbrNodes = 4)

timeAns <- summary(sienaTimeTest(testAns))

I then go on to run sienaBayes, but I need the homogeneity tests for that analysis to be meaningful.

Thanks for any help you're able to offer. I've been banging my head against this and consulted every siena resource I can find. I can't find anything that I'm doing that's different from the scripts on the website. So, thoughts welcome and appreciated!


Solution

  • Well, it took a while, but as expected, it's a simple answer: any dummies (including for group or time) need to be excluded from sienaTimeTest using the effects argument. When I used

    timeAns <- summary(sienaTimeTest(testAns, effects = c(1:5))
    

    it worked just fine.

    What I'm finding odd, though, is that isn't true all the time. There are instances in the RscriptMultipleGroups.R tutorial in which multigroup analyses are performed--sometimes with time dummies, sometimes not--and in which the effects argument is left out. sienaTimeTest runs without a problem.

    If anyone can explain that discrepancy, it would be helpful. Either way, though, I hope this helpful to someone facing the same problem.