我有一个多图的四个矩阵,如下:
> projects
1 2 3 4 5
1 0 0 4 1 0
2 0 0 3 2 5
3 0 0 0 0 0
4 0 0 0 0 1
5 0 0 0 0 0
> infrastructure
1 2 3 4 5
1 0 0 0 5 0
2 0 0 4 0 0
3 0 0 0 2 2
4 0 0 0 0 3
5 0 0 0 0 0
> information
1 2 3 4 5
1 0 1 3 0 0
2 0 0 2 3 4
3 0 0 0 0 0
4 0 0 0 0 0
5 0 0 0 0 0
> problems
1 2 3 4 5
1 0 1 0 1 0
2 0 0 0 0 0
3 0 0 0 1 1
4 0 0 0 0 0
5 0 0 0 0 0
我用......重新安排了它。
x <- array(NA, c(length(infrastructure[1,]),length(infrastructure[,1]),3))
x[,,1] <- infrastructure
x[,,2] <- information
x[,,3] <- problems
nl <- netlm(projects,x,reps=100)
当我表演&#34; netlm&#34;命令,出现下一条消息:
&#34; netlm中的错误(projects,x,reps = 100): netlm。&#34;
中需要的同类图表订单
我该如何解决? 感谢
答案 0 :(得分:0)
我在定义数组时犯了一个错误,我应该编写以下代码:array(NA,c(3,length(infrastructure[1,]),length(infrastructure[,1])))
答案 1 :(得分:0)
这里的问题是netlm需要列表而不是数组,所以我认为它不是将条目作为单独的网络读取。错误表明了这一点。它没有看到三个5x5矩阵。请改用list()
。
nets <- rgraph(5,4)
y <- nets[1,,]
info <- nets[2,,]
infra <- nets[3,,]
prob <- nets[4,,]
现在,您可以在list()
命令本身中使用netlm()
(保存一个步骤):
nl <- netlm(y,list(info,infra,prob),reps=100)
或者您可以将列表创建为对象并以这种方式使用它:
x <- list(info,infra,prob)
nl <- netlm(y,x,reps=100)
由于您已经有三个独立的网络,您可以这样做:
nl <- netlm(projects,list(problems, information, infrastructure),reps=100)