Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.17 KB | None | 0 0
  1. gm.search <- function (counts.observed, graph.init, forward, backward, score)
  2. {
  3.   n = ncol(counts.observed)
  4.  
  5.   cliques.init = maximal.cliques(as.igraph(graph.init))
  6.   score.init   = calculate.score(score, counts.observed, n, cliques.init) # <- error
  7.  
  8.   # Error in `[<-`(`*tmp*`, seq_along(tmp), k, value = tmp) :
  9.   #   subscript out of bounds
  10.   # 4 loglin(table, cliques) at assignment2.R#65
  11.   # 3 bic(counts.observed, nnodes, cliques) at assignment2.R#52
  12.   # 2 calculate.score(score, counts.observed, n, cliques.init) at assignment2.R#8
  13.   # 1 gm.search(table(coronary.dat), matrix(0, 6, 6), forward = T,
  14.   #     backward = T, score = "bic")
  15.  
  16.   # ...
  17. }
  18.  
  19.  
  20. calculate.score <- function (score, counts, nnodes, cliques) {
  21.   if (score == "aic") {
  22.     return (aic(counts.observed, cliques))
  23.   } else if (score == "bic") {
  24.     return (bic(counts.observed, nnodes, cliques))
  25.   } else {
  26.     stop ("Invalid score parameter. Only 'aic' or 'bic' supported.")
  27.   }
  28. }
  29.  
  30. aic <- function (counts, cliques)
  31. {
  32.   return (loglin(table, cliques) + 2 * dim(cliques))
  33. }
  34.  
  35. bic <- function (counts, nnodes, cliques)
  36. {
  37.   return (loglin(table, cliques) + log2(nnodes) * dim(cliques))
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement