我有一个知识结构,例如𝒦 ={{∅},{a},{b},{bc},{abd},{abcd},{abcde}}
并希望将其显示为矩阵。我怎样才能在 R 中做到这一点? pks
包中的函数 blim()
采用一个矩阵,这要求我拥有一个矩阵。
Falmagne, J.-C.、Koppen, M.、Villano, M.、Doignon, J.-P. 和 Johannesen, L. (1990)。知识空间简介:如何构建、测试和搜索它们。 心理学评论,97,201224。doi:10.1037/0033-295X.97.2.201
最佳答案
此类矩阵的适当示例或
a state-by-problem indicator matrix representing the knowledge structure. An element is one if the problem is contained in the state, and else zero
可能是 blim
文档中的内容:
data(DoignonFalmagne7)
DoignonFalmagne7$K
a b c d e
00000 0 0 0 0 0
10000 1 0 0 0 0
01000 0 1 0 0 0
11000 1 1 0 0 0
11100 1 1 1 0 0
11010 1 1 0 1 0
11110 1 1 1 1 0
11101 1 1 1 0 1
11111 1 1 1 1 1
假设知识结构作为字符向量提供,并且空集对应于""
,可以按如下方式进行:
kStruct <- c("", "a", "b", "bc", "abd", "abcd", "abcde")
ul <- strsplit(kStruct, "")
cn <- unique(unlist(ul))
K <- t(sapply(ul, function(x) cn %in% x) * 1)
dimnames(K) <- list(apply(K, 1, paste, collapse = ""), cn)
K
a b c d e
00000 0 0 0 0 0
10000 1 0 0 0 0
01000 0 1 0 0 0
01100 0 1 1 0 0
11010 1 1 0 1 0
11110 1 1 1 1 0
11111 1 1 1 1 1
或者:
cn <- unique(unlist(strsplit(kStruct, "")))
K <- sapply(cn, grepl, kStruct) * 1
rownames(K) <- apply(K, 1, paste, collapse = "")
另请注意,正如我所见,blim 不需要行或列的名称。
关于r - R中的知识结构到矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17761467/