forked from RubensZimbres/Repo-2016
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR - Markov Chains
45 lines (38 loc) · 881 Bytes
/
R - Markov Chains
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
set.seed(100)
k<-sample(seq(from = 1, to = 5, by = 1), size = 10, replace = TRUE)
edges0<-c(k[-1],c(k[-10:-2]))
require(DiagrammeR)
o<-cbind(k,edges0)
kk<-data.frame(o)
d<-c(k,edges0)
1/dim(data.frame(which(d==4)))[[1]]
k7<-function(j=1:5)
{return(round(1/dim(data.frame(which(d==j)))[[1]],digits=2))}
conn<-lapply(d,k7)
d
data.frame(conn)
b<-c(rep(8,10))
b
edges <-create_edges(
from = kk[,1],
to = kk[,2],
rel=conn,
length=c(rep(120,20)),
color = "black"
)
nodes<-create_nodes(label=TRUE,
style = "filled",
nodes = 1:max(k),
type = c(1:max(k)))
render_graph(
create_graph(edges_df = edges,nodes_df=nodes),
output = "visNetwork")
dim(data.frame(k))[[1]]
k
io<-data.frame(rep(list(c(1:5)),10))
io
replace(io[[10]],k[[10]],99)
k9<-function(u=1:10)
{return(replace(io[[u]],k[[u]],99))}
xx<-lapply(io,k9)
xx