Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # We'll bootstrap the monk data, consider those to somewhat legit representations of 'real'
- # graphs, and run those through the prob calculating function, then compare the prob of our
- # random graph to the resulting distribution of probabilities.
- # we can use the probability of the non bootstrapped, actual Monk graph data to possibly
- # slightly change the distribution of the probabitlies, if the bootstrapped calced probs
- # seem a bit skewed.
- # would this have implications regarding the theta involved?
- # first, we need a random graph.
- p = .28
- rand.grph <- matrix(sample( c(1, 0), size = 18*18, prob = c(p, (1-p)), replace = TRUE), nrow = 18)
- theta.mle <- c(-1.9, 1.89, .098)
- acc.trials.kappa = 700
- burn = 300
- prob.of.graph = function(graph.test, theta.mle, acc.trials.kappa, burn){
- kappa.test <- mean(mcmc.kappa(graph, theta = theta.mle,
- acc.trials = acc.trials.kappa)$kappa[burn:(acc.trials.kappa-1)])
- return(exp( Theta.vector %*% c(g1(graph.test), g2(graph.test), g3(graph.test)) / kappa.test))
- }
- # now, we want to retain certain charecteristics of the monk graph, so we wont randomly select
- # cells from the graph. We could do rows, we could to columns, the idea is to be random and
- # different while still keeping certain info from the graph, that is specifically different
- # than only the total number of ones in the graph.
- # we'll chose some by column, some by rown, and some by mixing up different grids, mxn, from
- # the monk graph
- bootsrap.graph = function(graph){
- r.comp <- runif(1)
- if(r.comp < .34){
- smp <- sample(1:18, size = 18, replace = TRUE)
- graph.new <- graph[,smp]}
- else #(r.comp < .67)
- {
- smp <- sample(1:18, size = 18, replace = TRUE)
- graph.new <- graph[,smp]}
- # else{
- # smp.col <- sample(2:17, size = 1, replace = TRUE)
- # smp.row <- sample(2:17, size = 1, replace = TRUE)
- # graph.new <- as.matrix(rbind( cbind( graph[smp.row:18,1:smp.col], graph[smp.row:18,(smp.col+1):18]),
- # cbind( graph[1:(smp.row-1),smp.col:18], graph[1:(smp.row-1),1:(smp.col-1)]) ),
- # nrow = 18)
- # colnames(graph.new) <- colnames(graph)
- # rownames(graph.new) <- rownames(1:18)
- # }
- return(graph.new)
- }
- # Yup, we're staying
- View(bootsrap.graph(graph))
- prob.dist.func = function(iter, graph.initial, theta.mle, acc.trials.kappa, burn){
- prob.store <- rep(0, iter)
- for(i in 1:iter){
- graph.test <- bootsrap.graph(graph.initial)
- prob.store <- prob.of.graph(graph.test, theta.mle, acc.trials.kappa, burn)
- }
- return(prob.store)
- }
- prob.dist.func = function(iter, graph.initial, theta.mle, acc.trials.kappa, burn){
- prob.store <- rep(0, iter)
- for(i in 1:iter){
- graph.test <- bootsrap.graph(graph.initial)
- prob.store [i] <- prob.of.graph(graph.test, theta.mle, acc.trials.kappa, burn)
- }
- return(prob.store)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement