add edge attribute based on another network












2















I have two networks of same vertex based on different criteria. I want to add edge attributes of one of the network based on the connection of the other network. That is, if node A and B are connected in network 2, I want to note down "1" as the attribute in network 1, if not connected, note down "0". I am wondering how can I achieve my goal with R package or other software? Any suggestion is welcomed. Thanks a lot for suggestion!










share|improve this question

























  • Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

    – Jingy Niu
    Jan 2 at 9:45











  • I have vote to reopen ; it doesn't have a reproducible example but it seems clear enough and has a good answer that may be useful for others.

    – user20650
    Jan 2 at 13:54
















2















I have two networks of same vertex based on different criteria. I want to add edge attributes of one of the network based on the connection of the other network. That is, if node A and B are connected in network 2, I want to note down "1" as the attribute in network 1, if not connected, note down "0". I am wondering how can I achieve my goal with R package or other software? Any suggestion is welcomed. Thanks a lot for suggestion!










share|improve this question

























  • Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

    – Jingy Niu
    Jan 2 at 9:45











  • I have vote to reopen ; it doesn't have a reproducible example but it seems clear enough and has a good answer that may be useful for others.

    – user20650
    Jan 2 at 13:54














2












2








2








I have two networks of same vertex based on different criteria. I want to add edge attributes of one of the network based on the connection of the other network. That is, if node A and B are connected in network 2, I want to note down "1" as the attribute in network 1, if not connected, note down "0". I am wondering how can I achieve my goal with R package or other software? Any suggestion is welcomed. Thanks a lot for suggestion!










share|improve this question
















I have two networks of same vertex based on different criteria. I want to add edge attributes of one of the network based on the connection of the other network. That is, if node A and B are connected in network 2, I want to note down "1" as the attribute in network 1, if not connected, note down "0". I am wondering how can I achieve my goal with R package or other software? Any suggestion is welcomed. Thanks a lot for suggestion!







r graph-theory sna






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 4:24









G5W

22.9k92042




22.9k92042










asked Jan 1 at 3:11









Jingy NiuJingy Niu

113




113













  • Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

    – Jingy Niu
    Jan 2 at 9:45











  • I have vote to reopen ; it doesn't have a reproducible example but it seems clear enough and has a good answer that may be useful for others.

    – user20650
    Jan 2 at 13:54



















  • Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

    – Jingy Niu
    Jan 2 at 9:45











  • I have vote to reopen ; it doesn't have a reproducible example but it seems clear enough and has a good answer that may be useful for others.

    – user20650
    Jan 2 at 13:54

















Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

– Jingy Niu
Jan 2 at 9:45





Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

– Jingy Niu
Jan 2 at 9:45













I have vote to reopen ; it doesn't have a reproducible example but it seems clear enough and has a good answer that may be useful for others.

– user20650
Jan 2 at 13:54





I have vote to reopen ; it doesn't have a reproducible example but it seems clear enough and has a good answer that may be useful for others.

– user20650
Jan 2 at 13:54












1 Answer
1






active

oldest

votes


















1














You can do this in R using the igraph package. Since you do not provide any data, I will make up an example.



Example Data



library(igraph)

set.seed(1234)
g1=erdos.renyi.game(10, 0.35)
g2=erdos.renyi.game(10, 0.35)
par(mfrow=c(1,2))
plot(g1)
plot(g2)


Two example graphs



Now we can create the edge attribute that you want. We initialize all values to zero, then loop through each edge in g2. If the same edge occurs in g1, we change the attribute to be 1.



E(g2)$net1 = 0
for(e in E(g2)) {
if(are_adjacent(g1, ends(g2,e)[1], ends(g2,e)[2])) {
E(g2)$net1[e] = 1 }
}

E(g2)$net1
[1] 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
E(g2)[which(E(g2)$net1 > 0)]
+ 4/19 edges from 3bdc176:
[1] 3--4 4--5 4--6 5--7


You can see that the attribute net1 says that the shared links are:

3--4 4--5 4--6 5--7

which agrees with the plot.






share|improve this answer
























  • I wonder if this could be done using intersection: for example, inter <- intersection(g1, g2) ; E(g2, P=t(get.edgelist(inter)))$net1 <- 1, although this way does require a dense matrix to be formed

    – user20650
    Jan 1 at 21:15













  • Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

    – Jingy Niu
    Jan 2 at 9:44











  • @JingyNiu I know little about ERGMs. I cannot help you with that.

    – G5W
    Jan 2 at 13:52











  • Thanks a lot anyway!

    – Jingy Niu
    Jan 3 at 9:21











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992804%2fadd-edge-attribute-based-on-another-network%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can do this in R using the igraph package. Since you do not provide any data, I will make up an example.



Example Data



library(igraph)

set.seed(1234)
g1=erdos.renyi.game(10, 0.35)
g2=erdos.renyi.game(10, 0.35)
par(mfrow=c(1,2))
plot(g1)
plot(g2)


Two example graphs



Now we can create the edge attribute that you want. We initialize all values to zero, then loop through each edge in g2. If the same edge occurs in g1, we change the attribute to be 1.



E(g2)$net1 = 0
for(e in E(g2)) {
if(are_adjacent(g1, ends(g2,e)[1], ends(g2,e)[2])) {
E(g2)$net1[e] = 1 }
}

E(g2)$net1
[1] 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
E(g2)[which(E(g2)$net1 > 0)]
+ 4/19 edges from 3bdc176:
[1] 3--4 4--5 4--6 5--7


You can see that the attribute net1 says that the shared links are:

3--4 4--5 4--6 5--7

which agrees with the plot.






share|improve this answer
























  • I wonder if this could be done using intersection: for example, inter <- intersection(g1, g2) ; E(g2, P=t(get.edgelist(inter)))$net1 <- 1, although this way does require a dense matrix to be formed

    – user20650
    Jan 1 at 21:15













  • Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

    – Jingy Niu
    Jan 2 at 9:44











  • @JingyNiu I know little about ERGMs. I cannot help you with that.

    – G5W
    Jan 2 at 13:52











  • Thanks a lot anyway!

    – Jingy Niu
    Jan 3 at 9:21
















1














You can do this in R using the igraph package. Since you do not provide any data, I will make up an example.



Example Data



library(igraph)

set.seed(1234)
g1=erdos.renyi.game(10, 0.35)
g2=erdos.renyi.game(10, 0.35)
par(mfrow=c(1,2))
plot(g1)
plot(g2)


Two example graphs



Now we can create the edge attribute that you want. We initialize all values to zero, then loop through each edge in g2. If the same edge occurs in g1, we change the attribute to be 1.



E(g2)$net1 = 0
for(e in E(g2)) {
if(are_adjacent(g1, ends(g2,e)[1], ends(g2,e)[2])) {
E(g2)$net1[e] = 1 }
}

E(g2)$net1
[1] 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
E(g2)[which(E(g2)$net1 > 0)]
+ 4/19 edges from 3bdc176:
[1] 3--4 4--5 4--6 5--7


You can see that the attribute net1 says that the shared links are:

3--4 4--5 4--6 5--7

which agrees with the plot.






share|improve this answer
























  • I wonder if this could be done using intersection: for example, inter <- intersection(g1, g2) ; E(g2, P=t(get.edgelist(inter)))$net1 <- 1, although this way does require a dense matrix to be formed

    – user20650
    Jan 1 at 21:15













  • Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

    – Jingy Niu
    Jan 2 at 9:44











  • @JingyNiu I know little about ERGMs. I cannot help you with that.

    – G5W
    Jan 2 at 13:52











  • Thanks a lot anyway!

    – Jingy Niu
    Jan 3 at 9:21














1












1








1







You can do this in R using the igraph package. Since you do not provide any data, I will make up an example.



Example Data



library(igraph)

set.seed(1234)
g1=erdos.renyi.game(10, 0.35)
g2=erdos.renyi.game(10, 0.35)
par(mfrow=c(1,2))
plot(g1)
plot(g2)


Two example graphs



Now we can create the edge attribute that you want. We initialize all values to zero, then loop through each edge in g2. If the same edge occurs in g1, we change the attribute to be 1.



E(g2)$net1 = 0
for(e in E(g2)) {
if(are_adjacent(g1, ends(g2,e)[1], ends(g2,e)[2])) {
E(g2)$net1[e] = 1 }
}

E(g2)$net1
[1] 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
E(g2)[which(E(g2)$net1 > 0)]
+ 4/19 edges from 3bdc176:
[1] 3--4 4--5 4--6 5--7


You can see that the attribute net1 says that the shared links are:

3--4 4--5 4--6 5--7

which agrees with the plot.






share|improve this answer













You can do this in R using the igraph package. Since you do not provide any data, I will make up an example.



Example Data



library(igraph)

set.seed(1234)
g1=erdos.renyi.game(10, 0.35)
g2=erdos.renyi.game(10, 0.35)
par(mfrow=c(1,2))
plot(g1)
plot(g2)


Two example graphs



Now we can create the edge attribute that you want. We initialize all values to zero, then loop through each edge in g2. If the same edge occurs in g1, we change the attribute to be 1.



E(g2)$net1 = 0
for(e in E(g2)) {
if(are_adjacent(g1, ends(g2,e)[1], ends(g2,e)[2])) {
E(g2)$net1[e] = 1 }
}

E(g2)$net1
[1] 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
E(g2)[which(E(g2)$net1 > 0)]
+ 4/19 edges from 3bdc176:
[1] 3--4 4--5 4--6 5--7


You can see that the attribute net1 says that the shared links are:

3--4 4--5 4--6 5--7

which agrees with the plot.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 1 at 4:11









G5WG5W

22.9k92042




22.9k92042













  • I wonder if this could be done using intersection: for example, inter <- intersection(g1, g2) ; E(g2, P=t(get.edgelist(inter)))$net1 <- 1, although this way does require a dense matrix to be formed

    – user20650
    Jan 1 at 21:15













  • Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

    – Jingy Niu
    Jan 2 at 9:44











  • @JingyNiu I know little about ERGMs. I cannot help you with that.

    – G5W
    Jan 2 at 13:52











  • Thanks a lot anyway!

    – Jingy Niu
    Jan 3 at 9:21



















  • I wonder if this could be done using intersection: for example, inter <- intersection(g1, g2) ; E(g2, P=t(get.edgelist(inter)))$net1 <- 1, although this way does require a dense matrix to be formed

    – user20650
    Jan 1 at 21:15













  • Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

    – Jingy Niu
    Jan 2 at 9:44











  • @JingyNiu I know little about ERGMs. I cannot help you with that.

    – G5W
    Jan 2 at 13:52











  • Thanks a lot anyway!

    – Jingy Niu
    Jan 3 at 9:21

















I wonder if this could be done using intersection: for example, inter <- intersection(g1, g2) ; E(g2, P=t(get.edgelist(inter)))$net1 <- 1, although this way does require a dense matrix to be formed

– user20650
Jan 1 at 21:15







I wonder if this could be done using intersection: for example, inter <- intersection(g1, g2) ; E(g2, P=t(get.edgelist(inter)))$net1 <- 1, although this way does require a dense matrix to be formed

– user20650
Jan 1 at 21:15















Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

– Jingy Niu
Jan 2 at 9:44





Thanks a lot for the guidance. That is very helpful! May I ask a follow up question? since I have edge attribute of g2, can I apply this information in my ERGM model, to check the effect of network alignment in the odds ratio of an edge in the focal model?

– Jingy Niu
Jan 2 at 9:44













@JingyNiu I know little about ERGMs. I cannot help you with that.

– G5W
Jan 2 at 13:52





@JingyNiu I know little about ERGMs. I cannot help you with that.

– G5W
Jan 2 at 13:52













Thanks a lot anyway!

– Jingy Niu
Jan 3 at 9:21





Thanks a lot anyway!

– Jingy Niu
Jan 3 at 9:21




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992804%2fadd-edge-attribute-based-on-another-network%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$