Skip to content

How to specify an edgecov using a matrix. #35

Closed Answered by krivit
benrosche asked this question in Q&A
Discussion options

You must be logged in to vote

While in principle, you can treat the data structure returned by Networks() as a block-diagonal matrix, it is generally better to use the N(), which takes care of the bookkeeping and handles things consistently. Here's how I would do it:

library(ergm.multi)
data(Goeyvaerts)

g <- Goeyvaerts[1:5]

# 5 ec_matrices that represent an edgecov 
ec_matrices <-
  purrr::map(g,\(x) { 
    n <- network.size(x)
    m <- matrix(rnorm(n*n,0,1),n,n)
    return(m)
  })

# attach each covariate matrix to its respective network
for(i in seq_along(g)) g[[i]] %n% "weight" <- ec_matrices[[i]]

summary(Networks(g) ~ N(~edges + edgecov("weight")))
#>          N(1)~edges N(1)~edgecov.weight 
#>           28.000…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by krivit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants