@@ -86,6 +86,9 @@ sienaGOF <- function(
86
86
{
87
87
stop(" You need to supply the parameter <<auxiliaryFunction>>." )
88
88
}
89
+ # This should be captured for possible later use
90
+ # (when it will have been used the name is no longer available):
91
+ auxfu <- deparse(substitute(auxiliaryFunction ))
89
92
# There might be more than one varName:
90
93
if (is.null(sFO $ f [[groupName ]]$ depvars [[varName [1 ]]]))
91
94
{
@@ -232,10 +235,10 @@ sienaGOF <- function(
232
235
cat(" > Completed " , iterations , " calculations\n\n " )
233
236
}
234
237
flush.console()
235
- if (var(vapply(simStatsByPeriod , length , FUN.VALUE = 0 ))> 1e-10 )
238
+ if (var(vapply(simStatsByPeriod , length , FUN.VALUE = 0 ))> 1e-8 )
236
239
{
237
- stop(" Function" , deparse(substitute( auxiliaryFunction )) ,
238
- " does not always give vectors of the same length" )
240
+ stop(" Function " , auxfu ,
241
+ " does not always give vectors of the same length" )
239
242
}
240
243
simStatsByPeriod <-
241
244
matrix (unlist(simStatsByPeriod ), ncol = iterations )
@@ -648,7 +651,8 @@ summary.sienaGOF <- function(object, ...) {
648
651
649
652
# #@plot.sienaGOF siena07 Plot method for sienaGOF
650
653
plot.sienaGOF <- function (x , center = FALSE , scale = FALSE , violin = TRUE ,
651
- key = NULL , perc = .05 , period = 1 , position = 4 , fontsize = 12 , ... )
654
+ key = NULL , perc = .05 , period = 1 , showAll = FALSE ,
655
+ position = 4 , fontsize = 12 , ... )
652
656
{
653
657
# # require(lattice)
654
658
args <- list (... )
@@ -681,17 +685,25 @@ plot.sienaGOF <- function (x, center=FALSE, scale=FALSE, violin=TRUE,
681
685
# # Need to check for useless statistics here:
682
686
n.obs <- nrow(obs )
683
687
684
- screen <- sapply(1 : ncol(obs ),function (i ){
688
+ if (showAll )
689
+ {
690
+ screen <- sapply(1 : ncol(obs ),function (i ){
691
+ (sum(is.nan(rbind(sims ,obs )[,i ])) == 0 ) })
692
+ }
693
+ else
694
+ {
695
+ screen <- sapply(1 : ncol(obs ),function (i ){
685
696
(sum(is.nan(rbind(sims ,obs )[,i ])) == 0 ) }) &
686
697
(diag(var(rbind(sims ,obs )))!= 0 )
687
-
688
- if (any((diag(var(rbind(sims ,obs )))== 0 )))
689
- { cat(" Note: some statistics are not plotted because their variance is 0.\n " )
690
- cat(" This holds for the statistic" )
691
- if (sum(diag(var(rbind(sims ,obs )))== 0 ) > 1 ){cat(" s" )}
692
- cat(" : " )
693
- cat(paste(attr(x ," key" )[which(diag(var(rbind(sims ,obs )))== 0 )], sep = " , " ))
694
- cat(" .\n " )
698
+ if (any((diag(var(rbind(sims ,obs )))== 0 )))
699
+ {
700
+ cat(" Note: some statistics are not plotted because their variance is 0.\n " )
701
+ cat(" This holds for the statistic" )
702
+ if (sum(diag(var(rbind(sims ,obs )))== 0 ) > 1 ){cat(" s" )}
703
+ cat(" : " )
704
+ cat(paste(attr(x ," key" )[which(diag(var(rbind(sims ,obs )))== 0 )], sep = " , " ))
705
+ cat(" .\n " )
706
+ }
695
707
}
696
708
697
709
sims <- sims [,screen , drop = FALSE ]
@@ -1523,7 +1535,7 @@ TriadCensus <- function (i, obsData, sims, period, groupName, varName, levls = 1
1523
1535
1524
1536
# #@dyadicCov sienaGOF Auxiliary variable for dyadic covariate
1525
1537
#
1526
- # An auxiliary function calculating the proportion of ties
1538
+ # An auxiliary function calculating the number of ties
1527
1539
# for subsets of ordered pairs corresponding to
1528
1540
# certain values of the categorical dyadic covariate dc.
1529
1541
# dc should be a matrix of the same dimensions as
@@ -1559,3 +1571,38 @@ dyadicCov <- function (i, obsData, sims, period, groupName, varName, dc){
1559
1571
ttmdyv [dims ] <- tmdyv # The other entries remain 0
1560
1572
ttmdyv
1561
1573
}
1574
+
1575
+ egoAlterCombi <- function (i , obsData , sims , period , groupName , varName ,
1576
+ trafo = NULL )
1577
+ {
1578
+ # An auxiliary function calculating the number of ties
1579
+ # for each ego-alter combination of values of the dependent variable;
1580
+ # the dependent variable is transformed by trafo.
1581
+ if (length(varName ) != 2 ){
1582
+ stop(" egoAlterCombi expects two varName parameters" )
1583
+ }
1584
+ if (is.null(trafo )){
1585
+ trafo <- function (x ){x }
1586
+ }
1587
+ varName1 <- varName [1 ]
1588
+ varName2 <- varName [2 ]
1589
+ m <- sparseMatrixExtraction(i , obsData , sims , period , groupName ,
1590
+ varName1 )
1591
+ x <- behaviorExtraction(i , obsData , sims , period , groupName ,
1592
+ varName2 )
1593
+ brange <- attr(obsData [[groupName ]]$ depvars [[varName2 ]],
1594
+ " behRange" )[1 ]: attr(obsData [[groupName ]]$ depvars [[varName2 ]],
1595
+ " behRange" )[2 ]
1596
+ combi.egoalter <- outer(10 * trafo(x ), trafo(x ) ,' +' )
1597
+ possible.pairs <-
1598
+ sort(unique(as.vector(outer(10 * trafo(brange ), trafo(brange ), ' +' ))))
1599
+ tmeax <- table((m * combi.egoalter )@ x , useNA = " no" )
1600
+ ppnames <- as.character(possible.pairs )
1601
+ teax <- setNames(0 * possible.pairs , ppnames )
1602
+ teax [dimnames(tmeax )[[1 ]]] <- tmeax
1603
+ # pad names with leading 0s, if necessary:
1604
+ pp.names <- ifelse(nchar(ppnames )== 1 , paste(" 0" ,ppnames ,sep = " " ),ppnames )
1605
+ names(teax ) <- pp.names
1606
+ teax
1607
+ }
1608
+
0 commit comments