我在并行使用R包( bnlearn和sna )方面有问题。下面的示例很简单:
library(bnlearn)
data("asia")
# build network
a <- hc(asia)
# output
a产出与预期相符:
Bayesian network learned via Score-based methods
model:
[A][S][T][L|S][B|S][E|T:L][X|E][D|B:E]
nodes: 8
arcs: 7
undirected arcs: 0
directed arcs: 7
average markov blanket size: 2.25
average neighbourhood size: 1.75
average branching factor: 0.88
learning algorithm: Hill-Climbing
score: BIC (disc.)
penalization coefficient: 4.258597
tests used in the learning procedure: 77
optimized: TRUE 一旦加载了sna包,就会收到完全不同的信息:
library(sna)
#output
a我得到:
Biased Net Model
Parameters:
Error in matrix(c(x$d, x$pi, x$sigma, x$rho), ncol = 1) :
'data' must be of a vector type, was 'NULL'由于我并不真正调用任何函数(只想获得a的输出),所以我认为使用::运算符是没有帮助的。
我想知道问题是否掩盖了我无法真正影响的内部功能。任何帮助都会很好!
发布于 2018-05-16 15:37:54
这有点类似于其他q & a's,只是在本例中有一个对print的隐式调用,而不是一个显式函数调用。是这个print函数被蒙蔽了。
要打印a,可以在终端中键入a,也可以显式地键入print(a)。为了获得bn对象的良好打印布局,作者编写了一个print方法,这是在输入a或print(a)时分派的内容。(要在没有这种特定打印的情况下查看它,可以使用print.default(a))。注意到class(a) == "bn"之后,您可以使用methods("print")或键入bnlearn:::print,然后输入<tab>来查看可用函数,从而查找print方法:这将导致一个(非导出的)函数bnlearn:::print.bn。
长话短说,sna包也有一个print.bn方法,用于class "bn" (偏置网)的对象,而这个函数掩盖了bnlearn中的对象。
因此,如果您在sna之后加载bnlearn,仍然可以显式地使用bnlearn:::print.bn(a)或重新定义print方法print.bn <- bnlearn:::print.bn来获得良好的打印,并且应该按照预期进行打印。
https://stackoverflow.com/questions/50365865
复制相似问题