Modeling a poisson branching pattern in R

preview_player
Показать описание

Question: Branching Processes R Code Tree Diagram
Code: 1) Write an R code for a function that simulates a branching process of a Poisson progeny distribution with mean 𝜆 and for number of generations n. 2) Then run the simulations for several values of 𝜆 like .5, 1, and 2 for a reasonable number of generations like 3, 4 or 5. 3) Make a plot of the resulting tree. (Think about placing the generations on concentric circles and make line plots between coordinates of the parents and their children).

------------------------

Answered By:

Matthew A.
Fluent in Fundamentals of Chemistry

------------------------

Written Explanation:

library(DiagrammeR)

#creates amount of leaves specified by poisson distribution
name ‹- node$name
children ‹- rpois(1,lambda) #pulled from poisson distribution
if (children == 0){
node$AddChild("X")
}
else{
for (i in c(1:children)){
}
}
}

#searches siblings for available leaf, if not moves up a level
sib ‹- node$siblings
print(node$parent$name)
temp ‹- node$parent
if(length(sib)›0){
for (i in c(1:length(sib))){
}
}
}
return(temp)
}

depth ‹- 3
lambda ‹- 4

parent ‹- Node$new("1")
node ‹- parent$children[[1]]
if(node$name == "X"){
node ‹- parent
}

while (node$name != parent$name){
print("i")
if (node$level›depth||node$name == "X"){
print("j")
node ‹- node$parent
while(!(node$isLeaf) & node$name != parent$name){
}
}
if (node$level‹=depth & node$isLeaf & node$name != parent$name){
if (node$leafCount › 0){
node ‹- node$children[[1]]
}
}
}

parent
plot(parent)

------------------------

About: Wyzant Ask an Expert offers free answers to your toughest academic and professional questions from over 80,000 verified experts. It’s trusted by millions of students each month with the majority of questions receiving an answer within 1 hour of being asked. If you ever need more than just an answer, Wyzant also offers personalized 1-on-1 sessions with experts that will work with you to help you understand whatever you’re trying to learn.

Рекомендации по теме