R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("dynamicGraph-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('dynamicGraph') Loading required package: tcltk Loading Tcl/Tk interface ... done > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "DynamicGraph" > > ### * DynamicGraph > > flush(stderr()); flush(stdout()) > > ### Name: DynamicGraph > ### Title: Simple interface to dynamicGraph > ### Aliases: DynamicGraph > ### Keywords: dplot hplot iplot dynamic graphs methods multivariate > > ### ** Examples > > require(tcltk); require(dynamicGraph) [1] TRUE [1] TRUE > > # Example 1: > > Z <- DynamicGraph(paste("", 1:5), title = "Very simple") (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > # Example 2: > > Z <- DynamicGraph(from = 1:4, to = c(2:4, 1), title = "Simply edges") Warning in check.names(from, "from") : Invalid index 4 in ' from ' (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > # Example 3: > > V.Types <- c("Discrete", "Ordinal", "Discrete", + "Continuous", "Discrete", "Continuous") > > V.Names <- c("Sex", "Age", "Eye", "FEV", "Hair", "Shosize") > V.Labels <- paste(V.Names, 1:6, sep ="/") > > From <- c(1, 2, 3, 4, 5, 6) > To <- c(2, 3, 4, 5, 6, 1) > > Z <- DynamicGraph(V.Names, V.Types, From, To, texts = c("Gryf", "Gaf"), + labels = V.Labels, title = "With labels (extraVertices)") (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > # Example 4: Oriented (cyclic) edges, without causal structure: > > Z <- DynamicGraph(V.Names, V.Types, From, To, oriented = TRUE, + labels = V.Labels, title = "Oriented edges") (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > # Example 5: A factor graph: > > Factors <- list(c(1, 2, 3, 4), c(3, 4, 5), c(4, 5, 6)) > > Z <- DynamicGraph(V.Names, V.Types, from = NULL, to = NULL, factors = Factors, + title = "Factorgraph", namesOnEdges = FALSE) (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > # Example 6: Edges with more than two vertices: > > EdgeList <- list(c(1, 2, 3, 4), c(3, 4, 5), c(4, 5, 6)) > > Z <- DynamicGraph(V.Names, V.Types, edge.list = EdgeList, + title = "Multiple edges", namesOnEdges = FALSE) (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > Z ################################################################################ <> name index p..1 p..2 p..3 blockindex stratum color vertices.Sex Sex 1 20 3.464102e+01 0 0 0 red vertices.Age Age 2 -20 3.464102e+01 0 0 0 red vertices.Eye Eye 3 -40 4.898587e-15 0 0 0 red vertices.FEV FEV 4 -20 -3.464102e+01 0 0 0 red vertices.Hair Hair 5 20 -3.464102e+01 0 0 0 red vertices.Shosize Shosize 6 40 -9.797174e-15 0 0 0 red label l..pos..1 l..pos..2 l..pos..3 class vertices.Sex Sex 0 0 0 dg.DiscreteVertex vertices.Age Age 0 0 0 dg.OrdinalVertex vertices.Eye Eye 0 0 0 dg.DiscreteVertex vertices.FEV FEV 0 0 0 dg.ContinuousVertex vertices.Hair Hair 0 0 0 dg.DiscreteVertex vertices.Shosize Shosize 0 0 0 dg.ContinuousVertex blockTree ================================================================================ Model: 1 << Multiple edges | 1 >> : NULL -------------------------------------------------------------------------------- Model: 1 ; Graph: 1 << Multiple edges / Simple | 1 1 >> visibleVertices: 1, 2, 3, 4, 5, 6 visibleBlocks: 1, 0 oriented dash v..i..1 v..i..2 v..i..3 v..i..4 vertexEdges.Sex~Age~Eye~FEV FALSE 1 2 3 4 vertexEdges.Eye~FEV~Hair FALSE 3 4 5 NA vertexEdges.FEV~Hair~Shosize FALSE 4 5 6 NA width color label l..pos..1 l..pos..2 vertexEdges.Sex~Age~Eye~FEV 2 black Sex~Age~Eye~FEV 0 0 vertexEdges.Eye~FEV~Hair 2 black Eye~FEV~Hair 0 0 vertexEdges.FEV~Hair~Shosize 2 black FEV~Hair~Shosize 0 0 l..pos..3 class vertexEdges.Sex~Age~Eye~FEV 0 dg.VertexEdge vertexEdges.Eye~FEV~Hair 0 dg.VertexEdge vertexEdges.FEV~Hair~Shosize 0 dg.VertexEdge ################################################################################ > > > > cleanEx(); ..nameEx <- "blockTreeToList" > > ### * blockTreeToList > > flush(stderr()); flush(stdout()) > > ### Name: blockTreeToList > ### Title: Extract the list of blocks from a block tree > ### Aliases: blockTreeToList > ### Keywords: methods dynamic graphs > > ### ** Examples > > Block.tree <- list(label = "W", Vertices = c("contry"), + X = list(Vertices = c("sex", "race"), + A = list(Vertices = c("hair", "eye"), + horizontal = FALSE), + B = list(Vertices = c("age"), + C = list(Vertices = c("education"))))) > Names <- unlist(Block.tree) > Names <- Names[grep("Vertices", names(Names))] > Types <- rep("Discrete", length(Names)) > vertices <- returnVertexList(Names, types = Types) > blocktree <- setTreeBlocks(Block.tree, vertices) > Labels(blockTreeToList(blocktree$BlockTree)) W X A B C "W" "X" "A" "B" "C" > > > > cleanEx(); ..nameEx <- "dg.Block-class" > > ### * dg.Block-class > > flush(stderr()); flush(stdout()) > > ### Name: dg.Block-class > ### Title: Class "dg.Block" > ### Aliases: dg.Block-class ancestors<-,dg.Block-method > ### ancestors,dg.Block-method closed<-,dg.Block-method > ### closed,dg.Block-method descendants<-,dg.Block-method > ### descendants,dg.Block-method draw,dg.Block-method > ### index<-,dg.Block-method index,dg.Block-method name,dg.Block-method > ### position<-,dg.Block-method position,dg.Block-method > ### stratum<-,dg.Block-method stratum,dg.Block-method > ### visible<-,dg.Block-method visible,dg.Block-method newBlock newBlock > ### dg.Block closed closed<- ancestors ancestors<- descendants > ### descendants<- > ### Keywords: classes > > ### ** Examples > > b <- newBlock() > str(b) Formal class 'dg.Block' [package "dynamicGraph"] with 10 slots ..@ stratum : num 0 ..@ index : num 0 ..@ ancestors : num 0 ..@ descendants : num 0 ..@ position : num [1:2, 1:3] 0 0 0 0 0 0 ..@ closed : logi FALSE ..@ visible : logi TRUE ..@ color : chr "Grey" ..@ label : chr "Label" ..@ label.position: num [1:3] 0 0 0 > > color(b) [1] "Grey" > label(b) [1] "Label" > labelPosition(b) [1] 0 0 0 > name(b) [1] "Label" > index(b) [1] 0 > position(b) [,1] [,2] [1,] 0 0 [2,] 0 0 [3,] 0 0 > stratum(b) [1] 0 > ancestors(b) [1] 0 > descendants(b) [1] 0 > visible(b) [1] TRUE > > color(b) <- "grey" > label(b) <- "NameAndLabel" > labelPosition(b) <- c(1, 2, 3) > # name(b) <- "NameAndLabel" # Not possible!!! > index(b) <- 3 > position(b) <- matrix(c( 10, 20, 30, 40, + 110, 120, 130, 140), byrow = TRUE, ncol = 4) > stratum(b) <- 1 > ancestors(b) <- c(1, 2) > descendants(b) <- c(4, 5) > visible(b) <- FALSE > > str(b) Formal class 'dg.Block' [package "dynamicGraph"] with 10 slots ..@ stratum : num 1 ..@ index : num -3 ..@ ancestors : num [1:2] 1 2 ..@ descendants : num [1:2] 4 5 ..@ position : num [1:4, 1:2] 10 20 30 40 110 120 130 140 ..@ closed : logi FALSE ..@ visible : logi FALSE ..@ color : chr "grey" ..@ label : chr "NameAndLabel" ..@ label.position: num [1:3] 1 2 3 > > > > cleanEx(); ..nameEx <- "dg.BlockEdge-class" > > ### * dg.BlockEdge-class > > flush(stderr()); flush(stdout()) > > ### Name: dg.BlockEdge-class > ### Title: Class "dg.BlockEdge" > ### Aliases: dg.BlockEdge-class nodeTypesOfEdge,dg.BlockEdge-method > ### oriented<-,dg.BlockEdge-method oriented,dg.BlockEdge-method > ### newBlockEdge newBlockEdge dg.BlockEdge > ### Keywords: classes > > ### ** Examples > > vertices <- returnVertexList(paste("V", 1:4, sep = "")) > block <- newBlock(stratum = 1) > blockedge <- newBlockEdge(c(4, -1), + new("dg.VertexList", list(vertices[[1]], block))) > > str(blockedge) Formal class 'dg.BlockEdge' [package "dynamicGraph"] with 7 slots ..@ oriented : logi TRUE ..@ dash : chr "" ..@ vertex.indices: num [1:2] 4 -1 ..@ width : num 2 ..@ color : chr "DarkOliveGreen" ..@ label : chr "V1~Label" ..@ label.position: num [1:3] 0 0 0 > > color(blockedge) [1] "DarkOliveGreen" > label(blockedge) [1] "V1~Label" > labelPosition(blockedge) [1] 0 0 0 > width(blockedge) [1] 2 > nodeIndicesOfEdge(blockedge) [1] 4 -1 > nodeTypesOfEdge(blockedge) [1] "Vertex" "Block" > > color(blockedge) <- "Black" Invalid color; > label(blockedge) <- "V1~1" > labelPosition(blockedge) <- c(0, 1, 2) > width(blockedge) <- 1 > nodeIndicesOfEdge(blockedge) <- c(1, -1) > > str(blockedge) Formal class 'dg.BlockEdge' [package "dynamicGraph"] with 7 slots ..@ oriented : logi TRUE ..@ dash : chr "" ..@ vertex.indices: num [1:2] 1 -1 ..@ width : num 1 ..@ color : chr "DarkOliveGreen" ..@ label : chr "V1~1" ..@ label.position: num [1:3] 0 1 2 > > > > cleanEx(); ..nameEx <- "dg.ExtraEdge-class" > > ### * dg.ExtraEdge-class > > flush(stderr()); flush(stdout()) > > ### Name: dg.ExtraEdge-class > ### Title: Class "dg.ExtraEdge" > ### Aliases: dg.ExtraEdge-class nodeTypesOfEdge,dg.ExtraEdge-method > ### newExtraEdge newExtraEdge dg.ExtraEdge > ### Keywords: classes > > ### ** Examples > > vertices <- returnVertexList(paste("V", 1:4, sep = "")) > extra <- returnVertexList(paste("E", 1:4, sep = "")) > extraedge <- newExtraEdge(c(3, -2), + new("dg.VertexList", c(vertices[3], extra[2]))) > str(extraedge) Formal class 'dg.ExtraEdge' [package "dynamicGraph"] with 6 slots ..@ dash : chr "" ..@ vertex.indices: num [1:2] 3 -2 ..@ width : num 2 ..@ color : chr "DarkOliveGreen" ..@ label : chr "V3~E2" ..@ label.position: num [1:3] 0 0 0 > > color(extraedge) [1] "DarkOliveGreen" > label(extraedge) [1] "V3~E2" > labelPosition(extraedge) [1] 0 0 0 > width(extraedge) [1] 2 > nodeIndicesOfEdge(extraedge) [1] 3 -2 > nodeTypesOfEdge(extraedge) [1] "Vertex" "Extra" > > color(extraedge) <- "Black" Invalid color; > label(extraedge) <- "Gryf" > labelPosition(extraedge) <- c(0, 1, 2) > width(extraedge) <- 1 > nodeIndicesOfEdge(extraedge) <- c(1, -1) > str(extraedge) Formal class 'dg.ExtraEdge' [package "dynamicGraph"] with 6 slots ..@ dash : chr "" ..@ vertex.indices: num [1:2] 1 -1 ..@ width : num 1 ..@ color : chr "DarkOliveGreen" ..@ label : chr "Gryf" ..@ label.position: num [1:3] 0 1 2 > > > > cleanEx(); ..nameEx <- "dg.FactorEdge-class" > > ### * dg.FactorEdge-class > > flush(stderr()); flush(stdout()) > > ### Name: dg.FactorEdge-class > ### Title: Class "dg.FactorEdge" > ### Aliases: dg.FactorEdge-class nodeTypesOfEdge,dg.FactorEdge-method > ### newFactorEdge newFactorEdge dg.FactorEdge > ### Keywords: classes > > ### ** Examples > > vertices <- returnVertexList(paste("V", 1:4, sep = "")) > factor <- newFactor(1:3, new("dg.VertexList", vertices[1:3]), + type = "Generator") > factoredge <- newFactorEdge(c(1, -1), + new("dg.VertexList", list(vertices[[1]], factor))) > str(factoredge) Formal class 'dg.FactorEdge' [package "dynamicGraph"] with 6 slots ..@ dash : chr "" ..@ vertex.indices: num [1:2] 1 -1 ..@ width : num 2 ..@ color : chr "DarkOliveGreen" ..@ label : chr "V1~V1:V2:V3" ..@ label.position: num [1:3] 0 0 0 > > color(factoredge) [1] "DarkOliveGreen" > label(factoredge) [1] "V1~V1:V2:V3" > labelPosition(factoredge) [1] 0 0 0 > width(factoredge) [1] 2 > nodeIndicesOfEdge(factoredge) [1] 1 -1 > nodeTypesOfEdge(factoredge) [1] "Vertex" "Factor" > > color(factoredge) <- "Black" Invalid color; > label(factoredge) <- "V1~V1:2:3" > labelPosition(factoredge) <- c(0, 1, 2) > width(factoredge) <- 1 > nodeIndicesOfEdge(factoredge) <- c(1, -1) > str(factoredge) Formal class 'dg.FactorEdge' [package "dynamicGraph"] with 6 slots ..@ dash : chr "" ..@ vertex.indices: num [1:2] 1 -1 ..@ width : num 1 ..@ color : chr "DarkOliveGreen" ..@ label : chr "V1~V1:2:3" ..@ label.position: num [1:3] 0 1 2 > > > > cleanEx(); ..nameEx <- "dg.FactorVertex-class" > > ### * dg.FactorVertex-class > > flush(stderr()); flush(stdout()) > > ### Name: dg.FactorVertex-class > ### Title: Class "dg.FactorVertex" > ### Aliases: dg.FactorVertex-class nodeIndices<-,dg.FactorVertex-method > ### nodeIndices,dg.FactorVertex-method index<-,dg.FactorVertex-method > ### index,dg.FactorVertex-method newFactor dg.FactorVertex newFactor > ### nodeIndices nodeIndices<- > ### Keywords: classes > > ### ** Examples > > vertices <- returnVertexList(paste("V", 1:4, sep = ""), + types = rep("Discrete", 4)) > factor <- newFactor(c(1, 2, 3), new("dg.VertexList", vertices[1:3]), + type = "Generator") > > str(factor) Formal class 'dg.Generator' [package "dynamicGraph"] with 9 slots ..@ vertex.indices: num [1:3] 1 2 3 ..@ name : chr "V1:V2:V3" ..@ index : num 0 ..@ position : Named num [1:3] -1.33e+01 2.37e-15 0.00e+00 .. ..- attr(*, "names")= chr [1:3] "X" "Y" "Z-3" ..@ blockindex : num 0 ..@ stratum : num 0 ..@ color : chr "yellow" ..@ label : chr "V1:V2:V3" ..@ label.position: num [1:3] 0 0 0 > > color(factor) [1] "yellow" > label(factor) [1] "V1:V2:V3" > labelPosition(factor) [1] 0 0 0 > name(factor) [1] "V1:V2:V3" > index(factor) [1] 0 > position(factor) X Y Z-3 -1.333333e+01 2.368476e-15 0.000000e+00 > nodeIndices(factor) [1] 1 2 3 > > color(factor) <- "green" > label(factor) <- "v-1-2-3" > labelPosition(factor) <- c(1, 2, 3) > name(factor) <- "V-123" > index(factor) <- 3 > position(factor) <- c( 10, 20, 30, 40) > > str(factor) Formal class 'dg.Generator' [package "dynamicGraph"] with 9 slots ..@ vertex.indices: num [1:3] 1 2 3 ..@ name : chr "V-123" ..@ index : num -3 ..@ position : num [1:4] 10 20 30 40 ..@ blockindex : num 0 ..@ stratum : num 0 ..@ color : chr "green" ..@ label : chr "v-1-2-3" ..@ label.position: num [1:3] 1 2 3 > > > > cleanEx(); ..nameEx <- "dg.Model-class" > > ### * dg.Model-class > > flush(stderr()); flush(stdout()) > > ### Name: dg.Model-class > ### Title: Class "dg.Model" > ### Aliases: dg.Model-class modifyModel,dg.Model-method > ### testEdge,dg.Model-method setGraphComponents,dg.Model-method > ### returnGraphComponents,dg.Model-method graphComponents,dg.Model-method > ### vertexEdges,dg.Model-method vertexEdges<-,dg.Model-method > ### Str,dg.Model-method setGraphComponents returnGraphComponents > ### graphComponents vertexEdges vertexEdges<- newDefaultModelObject > ### newDefaultModelObject modifyModel testEdge > ### Keywords: classes > > ### ** Examples > > # Part of the example "defaultObjects" of demo: > > # Edit the following to meet your needs: > # > # - Change the name "your.Model" > # > # - Work out how the get names, types and edges from the model object. > # > # - At "message", insert the relevant code for testing and modifying the model. > # > # - The slots visibleVertices, visibleBlocks, extraVertices, vertexEdges, > # blockEdges, factorVertices, factorEdges, and, extraEdges should be > # eliminated, and you should in "graphComponents" return relevant lists. > # > > > setClass("your.Model", + representation(name = "character", + visibleVertices = "numeric", + visibleBlocks = "numeric", + extraVertices = "dg.VertexList", + vertexEdges = "dg.VertexEdgeList", + blockEdges = "dg.BlockEdgeList", + factorVertices = "dg.FactorVertexList", + factorEdges = "dg.FactorEdgeList", + extraEdges = "dg.ExtraEdgeList")) [1] "your.Model" > > "newYourModelObject"<- function(name) { + result <- new("your.Model", name = name, + extraVertices = .emptyDgList("dg.VertexList"), + vertexEdges = .emptyDgList("dg.VertexEdgeList"), + blockEdges = .emptyDgList("dg.BlockEdgeList"), + factorVertices = .emptyDgList("dg.FactorVertexList"), + factorEdges = .emptyDgList("dg.FactorEdgeList"), + extraEdges = .emptyDgList("dg.ExtraEdgeList")) + return(result) + } > > if (!isGeneric("graphComponents")) { + if (is.function("graphComponents")) + fun <- graphComponents + else + fun <- function(object, viewType = NULL, ...) + standardGeneric("graphComponents") + setGeneric("graphComponents", fun) + } > > setMethod("graphComponents", "your.Model", + function(object, viewType = NULL, ...) + { # print(viewType); print ("graphComponents") + args <- list(...) + Args <- args$Arguments + Edges <- object@vertexEdges + Vertices <- Args$vertexList + VisibleVertices <- object@visibleVertices + if (viewType == "Factor") { + factors <- .cliquesFromEdges(Edges, Vertices, VisibleVertices) + if (is.null(factors) || (length(factors) == 0)) { + FactorVertices <- .emptyDgList("dg.FactorVertexList") + FactorEdges <- .emptyDgList("dg.FactorEdgeList") + } else { + result <- returnFactorVerticesAndEdges(Vertices, factors) + FactorVertices <- result$FactorVertices + FactorEdges <- result$FactorEdges + } + list(vertexEdges = object@vertexEdges, + blockEdges = object@blockEdges, + factorVertices = FactorVertices, + factorEdges = FactorEdges, + visibleVertices = object@visibleVertices, + visibleBlocks = object@visibleBlocks, + extraVertices = object@extraVertices, + extraEdges = object@extraEdges) + } else if (viewType == "Moral") { + message("Moral view not implemented; ") + list(vertexEdges = object@vertexEdges, + blockEdges = .emptyDgList("dg.BlockEdgeList"), + factorVertices = .emptyDgList("dg.FactorVertexList"), + factorEdges = .emptyDgList("dg.FactorEdgeList"), + visibleVertices = object@visibleVertices, + visibleBlocks = numeric(), + extraVertices = object@extraVertices, + extraEdges = object@extraEdges) + } else if (viewType == "Essential") { + message("Essential view not implemented; ") + list(vertexEdges = object@vertexEdges, + blockEdges = .emptyDgList("dg.BlockEdgeList"), + factorVertices = .emptyDgList("dg.FactorVertexList"), + factorEdges = .emptyDgList("dg.FactorEdgeList"), + visibleVertices = object@visibleVertices, + visibleBlocks = numeric(), + extraVertices = object@extraVertices, + extraEdges = object@extraEdges) + } else if (viewType == "Simple") { + list(vertexEdges = object@vertexEdges, + blockEdges = object@blockEdges, + factorVertices = .emptyDgList("dg.FactorVertexList"), + factorEdges = .emptyDgList("dg.FactorEdgeList"), + visibleVertices = object@visibleVertices, + visibleBlocks = object@visibleBlocks, + extraVertices = object@extraVertices, + extraEdges = object@extraEdges) + } else + message("View type not implemented; ") + }) [1] "graphComponents" > > if (!isGeneric("setGraphComponents")) { + if (is.function("setGraphComponents")) + fun <- setGraphComponents + else + fun <- function(object, viewType = NULL, + visibleVertices = NULL, + extraVertices = NULL, + vertexEdges = NULL, + blockEdges = NULL, + factorVertices = NULL, + factorEdges = NULL, + extraEdges = NULL, ...) + standardGeneric("setGraphComponents") + setGeneric("setGraphComponents", fun) + } > > setMethod("setGraphComponents", signature(object = "your.Model"), + function(object, viewType = NULL, + visibleVertices = NULL, + visibleBlocks = NULL, + extraVertices = NULL, + vertexEdges = NULL, + blockEdges = NULL, + factorVertices = NULL, + factorEdges = NULL, + extraEdges = NULL, ...) + { + if (!is.null(visibleVertices)) object@visibleVertices <- visibleVertices + if (!(viewType == "Moral")) + if (!is.null(visibleBlocks )) object@visibleBlocks <- visibleBlocks + if (!is.null(extraVertices )) object@extraVertices <- extraVertices + if (!is.null(vertexEdges )) object@vertexEdges <- vertexEdges + if (!is.null(blockEdges )) object@blockEdges <- blockEdges + if ((viewType == "Factor")) { + if (!is.null(factorVertices )) object@factorVertices <- factorVertices + if (!is.null(factorEdges )) object@factorEdges <- factorEdges + } + return(object) + }) [1] "setGraphComponents" > > if (!isGeneric("dynamic.Graph")) { + if (is.function("dynamic.Graph")) + fun <- dynamic.Graph + else + fun <- function(object, ...) + standardGeneric("dynamic.Graph") + setGeneric("dynamic.Graph", fun) + } [1] "dynamic.Graph" > > setMethod("dynamic.Graph", signature(object = "your.Model"), + function(object, ...) + { + + Names <- Your.function.for.extracting.variable.names.from.object( + object = object) + Types <- Your.function.for.extracting.variable.types.from.object( + object = object) + Edges <- Your.function.for.extracting.variable.edges.from.object( + object = object) + + DynamicGraph(names = Names, types = Types, + from = Edges[,1], to = Edges[,2], + object = object, ...) + }) [1] "dynamic.Graph" > > if (!isGeneric("testEdge")) { + if (is.function("testEdge")) + fun <- testEdge + else + fun <- function(object, action, name.1, name.2, ...) + standardGeneric("testEdge") + setGeneric("testEdge", fun) + } [1] "testEdge" > > setMethod("testEdge", signature(object = "your.Model"), + function(object, action, name.1, name.2, ...) + { + args <- list(...) + from.type <- args$from.type + to.type <- args$to.type + f <- function(type) if(is.null(type)) "" else paste("(", type, ")") + message(paste("Should return an object with the edge from", + name.1, f(from.type), "to", name.2, f(to.type), + "deleted from the argument object")) + return(newYourTestObject()) + }) [1] "testEdge" > > if (!isGeneric("modifyModel")) { + if (is.function("modifyModel")) + fun <- modifyModel + else + fun <- function(object, action, name, name.1, name.2, ...) + standardGeneric("modifyModel") + setGeneric("modifyModel", fun) + } [1] "modifyModel" > > setMethod("modifyModel", signature(object = "your.Model"), + function(object, action, name, name.1, name.2, ...) + { + args <- list(...) + Args <- args$Arguments + Edges <- args$newEdges$vertexEdges + Vertices <- Args$vertexList + + DoFactors <- FALSE + if (!is.null(args$Arguments) + && !is.null(args$Arguments$factorVertexList) + && (length(args$Arguments$factorVertexList) > 0) + && !is.null(args$Arguments$vertexList)) + DoFactors <- TRUE + + FactorVertices <- NULL + FactorEdges <- NULL + BlockEdges <- NULL + VisibleVertices <- Args$visibleVertices + VisibleBlocks <- Args$visibleBlocks + ExtraVertices <- NULL + ExtraEdges <- NULL + + f <- function(type) if (is.null(type)) "" else paste("(", type, ")") + g <- function(type) if (is.null(type)) "" else type + if (action == "dropEdge") { + message(paste("Should return an object with the edge from", + name.1, f(args$from.type), "to", name.2, f(args$to.type), + "deleted from the argument object")) + if ((g(args$from.type) == "Factor") || (g(args$from.type) == "Factor")) + return(NULL) + } else if (action == "addEdge") { + message(paste("Should return an object with the edge from", + name.1, f(args$from.type), "to", name.2, f(args$to.type), + "added to the argument object")) + if ((g(args$from.type) == "Factor") || (g(args$from.type) == "Factor")) + return(NULL) + } else if (action == "dropVertex") { + message(paste("Should return an object with the vertex", + name, f(args$type), + "deleted from the argument object")) + if ((g(args$type) == "Factor")) + return(NULL) + VisibleVertices <- VisibleVertices[VisibleVertices != args$index] + if (DoFactors && (args$index > 0)) { + x <- (args$Arguments$factorVertexList) + factors <- lapply(x, function(i) i@vertex.indices) + types <- lapply(x, function(i) class(i)) + factors <- lapply(factors, + function(x) { + y <- x[x != args$index] + if (length(y) > 0) return(y) else return(NULL) } ) + + if (!is.null(factors)) { + types <- types[unlist(lapply(factors, function(i) !is.null(i)))] + factors <- .removeNull(factors) + } + if (!is.null(factors)) { + subset <- function(x) + lapply(x, function(a) + any(unlist(lapply(x, + function(A) + all(!is.na(match(a, A))) && + (length(a) < length(A)))))) + s <- subset(factors) + types <- types[!unlist(s)] + factors <- factors[!unlist(s)] + if (!(is.null(factors))) { + result <- returnFactorVerticesAndEdges( + args$Arguments$vertexList, factors, types, + factorClasses = validFactorClasses()) + FactorVertices <- result$FactorVertices + FactorEdges <- result$FactorEdges + } + } else { + DoFactors <- FALSE + FactorVertices <- .emptyDgList("dg.FactorVertexList") + FactorEdges <- .emptyDgList("dg.FactorEdgeList") + } + } + } else if (action == "addVertex") { + VisibleVertices <- c(VisibleVertices, args$index) + message(paste("Should return an object with the vertex", + name, f(args$type), args$index, + "added to the argument object")) + if (DoFactors && (args$index > 0)) { + x <- (args$Arguments$factorVertexList) + factors <- lapply(x, function(i) i@vertex.indices) + types <- lapply(x, function(i) class(i)) + if (!is.null(factors)) + factors <- .removeNull(factors) + if (is.null(factors)) { + factors <- list(args$index) + types <- validFactorClasses()[1, 1] + } else { + n <- length(types) + factors <- append(factors, list(args$index)) + types <- append(types, types[n]) + } + if (!(is.null(factors))) { + result <- returnFactorVerticesAndEdges( + args$Arguments$vertexList, factors, types, + factorClasses = validFactorClasses()) + FactorVertices <- result$FactorVertices + FactorEdges <- result$FactorEdges } } + } + if (is.null(FactorVertices) && DoFactors && !is.null(Edges)) { + + factors <- .cliquesFromEdges(Edges, Vertices, VisibleVertices) + + if (is.null(factors) || (length(factors) == 0)) { + FactorVertices <- .emptyDgList("dg.FactorVertexList") + FactorEdges <- .emptyDgList("dg.FactorEdgeList") + } else { + result <- returnFactorVerticesAndEdges(Vertices, factors) + FactorVertices <- result$FactorVertices + FactorEdges <- result$FactorEdges } } + return(list(object = object, + BlockEdges = BlockEdges, + FactorVertices = FactorVertices, + FactorEdges = FactorEdges, + VisibleVertices = VisibleVertices, + VisibleBlocks = VisibleBlocks, + ExtraVertices = ExtraVertices, + ExtraEdges = ExtraEdges)) + }) [1] "modifyModel" > > setMethod("Str", "your.Model", + function(object, setRowLabels = FALSE, title = "", ...) { + message(object@name) }) [1] "Str" > > newYourModelObject("ModelObject") An object of class "your.Model" Slot "name": [1] "ModelObject" Slot "visibleVertices": numeric(0) Slot "visibleBlocks": numeric(0) Slot "extraVertices": Slot "vertexEdges": Slot "blockEdges": Slot "factorVertices": Slot "factorEdges": Slot "extraEdges": > > > > cleanEx(); ..nameEx <- "dg.Test-class" > > ### * dg.Test-class > > flush(stderr()); flush(stdout()) > > ### Name: dg.Test-class > ### Title: Class "dg.Test" > ### Aliases: dg.Test-class label,dg.Test-method width,dg.Test-method > ### newDefaultTestObject > ### Keywords: classes > > ### ** Examples > > # Part of the example "defaultObjects" of demo: > > setClass("your.Test", + representation(deviance = "numeric", df = "numeric", p = "numeric")) [1] "your.Test" > > "newYourTestObject" <- function(name) { + df <- round(runif(1, 1, 25)) + message("Just generating a random test!!!!!") + deviance <- rchisq(1, df) + p <- 1 - pchisq(deviance, df) + result <- new("your.Test", df = df, deviance = deviance, p = p) + return(result) + } > > if (!isGeneric("label") && !isGeneric("label", where = 2)) { + if (is.function("label")) + fun <- label + else + fun <- function(object) standardGeneric("label") + setGeneric("label", fun) + } > > setMethod("label", "your.Test", + function(object) format(object@p, digits = 4)) [1] "label" > > if (!isGeneric("width") && !isGeneric("width", where = 2)) { + if (is.function("width")) + fun <- width + else + fun <- function(object) standardGeneric("width") + setGeneric("width", fun) + } > > setMethod("width", "your.Test", + function(object) round(2 + 5 * (1 - object@p))) [1] "width" > > newYourTestObject("TestObject") Just generating a random test!!!!! An object of class "your.Test" Slot "deviance": [1] 4.923109 Slot "df": [1] 7 Slot "p": [1] 0.6693462 > > > > cleanEx(); ..nameEx <- "dg.Vertex-class" > > ### * dg.Vertex-class > > flush(stderr()); flush(stdout()) > > ### Name: dg.Vertex-class > ### Title: Class "dg.Vertex" > ### Aliases: dg.Vertex-class ancestors<-,dg.Vertex-method > ### ancestors,dg.Vertex-method blockindex<-,dg.Vertex-method > ### blockindex,dg.Vertex-method descendants<-,dg.Vertex-method > ### descendants,dg.Vertex-method index<-,dg.Vertex-method > ### index,dg.Vertex-method name<-,dg.Vertex-method name,dg.Vertex-method > ### position<-,dg.Vertex-method position,dg.Vertex-method > ### stratum<-,dg.Vertex-method stratum,dg.Vertex-method > ### visible<-,dg.Vertex-method visible,dg.Vertex-method newVertex dg.Node > ### dg.Vertex newVertex draw color color<- label label<- labelPosition > ### labelPosition<- name name<- index index<- position position<- stratum > ### stratum<- blockindex blockindex<- visible visible<- addToPopups > ### propertyDialog > ### Keywords: classes > > ### ** Examples > > > a <- newVertex("a", "A", "Discrete", 1, c(0, 0, 0)) > > str(a) Formal class 'dg.DiscreteVertex' [package "dynamicGraph"] with 8 slots ..@ name : chr "a" ..@ index : num 1 ..@ position : num [1:3] 0 0 0 ..@ blockindex : num 0 ..@ stratum : num 0 ..@ color : chr "SaddleBrown" ..@ label : chr "A" ..@ label.position: num [1:3] 0 0 0 > > color(a) [1] "SaddleBrown" > label(a) [1] "A" > labelPosition(a) [1] 0 0 0 > name(a) [1] "a" > index(a) [1] 1 > position(a) [1] 0 0 0 > stratum(a) [1] 0 > > color(a) <- "red" > label(a) <- "A vertex" > labelPosition(a) <- c(1, 2, 3) > name(a) <- "Capital.A" > index(a) <- -1 > position(a) <- c(10, 20, 30) > stratum(a) <- 1 > > str(a) Formal class 'dg.DiscreteVertex' [package "dynamicGraph"] with 8 slots ..@ name : chr "Capital.A" ..@ index : num -1 ..@ position : num [1:3] 10 20 30 ..@ blockindex : num 0 ..@ stratum : num 1 ..@ color : chr "red" ..@ label : chr "A vertex" ..@ label.position: num [1:3] 1 2 3 > > > > > > > cleanEx(); ..nameEx <- "dg.VertexEdge-class" > > ### * dg.VertexEdge-class > > flush(stderr()); flush(stdout()) > > ### Name: dg.VertexEdge-class > ### Title: Class "dg.VertexEdge" > ### Aliases: dg.VertexEdge-class nodeTypesOfEdge,dg.VertexEdge-method > ### oriented<-,dg.VertexEdge-method oriented,dg.VertexEdge-method > ### dg.VertexEdge-class dg.DashedEdge-class dg.DottedEdge-class > ### dg.DoubleArrowEdge-class dg.DoubleConnectedEdge-class > ### dg.TripleConnectedEdge-class newVertexEdge dg.Edge dg.VertexEdge > ### dg.DashedEdge dg.DottedEdge dg.DoubleArrowEdge dg.DoubleConnectedEdge > ### dg.TripleConnectedEdge newVertexEdge nodeIndicesOfEdge > ### nodeIndicesOfEdge<- nodeTypesOfEdge width width<- dash dash<- > ### oriented oriented<- > ### Keywords: classes > > ### ** Examples > > vertices <- returnVertexList(paste("V", 1:4, sep = "")) > e <- newVertexEdge(c(1, 2, 3), vertices = new("dg.VertexList", vertices[1:3])) > > str(e) Formal class 'dg.VertexEdge' [package "dynamicGraph"] with 7 slots ..@ oriented : logi FALSE ..@ dash : chr "" ..@ vertex.indices: num [1:3] 1 2 3 ..@ width : num 2 ..@ color : chr "DarkOliveGreen" ..@ label : chr "V1~V2~V3" ..@ label.position: num [1:3] 0 0 0 > > color(e) [1] "DarkOliveGreen" > label(e) [1] "V1~V2~V3" > labelPosition(e) [1] 0 0 0 > width(e) [1] 2 > oriented(e) [1] FALSE > nodeIndicesOfEdge(e) [1] 1 2 3 > nodeTypesOfEdge(e) [1] "Vertex" "Vertex" "Vertex" > > color(e) <- "Black" Invalid color; > label(e) <- "1-2" > labelPosition(e) <- c(10, 20, 30) > width(e) <- 1 > oriented(e) <- TRUE > nodeIndicesOfEdge(e) <- c(1, 2) > > str(e) Formal class 'dg.VertexEdge' [package "dynamicGraph"] with 7 slots ..@ oriented : logi TRUE ..@ dash : chr "" ..@ vertex.indices: num [1:2] 1 2 ..@ width : num 1 ..@ color : chr "DarkOliveGreen" ..@ label : chr "1-2" ..@ label.position: num [1:3] 10 20 30 > > > > > > > cleanEx(); ..nameEx <- "drawModel" > > ### * drawModel > > flush(stderr()); flush(stdout()) > > ### Name: drawModel > ### Title: Draw the dynamicGraph window and slaves > ### Aliases: drawModel redrawView redrawGraphWindow menu > ### Keywords: methods > > ### ** Examples > > # The use of "drawModel" and "redrawView" by > # "DynamicGraph" in the example "usermenus" of demo: > > your.DrawModel <- function(object, slave = FALSE, viewType = "Simple", ...) { + args <- list(...) + Args <- args$Arguments + + # Here you should make your new model (this is just a copy): + + Object <- object + title <- Object@name + + # and compute edges (here 'NULL' if the model not has been updated): + + Edges <- graphComponents(Object, viewType, Arguments = Args) + EdgeList <- Edges$vertexEdges + ExtraVertices <- Edges$extraVertices + FactorVertices <- Edges$factorVertices + FactorEdges <- Edges$factorEdges + BlockEdges <- Edges$blockEdges + ExtraEdges <- Edges$extraEdges + visualVertices <- Edges$visualVertices + visualBlocks <- Edges$visualBlocks + + if (slave) { + # Drawing ''an other model'' in a new window: + DynamicGraph(addModel = TRUE, # <- + frameModels = Args$frameModels, + frameViews = NULL, # <- not used here + graphWindow = NULL, # <- not used here + edgeList = EdgeList, + object = Object, + extraList = ExtraVertices, + extraEdgeList = ExtraEdges, + factorVertexList = FactorVertices, + factorEdgeList = FactorEdges, + blockEdgeList = BlockEdges, + visualVertices = visualVertices, + visualBlocks = visualBlocks, + title = title, + Arguments = Args) + } else { + # Overwriting with ''an other model'' in same view: + DynamicGraph(overwrite = TRUE, # <- + addModel = TRUE, # <- + frameModels = Args$frameModels, + frameViews = Args$frameViews, + graphWindow = Args$graphWindow, # <- + edgeList = EdgeList, + object = Object, + extraList = ExtraVertices, + extraEdgeList = ExtraEdges, + factorVertexList = FactorVertices, + factorEdgeList = FactorEdges, + blockEdgeList = BlockEdges, + visualVertices = visualVertices, + visualBlocks = visualBlocks, + title = "Not used!", + width = NULL, height = NULL, + Arguments = Args) } + } > > your.LabelAllEdges <- function(object, slave = FALSE, ...) + { + args <- list(...) + Args <- args$Arguments + + getNodeName <- function(index, type) + if (type == "Vertex") + name(Args$vertexList[[index]]) + else if (type == "Factor") + name(Args$factorVertexList[[abs(index)]]) + else if (type == "Extra") + name(Args$extraList[[abs(index)]]) + else if (type == "Block") + label(Args$blockList[[abs(index)]]) + else + NULL + + visitEdges <- function(edges) { + for (i in seq(along = edges)) { + vertices <- nodeIndicesOfEdge(edges[[i]]) + types <- nodeTypesOfEdge(edges[[i]]) + + name.f <- getNodeName(vertices[1], types[1]) + name.t <- getNodeName(vertices[2], types[2]) + + R <- testEdge(object, action = "remove", + name.1 = name.f, name.2 = name.t, + from = vertices[1], to = vertices[2], + from.type = types[1], to.type = types[2], + edge.index = i, force = force, Arguments = Args) + + if (!is.null(R)) { + if (TRUE || (hasMethod("label", class(R)))) + label(edges[[i]]) <- label(R) + if (TRUE || (hasMethod("width", class(R)))) + width(edges[[i]]) <- width(R) + } + } + return(edges) + } + + edgeList <- visitEdges(Args$edgeList) + factorEdgeList <- visitEdges(Args$factorEdgeList) + blockEdgeList <- visitEdges(Args$blockEdgeList) + + if (slave) { + # Adding an other view of the same model: + DynamicGraph(addView = TRUE, # <- + frameModels = Args$frameModels, + frameViews = Args$frameViews, + graphWindow = NULL, # <- not used here + edgeList = edgeList, + factorEdgeList = factorEdgeList, + blockEdgeList = blockEdgeList, + title = "A slave window", + Arguments = Args) + } else { + # Overwriting with an other view of the same model: + DynamicGraph(overwrite = TRUE, # <- + addView = TRUE, # <- + frameModels = Args$frameModels, + frameViews = Args$frameViews, + graphWindow = Args$graphWindow, # <- + edgeList = edgeList, + factorEdgeList = factorEdgeList, + blockEdgeList = blockEdgeList, + title = "Not used!", + width = NULL, height = NULL, + Arguments = Args) } + } > > palle <- function(...) print("Palle") > palle <- function(...) print(list(...)$Arguments$object@name) > > Menus <- + list(MainUser = + list(label = "Transformation by 'prcomp' on position of \"vertices\", and redraw", + command = function(object, ...) { + Args <- list(...)$Arguments + transformation <- t(prcomp(Positions(Args$vertexList))$rotation) + Args$redrawView(graphWindow = Args$graphWindow, + transformation = transformation, Arguments = Args) + }), + MainUser = + list(label = "Position of \"vertices\" by 'cmdscale', and redraw", + command = function(object, ...) { + Args <- list(...)$Arguments + Vertices <- Args$vertexList + Edges <- Args$edgeList + positions <- Positions(Args$vertexList) + N <- dim(positions)[2] + e <- NodeIndices(Edges) + n <- Names(Vertices) + X <- matrix(rep(-1, length(n)^2), ncol = length(n)) + for (i in 1:length(e)) { + suppressWarnings(w <- as.numeric(names(e)[i])) + if (is.na(w)) w <- .5 + X[e[[i]][1], e[[i]][2]] <- w + X[e[[i]][2], e[[i]][1]] <- w + } + dimnames(X) <- list(n, n) + d <- 1.25 + X[X==-1] <- d + X <- X - d * diag(length(n)) + mdsX <- cmdscale(X, k = N, add = TRUE, eig = TRUE, x.ret = TRUE) + # mdsX <- isoMDS(X, k = N) + M <- max(abs(mdsX$points)) + Positions(Args$vertexList) <<- mdsX$points / M * 45 + Args$redrawView(graphWindow = Args$graphWindow, + # Positions = Positions(Args$vertexList), + vertexList = Args$vertexList, Arguments = Args) + }), + MainUser = + list(label = "Position of \"vertices\"", + command = function(object, ...) + print(Positions(list(...)$Arguments$vertexList))), + MainUser = + list(label = "Label all edges, in this window", + command = function(object, ...) + your.LabelAllEdges(object, slave = FALSE, ...)), + MainUser = + list(label = "Label all edges, in slave window", + command = function(object, ...) + your.LabelAllEdges(object, slave = TRUE, ...)), + MainUser = + list(label = "Draw model, in this window", + command = function(object, ...) + your.DrawModel(object, slave = FALSE, ...)), + MainUser = + list(label = "Draw model, in slave window", + command = function(object, ...) + your.DrawModel(object, slave = TRUE, ...)), + MainUser = + list(label = "Call of function 'modalDialog', result on 'title' at top", + command = function(object, ...) { + Args <- list(...)$Arguments + ReturnVal <- modalDialog("Test modalDialog Entry", + "Enter name", Args$title, + top = Args$top) + print(ReturnVal) + if (ReturnVal == "ID_CANCEL") + return() + tktitle(Args$top) <- ReturnVal } ), + MainUser = + list(label = "Call of function 'palle', result on 'viewLabel' at bottom", + command = function(object, ...) { + Args <- list(...)$Arguments + tkconfigure(Args$viewLabel, + text = paste(Args$viewType, " | ", palle(...))) } ), + Vertex = + list(label = "Test of user popup menu for vertices: Label", + command = function(object, name, ...) { + # print(name) + args <- list(...) + # print(names(args)) + # print(c(args$type)) + # print(c(args$index)) + Args <- args$Arguments + print(Args$vertexList[[args$index]]@label) } ), + Edge = + list(label = "Test of user popup menu for edges: Class", + command = function(object, name1, name2, ...) { + args <- list(...) + # print(c(name1, name2)) + # print(c(args$edge.index, args$which.edge, args$from, args$to)) + # print(c(args$from.type, args$to.type, args$edge.type)) + Args <- list(...)$Arguments + ReturnVal <- selectDialog("Test selectDialog Entry", + "Select name", Args$edgeClasses[,1], + top = Args$top) + print(ReturnVal) + if (ReturnVal == "ID_CANCEL") + return() + if ((args$from > 0) && (args$to > 0)) { + edgeList <- Args$edgeList + class(edgeList[[args$edge.index]]) <- + Args$edgeClasses[ReturnVal, 2] + # vertexEdges(Args$object) <<- edgeList # Not working !!! + Args$redrawView(graphWindow = Args$graphWindow, + edgeList = edgeList, title = "Not used!", + width = NULL, height = NULL, Arguments = Args) + } } ), + ClosedBlock = + list(label = "Test of user popup menu for blocks", + command = function(object, name, ...) { + print(name) + print(c(list(...)$index)) } ) + ) > > > > cleanEx(); ..nameEx <- "dynamicGraphMain" > > ### * dynamicGraphMain > > flush(stderr()); flush(stdout()) > > ### Name: dynamicGraphMain > ### Title: Dynamic Graph > ### Aliases: dynamicGraphMain dynamicGraph > ### Keywords: dplot hplot iplot dynamic graphs methods multivariate > > ### ** Examples > > require(tcltk) [1] TRUE > require(dynamicGraph) [1] TRUE > > V.Names <- paste(c("Sex", "Age", "Eye", "FEV", "Hair", "Shosize"), + 1:6, sep ="/") > > V.Types <- c("Discrete", "Ordinal", "Discrete", + "Continuous", "Discrete", "Continuous") > > Vertices <- returnVertexList(V.Names, types = V.Types, color = "red") > > From <- c(1, 2, 3, 4, 5, 6) > To <- c(2, 3, 4, 5, 6, 1) > > EdgeList <- vector("list", length(To)) > for (j in seq(along = To)) EdgeList[[j]] <- c(From[j], To[j]) > Edges <- returnEdgeList(EdgeList, Vertices, color = "black") > > Z <- dynamicGraphMain(Vertices, edgeList = Edges, w = 4) (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > > > cleanEx(); ..nameEx <- "modalDialog" > > ### * modalDialog > > flush(stderr()); flush(stdout()) > > ### Name: modalDialog > ### Title: Modal dialog window for returning a text string > ### Aliases: modalDialog > ### Keywords: dynamic > > ### ** Examples > > Menus <- + list(MainUser = + list(label = "Test of user drag down menu - Position of \"vertices\"", + command = function(object, ...) + print(Positions(list(...)$Arguments$vertexList))), + MainUser = + list(label = "Test of user drag down menu - modalDialog", + command = function(object, ...) { + Args <- list(...)$Arguments + ReturnVal <- modalDialog("Test modalDialog Entry", "Enter name", + Args$title, graphWindow = Args$graphWindow) + print(ReturnVal) + if (ReturnVal == "ID_CANCEL") + return() } ) + ) > > > > cleanEx(); ..nameEx <- "nameToVertexIndex" > > ### * nameToVertexIndex > > flush(stderr()); flush(stdout()) > > ### Name: nameToVertexIndex > ### Title: The indices of vertices > ### Aliases: nameToVertexIndex > ### Keywords: dynamic graphs > > ### ** Examples > > Names <- c("Sex", "Age", "Eye", "FEV", "Hair", "Shosize") > Types <- rep("Discrete", 6) > vertices <- returnVertexList(Names, types = Types) > nameToVertexIndex(c("Sex", "Eye"), vertices) [1] 1 3 > > > > cleanEx(); ..nameEx <- "returnBlockEdgeList" > > ### * returnBlockEdgeList > > flush(stderr()); flush(stdout()) > > ### Name: returnBlockEdgeList > ### Title: Class "dg.BlockEdgeList": The block edge list > ### Aliases: blockEdgeList returnBlockEdgeList dg.BlockEdgeList-class > ### Keywords: methods dynamic graphs > > ### ** Examples > > Block.tree <- list(label = "W", Vertices = c("country"), + X = list(Vertices = c("sex", "race"), + A = list(Vertices = c("hair", "eye"), + horizontal = FALSE), + B = list(Vertices = c("age"), + C = list(Vertices = c("education"))))) > Names <- unlist(Block.tree) > Names <- Names[grep("Vertices", names(Names))] > Types <- rep("Discrete", length(Names)) > vertices <- returnVertexList(Names, types = Types) > blocktree <- setTreeBlocks(Block.tree, vertices) > blocks <- blockTreeToList(blocktree$BlockTree) > from <- c("country", "country", "race", "race", "sex", "sex") > to <- c( "sex", "race", "hair", "eye", "education", "age") > from <- match(from, Names) > to <- match(to, Names) > edge.list <- vector("list", length(to)) > for (j in seq(along = to)) edge.list[[j]] <- c(from[j], to[j]) > edges <- returnEdgeList(edge.list, vertices, color = "red", oriented = TRUE) > vertices <- blocktree$Vertices > blockedges <- returnBlockEdgeList(edge.list, vertices, blocks, + color = "red", oriented = TRUE) > > Names(blockedges) [1] "country~X" "W~sex" "W~X" "W~race" "race~A" [6] "X~hair" "X~A" "X~eye" "sex~C" "sex~B" [11] "X~education" "X~C" "X~age" "X~B" > Colors(blockedges) country~X W~sex W~X W~race race~A X~hair "red" "red" "red" "red" "red" "red" X~A X~eye sex~C sex~B X~education X~C "red" "red" "red" "red" "red" "red" X~age X~B "red" "red" > Labels(blockedges) country~X W~sex W~X W~race race~A "country~X" "W~sex" "W~X" "W~race" "race~A" X~hair X~A X~eye sex~C sex~B "X~hair" "X~A" "X~eye" "sex~C" "sex~B" X~education X~C X~age X~B "X~education" "X~C" "X~age" "X~B" > LabelPositions(blockedges) X Y Z-3 country~X 0 0 0 W~sex 0 0 0 W~X 0 0 0 W~race 0 0 0 race~A 0 0 0 X~hair 0 0 0 X~A 0 0 0 X~eye 0 0 0 sex~C 0 0 0 sex~B 0 0 0 X~education 0 0 0 X~C 0 0 0 X~age 0 0 0 X~B 0 0 0 > # Positions(blockedges) > # Strata(blockedges) > # Indices(blockedges) > str(NodeTypes(blockedges)) List of 14 $ country~X : chr [1:2] "Vertex" "Block" $ W~sex : chr [1:2] "Block" "Vertex" $ W~X : chr [1:2] "Block" "Block" $ W~race : chr [1:2] "Block" "Vertex" $ race~A : chr [1:2] "Vertex" "Block" $ X~hair : chr [1:2] "Block" "Vertex" $ X~A : chr [1:2] "Block" "Block" $ X~eye : chr [1:2] "Block" "Vertex" $ sex~C : chr [1:2] "Vertex" "Block" $ sex~B : chr [1:2] "Vertex" "Block" $ X~education: chr [1:2] "Block" "Vertex" $ X~C : chr [1:2] "Block" "Block" $ X~age : chr [1:2] "Block" "Vertex" $ X~B : chr [1:2] "Block" "Block" > str(NodeIndices(blockedges)) List of 14 $ country~X : num [1:2] 1 -2 $ W~sex : num [1:2] -1 2 $ W~X : num [1:2] -1 -2 $ W~race : num [1:2] -1 3 $ race~A : num [1:2] 3 -3 $ X~hair : num [1:2] -2 4 $ X~A : num [1:2] -2 -3 $ X~eye : num [1:2] -2 5 $ sex~C : num [1:2] 2 -5 $ sex~B : num [1:2] 2 -4 $ X~education: num [1:2] -2 7 $ X~C : num [1:2] -2 -5 $ X~age : num [1:2] -2 6 $ X~B : num [1:2] -2 -4 > Widths(blockedges) country~X W~sex W~X W~race race~A X~hair 2 2 2 2 2 2 X~A X~eye sex~C sex~B X~education X~C 2 2 2 2 2 2 X~age X~B 2 2 > Oriented(blockedges) country~X W~sex W~X W~race race~A X~hair TRUE TRUE TRUE TRUE TRUE TRUE X~A X~eye sex~C sex~B X~education X~C TRUE TRUE TRUE TRUE TRUE TRUE X~age X~B TRUE TRUE > Widths(blockedges) <- rep(1, 7) Warning in "Widths<-"(`*tmp*`, value = c(1, 1, 1, 1, 1, 1, 1)) : Invalid list of values for widths > Widths(blockedges) <- rep(1, 14) > Widths(blockedges) country~X W~sex W~X W~race race~A X~hair 1 1 1 1 1 1 X~A X~eye sex~C sex~B X~education X~C 1 1 1 1 1 1 X~age X~B 1 1 > asDataFrame(blockedges) oriented dash v..i..1 v..i..2 width color label l..pos..1 l..pos..2 1 TRUE 1 -2 1 red country~X 0 0 2 TRUE -1 2 1 red W~sex 0 0 3 TRUE -1 -2 1 red W~X 0 0 4 TRUE -1 3 1 red W~race 0 0 5 TRUE 3 -3 1 red race~A 0 0 6 TRUE -2 4 1 red X~hair 0 0 7 TRUE -2 -3 1 red X~A 0 0 8 TRUE -2 5 1 red X~eye 0 0 9 TRUE 2 -5 1 red sex~C 0 0 10 TRUE 2 -4 1 red sex~B 0 0 11 TRUE -2 7 1 red X~education 0 0 12 TRUE -2 -5 1 red X~C 0 0 13 TRUE -2 6 1 red X~age 0 0 14 TRUE -2 -4 1 red X~B 0 0 l..pos..3 class 1 0 dg.BlockEdge 2 0 dg.BlockEdge 3 0 dg.BlockEdge 4 0 dg.BlockEdge 5 0 dg.BlockEdge 6 0 dg.BlockEdge 7 0 dg.BlockEdge 8 0 dg.BlockEdge 9 0 dg.BlockEdge 10 0 dg.BlockEdge 11 0 dg.BlockEdge 12 0 dg.BlockEdge 13 0 dg.BlockEdge 14 0 dg.BlockEdge > > > > cleanEx(); ..nameEx <- "returnEdgeList" > > ### * returnEdgeList > > flush(stderr()); flush(stdout()) > > ### Name: returnEdgeList > ### Title: Class "dg.VertexEdgeList": The edge list > ### Aliases: vertexEdgeList returnEdgeList dg.VertexEdgeList-class > ### Keywords: methods dynamic graphs > > ### ** Examples > > from <- c("contry", "contry", "race", "race", "sex", "sex") > to <- c( "sex", "race", "hair", "eye", "education", "age") > vertexnames <- unique(sort(c(from, to))) > vertices <- returnVertexList(vertexnames) > # from <- match(from, vertexnames) > # to <- match(to, vertexnames) > edge.list <- vector("list", length(to)) > for (j in seq(along = to)) edge.list[[j]] <- c(from[j], to[j]) > edges <- returnEdgeList(edge.list, vertices, color = "red", oriented = TRUE) > > Names(edges) [1] "contry~sex" "contry~race" "race~hair" "race~eye" [5] "sex~education" "sex~age" > Colors(edges) contry~sex contry~race race~hair race~eye sex~education "red" "red" "red" "red" "red" sex~age "red" > Labels(edges) contry~sex contry~race race~hair race~eye sex~education "contry~sex" "contry~race" "race~hair" "race~eye" "sex~education" sex~age "sex~age" > LabelPositions(edges) X Y Z-3 contry~sex 0 0 0 contry~race 0 0 0 race~hair 0 0 0 race~eye 0 0 0 sex~education 0 0 0 sex~age 0 0 0 > # Positions(edges) > # Strata(edges) > # Indices(edges) > str(NodeTypes(edges)) List of 6 $ contry~sex : chr [1:2] "Vertex" "Vertex" $ contry~race : chr [1:2] "Vertex" "Vertex" $ race~hair : chr [1:2] "Vertex" "Vertex" $ race~eye : chr [1:2] "Vertex" "Vertex" $ sex~education: chr [1:2] "Vertex" "Vertex" $ sex~age : chr [1:2] "Vertex" "Vertex" > str(NodeIndices(edges)) List of 6 $ contry~sex : int [1:2] 2 7 $ contry~race : int [1:2] 2 6 $ race~hair : int [1:2] 6 5 $ race~eye : int [1:2] 6 4 $ sex~education: int [1:2] 7 3 $ sex~age : int [1:2] 7 1 > Dashes(edges) contry~sex contry~race race~hair race~eye sex~education "" "" "" "" "" sex~age "" > Widths(edges) contry~sex contry~race race~hair race~eye sex~education 2 2 2 2 2 sex~age 2 > Oriented(edges) contry~sex contry~race race~hair race~eye sex~education TRUE TRUE TRUE TRUE TRUE sex~age TRUE > Widths(edges) <- rep(1, 7) Warning in "Widths<-"(`*tmp*`, value = c(1, 1, 1, 1, 1, 1, 1)) : Invalid list of values for widths > Widths(edges) <- rep(1, 6) > Widths(edges) contry~sex contry~race race~hair race~eye sex~education 1 1 1 1 1 sex~age 1 > asDataFrame(edges) oriented dash v..i..1 v..i..2 width color label l..pos..1 l..pos..2 1 TRUE 2 7 1 red contry~sex 0 0 2 TRUE 2 6 1 red contry~race 0 0 3 TRUE 6 5 1 red race~hair 0 0 4 TRUE 6 4 1 red race~eye 0 0 5 TRUE 7 3 1 red sex~education 0 0 6 TRUE 7 1 1 red sex~age 0 0 l..pos..3 class 1 0 dg.VertexEdge 2 0 dg.VertexEdge 3 0 dg.VertexEdge 4 0 dg.VertexEdge 5 0 dg.VertexEdge 6 0 dg.VertexEdge > > > > cleanEx(); ..nameEx <- "returnVertexList" > > ### * returnVertexList > > flush(stderr()); flush(stdout()) > > ### Name: returnVertexList > ### Title: Class "dg.VertexList": The vertex list > ### Aliases: vertexList returnVertexList dg.VertexList-class > ### Keywords: methods dynamic graphs > > ### ** Examples > > vertices <- returnVertexList(c("A", "B", "C", "D"), + labels = c("OrdinalVertex", "TextVertex", + "ContinuousVertex", "DiscreteVertex"), + types = c("Ordinal", "TextVertex", + "Continuous", "Discrete"), N = 2) > Names(vertices) [1] "A" "B" "C" "D" > Colors(vertices) A B C D "DarkRed" "FloralWhite" "DarkRed" "DarkRed" > Labels(vertices) A B C D "OrdinalVertex" "TextVertex" "ContinuousVertex" "DiscreteVertex" > LabelPositions(vertices) X Y A 0 0 B 0 0 C 0 0 D 0 0 > Positions(vertices) X Y A 2.449294e-15 4.000000e+01 B -4.000000e+01 4.898587e-15 C -7.347881e-15 -4.000000e+01 D 4.000000e+01 -9.797174e-15 > Strata(vertices) A B C D 0 0 0 0 > Indices(vertices) A B C D 1 -2 3 4 > Names(vertices) <- c("a", "b", "c", "d") > Colors(vertices) <- rep("Blue", 4) > Labels(vertices) <- c("A", "B", "C", "D") > LabelPositions(vertices) <- matrix(rep(0, 12), ncol = 3) > Positions(vertices) <- matrix(rep(0, 12), ncol = 3) > Strata(vertices) <- rep(1, 4) > Names(vertices) [1] "a" "b" "c" "d" > Colors(vertices) a b c d "Blue" "Blue" "Blue" "Blue" > Labels(vertices) a b c d "A" "B" "C" "D" > LabelPositions(vertices) X Y Z-3 a 0 0 0 b 0 0 0 c 0 0 0 d 0 0 0 > Positions(vertices) X Y Z-3 a 0 0 0 b 0 0 0 c 0 0 0 d 0 0 0 > Strata(vertices) a b c d 1 1 1 1 > Indices(vertices) a b c d 1 -2 3 4 > asDataFrame(vertices) name index p..1 p..2 p..3 blockindex stratum color label l..pos..1 l..pos..2 1 a 1 0 0 0 0 1 Blue A 0 0 2 b -2 0 0 0 0 1 Blue B 0 0 3 c 3 0 0 0 0 1 Blue C 0 0 4 d 4 0 0 0 0 1 Blue D 0 0 l..pos..3 class 1 0 dg.OrdinalVertex 2 0 dg.TextVertex 3 0 dg.ContinuousVertex 4 0 dg.DiscreteVertex > > > > cleanEx(); ..nameEx <- "setBlocks" > > ### * setBlocks > > flush(stderr()); flush(stdout()) > > ### Name: setBlocks > ### Title: Class "dg.BlockList": The block list > ### Aliases: setBlocks blockList dg.BlockList-class > ### Keywords: methods dynamic graphs > > ### ** Examples > > require(tcltk) [1] TRUE > > require(dynamicGraph) [1] TRUE > > V.Types <- c("Discrete", "Ordinal", "Discrete", + "Continuous", "Discrete", "Continuous") > > V.Names <- c("Sex", "Age", "Eye", "FEV", "Hair", "Shosize") > V.Names <- paste(V.Names, 1:6, sep ="/") > > From <- c(1, 2, 3, 4, 5, 6) > To <- c(2, 3, 4, 5, 6, 1) > > # A block recursive model: > > Blocks <- list(Basic = c(2, 1), Intermediate = c(5, 4, 3), Now = c(6)) > > V.Names <- paste(V.Names, c(1, 1, 2, 2, 2, 3), sep =":") > > Z <- DynamicGraph(V.Names, V.Types, From, To, blocks = Blocks, + width = 600, height = 600, drawblocks = TRUE, + drawBlockBackground = FALSE, title = "DrawBlocks") (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > # A block recursiv model, without drawing blocks: > > Z <- DynamicGraph(V.Names, V.Types, From, To, blocks = Blocks, + width = 600, height = 600, + drawblocks = FALSE, title = "No blocks drawn") (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > # A block recursive model with nested blocks: > > Z <- DynamicGraph(V.Names, V.Types, From, To, blocks = Blocks, + width = 600, height = 600, drawblocks = TRUE, + nested.blocks = TRUE, title = "Nested blocks", + blockColors = paste("Grey", 100 - 2 * (1:10), sep = "")) (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > # The block list of the last example: > > vertices <- returnVertexList(V.Names, types = V.Types) > blockList <- setBlocks(Blocks, vertices = vertices, nested.blocks = TRUE, + blockColors = paste("Grey", 100 - 2 * (1:10), sep = "")) > > names(blockList) [1] "Blocks" "Vertices" > str(blockList$Blocks[[1]]) Formal class 'dg.Block' [package "dynamicGraph"] with 10 slots ..@ stratum : int 1 ..@ index : int -1 ..@ ancestors : num 0 ..@ descendants : num 0 ..@ position : num [1:2, 1:3] -47.5 47.5 -47.5 47.5 -47.5 47.5 ..@ closed : logi FALSE ..@ visible : logi TRUE ..@ color : chr "Grey98" ..@ label : chr "Basic" ..@ label.position: num [1:3] 0 0 0 > > names(blockList$Blocks) [1] "Basic" "Intermediate" "Now" > Names(blockList$Blocks) [1] "Basic" "Intermediate" "Now" > Labels(blockList$Blocks) Basic Intermediate Now "Basic" "Intermediate" "Now" > LabelPositions(blockList$Blocks) X Y Z-3 Basic 0 0 0 Intermediate 0 0 0 Now 0 0 0 > Positions(blockList$Blocks) X Y Z-3 x y z-3 Basic -47.500000 -47.50 -47.50000 47.50000 47.50000 47.50000 Intermediate -26.388889 -23.75 -31.66667 36.94444 39.58333 31.66667 Now -5.277778 0.00 -15.83333 26.38889 31.66667 15.83333 > Strata(blockList$Blocks) Basic Intermediate Now 1 2 3 > Colors(blockList$Blocks) Basic Intermediate Now "Grey98" "Grey96" "Grey94" > NodeAncestors(blockList$Blocks) $Basic [1] 0 $Intermediate [1] 0 $Now [1] 0 > NodeDescendants(blockList$Blocks) $Basic [1] 0 $Intermediate [1] 0 $Now [1] 0 > Visible(blockList$Blocks) Basic Intermediate Now TRUE TRUE TRUE > Indices(blockList$Blocks) Basic Intermediate Now 1 2 3 > > names(blockList$Vertices) [1] "Sex/1:1" "Age/2:1" "Eye/3:2" "FEV/4:2" "Hair/5:2" [6] "Shosize/6:3" > Names(blockList$Vertices) [1] "Sex/1:1" "Age/2:1" "Eye/3:2" "FEV/4:2" "Hair/5:2" [6] "Shosize/6:3" > Labels(blockList$Vertices) Sex/1:1 Age/2:1 Eye/3:2 FEV/4:2 Hair/5:2 "Sex/1:1" "Age/2:1" "Eye/3:2" "FEV/4:2" "Hair/5:2" Shosize/6:3 "Shosize/6:3" > LabelPositions(blockList$Vertices) X Y Z-3 Sex/1:1 0 0 0 Age/2:1 0 0 0 Eye/3:2 0 0 0 FEV/4:2 0 0 0 Hair/5:2 0 0 0 Shosize/6:3 0 0 0 > Positions(blockList$Vertices) X Y Z-3 Sex/1:1 -36.944444 43.54167 0 Age/2:1 -36.944444 -35.62500 0 Eye/3:2 -15.833333 35.62500 0 FEV/4:2 -15.833333 11.87500 0 Hair/5:2 -15.833333 -11.87500 0 Shosize/6:3 5.277778 11.87500 0 > Strata(blockList$Vertices) Sex/1:1 Age/2:1 Eye/3:2 FEV/4:2 Hair/5:2 Shosize/6:3 1 1 2 2 2 3 > Colors(blockList$Vertices) Sex/1:1 Age/2:1 Eye/3:2 FEV/4:2 Hair/5:2 Shosize/6:3 "DarkRed" "DarkRed" "DarkRed" "DarkRed" "DarkRed" "DarkRed" > Indices(blockList$Vertices) Sex/1:1 Age/2:1 Eye/3:2 FEV/4:2 Hair/5:2 Shosize/6:3 1 2 3 4 5 6 > > asDataFrame(blockList$Vertices) name index p..1 p..2 p..3 blockindex stratum color 1 Sex/1:1 1 -36.944444 43.54167 0 1 1 DarkRed 2 Age/2:1 2 -36.944444 -35.62500 0 1 1 DarkRed 3 Eye/3:2 3 -15.833333 35.62500 0 2 2 DarkRed 4 FEV/4:2 4 -15.833333 11.87500 0 2 2 DarkRed 5 Hair/5:2 5 -15.833333 -11.87500 0 2 2 DarkRed 6 Shosize/6:3 6 5.277778 11.87500 0 3 3 DarkRed label l..pos..1 l..pos..2 l..pos..3 class 1 Sex/1:1 0 0 0 dg.DiscreteVertex 2 Age/2:1 0 0 0 dg.OrdinalVertex 3 Eye/3:2 0 0 0 dg.DiscreteVertex 4 FEV/4:2 0 0 0 dg.ContinuousVertex 5 Hair/5:2 0 0 0 dg.DiscreteVertex 6 Shosize/6:3 0 0 0 dg.ContinuousVertex > asDataFrame(blockList$Blocks) stratum index ancestors descendants p..1 p..2 p..3 p..4 1 1 -1 0 0 -47.500000 47.50000 -47.50 47.50000 2 2 -2 0 0 -26.388889 36.94444 -23.75 39.58333 3 3 -3 0 0 -5.277778 26.38889 0.00 31.66667 p..5 p..6 closed visible color label l..pos..1 l..pos..2 1 -47.50000 47.50000 FALSE TRUE Grey98 Basic 0 0 2 -31.66667 31.66667 FALSE TRUE Grey96 Intermediate 0 0 3 -15.83333 15.83333 FALSE TRUE Grey94 Now 0 0 l..pos..3 class 1 0 dg.Block 2 0 dg.Block 3 0 dg.Block > > > > > cleanEx(); ..nameEx <- "setTreeBlocks" > > ### * setTreeBlocks > > flush(stderr()); flush(stdout()) > > ### Name: setTreeBlocks > ### Title: The block tree > ### Aliases: setTreeBlocks Closed Closed<- NodeAncestors NodeAncestors<- > ### NodeDescendants NodeDescendants<- > ### Keywords: methods dynamic graphs > > ### ** Examples > > # Example 1: > > Block.tree <- list(label = "W", Vertices = c("country"), + X = list(Vertices = c("race", "sex"), + A = list(Vertices = c("hair", "eye"), + horizontal = FALSE), + B = list(Vertices = c("education"), + C = list(Vertices = c("age"))))) > V.Names <- unlist(Block.tree) > vertices <- returnVertexList(V.Names[grep("Vertices", names(V.Names))]) > blocktree <- setTreeBlocks(Block.tree, vertices) > > Positions(blockTreeToList(blocktree$BlockTree)) X Y Z-3 x y z-3 W -48 -48.000 -48 48.0 -19.500 48 X -48 -18.000 -48 48.0 3.000 48 A -48 4.500 -48 -1.5 48.000 48 B 0 4.500 -48 48.0 19.875 48 C 0 21.375 -48 48.0 48.000 48 > Positions(blocktree$Vertices) X Y Z-3 country 0.00 -29.7500 0 race -24.00 -3.5000 0 sex 24.00 -3.5000 0 hair -24.75 21.3750 0 eye -24.75 39.1250 0 education 24.00 16.1875 0 age 24.00 38.6875 0 > NodeAncestors(blockTreeToList(blocktree$BlockTree)) $W [1] 0 $X [1] 1 $A [1] 1 2 $B [1] 1 2 $C [1] 1 2 4 > NodeDescendants(blockTreeToList(blocktree$BlockTree)) $W [1] 2 3 4 5 $X [1] 3 4 5 $A [1] 0 $B [1] 5 $C [1] 0 > > vertexStrata <- Strata(blocktree$Vertices) > vertexStrata country race sex hair eye education age 1 2 2 3 3 4 5 > vertexNames <- Names(blocktree$Vertices) > names(vertexNames) <- NULL > vertexNames [1] "country" "race" "sex" "hair" "eye" "education" [7] "age" > > # Indices of the vertices in blocks: > > indicesInBlock <- vector("list", max(vertexStrata)) > for (i in seq(along = vertexStrata)) + indicesInBlock[[vertexStrata[i]]] <- + append(indicesInBlock[[vertexStrata[i]]], i) > str(indicesInBlock) List of 5 $ : int 1 $ : int [1:2] 2 3 $ : int [1:2] 4 5 $ : int 6 $ : int 7 > > # Names of the vertices in blocks: > > vertexNamesInblock <- vector("list", max(vertexStrata)) > for (i in seq(along = vertexStrata)) + vertexNamesInblock[[vertexStrata[i]]] <- + append(vertexNamesInblock[[vertexStrata[i]]], vertexNames[i]) > str(vertexNamesInblock) List of 5 $ : chr "country" $ : chr [1:2] "race" "sex" $ : chr [1:2] "hair" "eye" $ : chr "education" $ : chr "age" > > # A useful function, replace "k" (block index k) > # in block "i" by "x[k]", the content "x[k]" of block "k": > > f <- function(A, x) { + result <- vector("list", length(A)) + names(result) <- names(A) + for (i in seq(along = A)) + if ((length(A[[i]]) > 0) && (A[[i]] != 0)) + for (k in A[[i]]) + result[[i]] <- append(result[[i]], x[k]) + return(result) + } > > # For each block, names of vertices in ancestor blocks: > > vertexAncOfBlock <- f(NodeAncestors(blockTreeToList(blocktree$BlockTree)), + vertexNamesInblock) > str(vertexAncOfBlock) List of 5 $ W: NULL $ X:List of 1 ..$ : chr "country" $ A:List of 2 ..$ : chr "country" ..$ : chr [1:2] "race" "sex" $ B:List of 2 ..$ : chr "country" ..$ : chr [1:2] "race" "sex" $ C:List of 3 ..$ : chr "country" ..$ : chr [1:2] "race" "sex" ..$ : chr "education" > > for (i in seq(along = vertexAncOfBlock)) + if (length(vertexAncOfBlock[[i]]) > 0) + vertexAncOfBlock[[i]] <- unlist(vertexAncOfBlock[[i]]) > str(vertexAncOfBlock) List of 5 $ W: NULL $ X: chr "country" $ A: chr [1:3] "country" "race" "sex" $ B: chr [1:3] "country" "race" "sex" $ C: chr [1:4] "country" "race" "sex" "education" > > # For each block, names of vertices in descendant blocks: > > vertexDesOfBlock <- f(NodeDescendants(blockTreeToList(blocktree$BlockTree)), + vertexNamesInblock) > str(vertexDesOfBlock) List of 5 $ W:List of 4 ..$ : chr [1:2] "race" "sex" ..$ : chr [1:2] "hair" "eye" ..$ : chr "education" ..$ : chr "age" $ X:List of 3 ..$ : chr [1:2] "hair" "eye" ..$ : chr "education" ..$ : chr "age" $ A: NULL $ B:List of 1 ..$ : chr "age" $ C: NULL > > for (i in seq(along = vertexDesOfBlock)) + if (length(vertexDesOfBlock[[i]]) > 0) + vertexDesOfBlock[[i]] <- unlist(vertexDesOfBlock[[i]]) > str(vertexDesOfBlock) List of 5 $ W: chr [1:6] "race" "sex" "hair" "eye" ... $ X: chr [1:4] "hair" "eye" "education" "age" $ A: NULL $ B: chr "age" $ C: NULL > > # Example 2: > > Block.tree <- + list(g = 0, G = 54, label = "Pedegree.G", + Male.Side = + list(g = 0, G = 33, + Father = + list(g = 0, G = 12, + P.G.Father = list(Vertices = c("P.G.Father.1")), + P.G.Mother = list(Vertices = c("P.G.Mother.1")), + common.children = list(g = 0, label = "Father.1", + Vertices = c("Father.1"))), + Mother = + list(g = 0, G = 12, + M.G.Father = list(Vertices = c("M.G.Father.1")), + M.G.Mother = list(Vertices = c("M.G.Mother.1")), + common.children = list(g = 0, label = "Mother.1", + Vertices = c("Mother.1"))), + common.children = list(g = 2, Vertices = c("Male"))), + Female.Side = list(g = 0, G = 12, + P.G.Father = list(Vertices = c("P.G.Father.2")), + P.G.Mother = list(Vertices = c("P.G.Mother.2")), + M.G.Father = list(Vertices = c("M.G.Father.2")), + M.G.Mother = list(Vertices = c("M.G.Mother.2")), + common.children = list(g = 0, G = 12, label = "Female", + Father = list(Vertices = c("Father.2")), + Mother = list(Vertices = c("Mother.2")), + common.children = list(g = 2, Vertices = c("Female")))), + common.children = list(Vertices = c("Marriage"), g = 3, label = "Children", + Son = list(Vertices = c("Son"), g = 3, + P.G.Son = list(Vertices = c("P.G.Son"), g = 2), + P.G.Dat = list(Vertices = c("P.G.Dat"), g = 1)), + Dat = list(Vertices = c("Dat"), g = 2, + M.G.Son = list(Vertices = c("M.G.Son")), + M.G.Dat = list(Vertices = c("M.G.Dat"))) + ) + ) > > v <- unlist(Block.tree) > V.Names <- v[grep("Vertices", names(v))] > rm(v) > > FromTo <- matrix(c("P.G.Father.1", "Father.1", "P.G.Father.2", "Father.2", + "P.G.Mother.1", "Father.1", "P.G.Mother.2", "Father.2", + "M.G.Father.1", "Mother.1", "M.G.Father.2", "Mother.2", + "M.G.Mother.1", "Mother.1", "M.G.Mother.2", "Mother.2", + "Father.1", "Male", "Father.2", "Female", + "Mother.1", "Male", "Mother.2", "Female", + "Male", "Marriage", "Female", "Marriage", + "Marriage", "Son", "Marriage", "Dat", + "Son", "P.G.Son", "Dat", "M.G.Son", + "Son", "P.G.Dat", "Dat", "M.G.Dat"), + byrow = TRUE, ncol = 2) > > From <- match(FromTo[,1], V.Names) > To <- match(FromTo[,2], V.Names) > > V.Types <- rep("Discrete", length(V.Names)) > > Object <- NULL > Z <- DynamicGraph(V.Names, V.Types, From, To, block.tree = Block.tree, + object = Object, width = 600, height = 600, + drawblocks = TRUE, drawBlockFrame = TRUE, + overlaying = TRUE, title = "Pedegree.G") (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > > > cleanEx(); ..nameEx <- "validEdgeClasses" > > ### * validEdgeClasses > > flush(stderr()); flush(stdout()) > > ### Name: validEdgeClasses > ### Title: Valid edge classes > ### Aliases: edgeClasses validEdgeClasses > ### Keywords: methods dynamic graphs > > ### ** Examples > > require(tcltk) [1] TRUE > > # Test with new edge class (demo(Circle.newEdge)): > > setClass("NewEdge", contains = "dg.VertexEdge") [1] "NewEdge" > > myEdgeClasses <- rbind(validEdgeClasses(), + NewEdge = c("NewEdge", "NewEdge")) > > setMethod("draw", "NewEdge", + function(object, canvas, position, + x = lapply(position, function(e) e[1]), + y = lapply(position, function(e) e[2]), + stratum = as.vector(rep(0, length(position)), + mode = "list"), + w = 2, color = "green", background = "white") + { + f <- function(i, j) { + dash <- "." + arrowhead <- "both" + l <- function(xi, yi, xj, yj) + tkcreate(canvas, "line", xi, yi, xj, yj, width = w, + arrow = arrowhead, dash = dash, + # arrowshape = as.list(c(2, 5, 3) * w), + fill = color(object), activefill = "DarkSlateGray") + lines <- list(l(x[[i]], y[[i]], x[[j]], y[[j]])) + label.position <- (position[[i]] + position[[j]]) / 2 + pos <- label.position + rep(0, length(label.position)) + label <- tkcreate(canvas, "text", pos[1], pos[2], + text = object@label, anchor = "nw", + font = "8x16", activefill = "DarkSlateGray") + tags <- NULL + x. <- mean(unlist(x)) + y. <- mean(unlist(y)) + s <- 4 * w * sqrt(4 / pi) + p <- tkcreate(canvas, "rectangle", + x. - s, y. - s, x. + s, y. + s, + fill = color(object), activefill = "SeaGreen") + tags <- list(p) + return(list(lines = lines, tags = tags, + from = object@vertex.indices[i], + to = object@vertex.indices[j], + label = label, label.position = label.position)) + } + result <- NULL + edge <- object@vertex.indices + m <- length(edge) + for (j in seq(along = edge)) + if (j < length(edge)) + for (k in (j+1):length(edge)) + result <- append(result, list(f(j, k))) + return(result) + }) [1] "draw" > > setMethod("addToPopups", "NewEdge", + function(object, type, nodePopupMenu, i, + updateArguments, Args, ...) + { + tkadd(nodePopupMenu, "command", + label = paste(" --- This is a my new vertex!"), + command = function() { print(name(object))}) + }) [1] "addToPopups" > > # Why are these 2 * 7 methods not avaliable from "dg.VertexEdge" ? > > setMethod("color", "NewEdge", function(object) object@color) [1] "color" > setReplaceMethod("color", "NewEdge", + function(x, value) {x@color <- value; x} ) [1] "color<-" > > setMethod("label", "NewEdge", function(object) object@label) [1] "label" > setReplaceMethod("label", "NewEdge", + function(x, value) {x@label <- value; x} ) [1] "label<-" > > setMethod("name", "NewEdge", function(object) object@label) [1] "name" > setReplaceMethod("name", "NewEdge", + function(x, value) {x@label <- value; x} ) [1] "name<-" > > setMethod("labelPosition", "NewEdge", + function(object) object@label.position) [1] "labelPosition" > setReplaceMethod("labelPosition", "NewEdge", + function(x, value) {x@label.position <- value; x} ) [1] "labelPosition<-" > > setMethod("nodeIndices", "NewEdge", function(object) object@vextex.indices) [1] "nodeIndices" > setReplaceMethod("nodeIndices", "NewEdge", + function(x, value) {x@vextex.indices <- value; x} ) [1] "nodeIndices<-" > > setMethod("width", "NewEdge", function(object) object@width) [1] "width" > setReplaceMethod("width", "NewEdge", + function(x, value) {x@width <- value; x} ) [1] "width<-" > > setMethod("dash", "NewEdge", function(object) object@dash) [1] "dash" > setReplaceMethod("dash", "NewEdge", + function(x, value) {x@dash <- value; x} ) [1] "dash<-" > > setMethod("propertyDialog", "NewEdge", + function(object, classes = NULL, title = class(object), + sub.title = label(object), name.object = name(object), + okReturn = TRUE, + fixedSlots = NULL, difficultSlots = NULL, + top = NULL, entryWidth = 20, do.grab = FALSE) { + .propertyDialog(object, classes = classes, title = title, + sub.title = sub.title, name.object = name.object, + okReturn = okReturn, + fixedSlots = fixedSlots, difficultSlots = difficultSlots, + top = top, entryWidth = entryWidth, do.grab = do.grab) + }) [1] "propertyDialog" > > V.Types <- c("Discrete", "Ordinal", "Discrete", + "Continuous", "Discrete", "Continuous") > > V.Names <- c("Sex", "Age", "Eye", "FEV", "Hair", "Shosize") > V.Labels <- paste(V.Names, 1:6, sep ="/") > > From <- c(1, 2, 3, 4, 5, 6, 3) > To <- c(2, 3, 4, 5, 6, 1, 6) > > Z <- DynamicGraph(V.Names, V.Types, From, To, texts = c("Gryf", "gaf"), + edge.types = c("NewEdge", + "VertexEdge", + "Dashed", + "Dotted", + "DoubleArrow", + "DoubleConnected", + "TripleConnected"), + labels = V.Labels, + updateEdgeLabels = FALSE, edgeColor = "green", + vertexColor = "blue", edgeClasses = myEdgeClasses) (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > > > > cleanEx(); ..nameEx <- "validFactorClasses" > > ### * validFactorClasses > > flush(stderr()); flush(stdout()) > > ### Name: validFactorClasses > ### Title: Valid factor vertex classes > ### Aliases: factorClasses validFactorClasses > ### Keywords: methods dynamic graphs > > ### ** Examples > validFactorClasses() Label Class Generator "Generator" "dg.Generator" Discrete generator "Discrete generator" "dg.DiscreteGenerator" Linear generator "Linear generator" "dg.LinearGenerator" Quadratic generator "Quadratic generator" "dg.QuadraticGenerator" > > > cleanEx(); ..nameEx <- "validVertexClasses" > > ### * validVertexClasses > > flush(stderr()); flush(stdout()) > > ### Name: validVertexClasses > ### Title: Valid vertex classes > ### Aliases: vertexClasses validVertexClasses > ### Keywords: methods dynamic graphs > > ### ** Examples > > require(tcltk) [1] TRUE > > # Test with new vertex class (demo(Circle.newVertex)): > > setClass("NewVertex", contains = "dg.Vertex", + representation(my.text = "character", + my.number = "numeric"), + prototype(my.text = "", + my.number = 2)) [1] "NewVertex" > > myVertexClasses <- rbind(validVertexClasses(), + NewVertex = c("NewVertex", "NewVertex")) > > setMethod("draw", "NewVertex", + function(object, canvas, position, + x = position[1], y = position[2], stratum = 0, + w = 2, color = "green", background = "white") + { + s <- w * sqrt(4 / pi) / 2 + p1 <- tkcreate(canvas, "oval", + x - s - s, y - s, x + s - s, y + s, + fill = color(object), activefill = "IndianRed") + p2 <- tkcreate(canvas, "oval", + x - s + s, y - s, x + s + s, y + s, + fill = color(object), activefill = "IndianRed") + p3 <- tkcreate(canvas, "oval", + x - s, y - s - s, x + s, y + s - s, + fill = color(object), activefill = "IndianRed") + p4 <- tkcreate(canvas, "poly", x - 1.5 * s, y + 3 * s, + x + 1.5 * s, y + 3 * s, x, y, + fill = color(object), activefill = "SteelBlue") + return(list(dynamic = list(p1, p2, p3, p4), fixed = NULL)) }) [1] "draw" > > setMethod("addToPopups", "NewVertex", + function(object, type, nodePopupMenu, i, + updateArguments, Args, ...) + { + tkadd(nodePopupMenu, "command", + label = paste(" --- This is a my new vertex!"), + command = function() { print(name(object))}) + }) [1] "addToPopups" > > if (!isGeneric("my.text")) { + if (is.function("my.text")) + fun <- my.text + else + fun <- function(object) standardGeneric("my.text") + setGeneric("my.text", fun) + } [1] "my.text" > setGeneric("my.text<-", + function(x, value) standardGeneric("my.text<-")) [1] "my.text<-" > > setMethod("my.text", "NewVertex", + function(object) object@my.text) [1] "my.text" > setReplaceMethod("my.text", "NewVertex", + function(x, value) {x@my.text <- value; x} ) [1] "my.text<-" > > if (!isGeneric("my.number")) { + if (is.function("my.number")) + fun <- my.number + else + fun <- function(object) standardGeneric("my.number") + setGeneric("my.number", fun) + } [1] "my.number" > setGeneric("my.number<-", + function(x, value) standardGeneric("my.number<-")) [1] "my.number<-" > > setMethod("my.number", "NewVertex", + function(object) object@my.number) [1] "my.number" > setReplaceMethod("my.number", "NewVertex", + function(x, value) {x@my.number <- value; x} ) [1] "my.number<-" > > # Why are these 2 * 7 methods not avaliable from "dg.Vertex" ? > > setMethod("color", "NewVertex", + function(object) object@color) [1] "color" > setReplaceMethod("color", "NewVertex", + function(x, value) {x@color <- value; x} ) [1] "color<-" > > setMethod("label", "NewVertex", + function(object) object@label) [1] "label" > setReplaceMethod("label", "NewVertex", + function(x, value) {x@label <- value; x} ) [1] "label<-" > > setMethod("labelPosition", "NewVertex", + function(object) object@label.position) [1] "labelPosition" > setReplaceMethod("labelPosition", "NewVertex", + function(x, value) {x@label.position <- value; x} ) [1] "labelPosition<-" > > setMethod("name", "NewVertex", + function(object) object@name) [1] "name" > setReplaceMethod("name", "NewVertex", + function(x, value) {x@name <- value; x} ) [1] "name<-" > > setMethod("index", "NewVertex", + function(object) object@index) [1] "index" > setReplaceMethod("index", "NewVertex", + function(x, value) {x@index <- value; x} ) [1] "index<-" > > setMethod("position", "NewVertex", + function(object) object@position) [1] "position" > setReplaceMethod("position", "NewVertex", + function(x, value) {x@position <- value; x} ) [1] "position<-" > > setMethod("stratum", "NewVertex", + function(object) object@stratum) [1] "stratum" > setReplaceMethod("stratum", "NewVertex", + function(x, value) {x@stratum <- value; x} ) [1] "stratum<-" > > setMethod("propertyDialog", "NewVertex", + function(object, classes = NULL, title = class(object), + sub.title = label(object), name.object = name(object), + okReturn = TRUE, + fixedSlots = NULL, difficultSlots = NULL, + top = NULL, entryWidth = 20, do.grab = FALSE) { + .propertyDialog(object, classes = classes, title = title, + sub.title = sub.title, name.object = name.object, + okReturn = okReturn, + fixedSlots = fixedSlots, difficultSlots = difficultSlots, + top = top, entryWidth = entryWidth, do.grab = do.grab) + }) [1] "propertyDialog" > > V.Types <- rep("NewVertex", 6) > > V.Names <- c("Sex", "Age", "Eye", "FEV", "Hair", "Shosize") > V.Labels <- paste(V.Names, 1:6, sep ="/") > > From <- c(1, 2, 3, 4, 5, 6) > To <- c(2, 3, 4, 5, 6, 1) > > Z <- DynamicGraph(V.Names, V.Types, From, To, texts = c("Gryf", "gaf"), + labels = V.Labels, + updateEdgeLabels = FALSE, edgeColor = "green", + vertexColor = "blue", vertexClasses = myVertexClasses) (( No 'update' and 'overwrite' since 'returnLink = FALSE')) > > > > cleanEx(); ..nameEx <- "validViewClasses" > > ### * validViewClasses > > flush(stderr()); flush(stdout()) > > ### Name: validViewClasses > ### Title: Valid view classes > ### Aliases: viewClasses validViewClasses > ### Keywords: methods dynamic graphs > > ### ** Examples > validViewClasses() Label Class Simple "Simple" "SimpleDynamicGraphView" Factor "Factor" "FactorDynamicGraphView" Moral "Moral" "MoralDynamicGraphView" Essential "Essential" "EssentialDynamicGraphView" > > > ### *