3

我在 Mac 上使用新更新的 R 和 Traminer 来分析序列数据,并且无法让 seqtree 和 seqtreedisplay 运行回归树。使用 TraMineR 附带的 biofam 数据,R 给出了三个带有简单树和回归树的错误消息。

library(TraMineR)
library(TraMineRextras)

data(biofam)
bio.seq <- seqdef(biofam, 10:25, weights=bio$wp00tbgs, xtstep = 2)

## Create Ward clusters using an OM distance matrix

properties <- matrix(c(# left, married, child, divorced
  0, 0, 0, 0, # parent
  1, 0, 0, 0, # left
  0, 1, .5, 0,# married
  1, 1, 0, 0, # left+married
  0, 0, 1, 0, # child
  1, 0, 1, 0, # left+child
  1, 1, 1, 0, # left+married+child
  .5, 1, .5, 1 #divorced
), 8, 4, byrow=TRUE)

sm <- as.matrix(dist(properties))
indel <- .5 * max(sm)
bio.dist <- seqdist(bio.seq, method="OM", indel=indel, sm=sm, full.matrix=FALSE)

weight <- attr(bio.seq, "weights")
ward <- hclust(bio.dist, method="ward", members=weight)

## Tree display of the cluster solution and growing a regression tree

tree2 <- as.seqtree(ward, seqdata=bio.seq, diss=bio.dist, ncluster=2)
seqtreedisplay(tree2, type="I", border=NA, sortv="from.start", showdepth=TRUE) 

treereg <- seqtree(bio.seq ~ sex + plingu02, data=biofam, 
               diss=bio.dist)
seqtreedisplay(treereg, type="I", border=NA, sortv="from.start")

错误消息是

> seqtreedisplay(tree2, type="I", border=NA, sortv="from.start", showdepth=TRUE)
sh: dot: command not found
The file /private/var/folders/YY/YYp18zjXELKZUAbIpHvtIk+++TI/-Tmp-
/RtmpVNNMlt/tmpseqtree3745b091371.png does not exist.

> treereg <- seqtree(bio.seq ~ sex + cohort2 + religion + plingu02, data=bio,
 diss=bio.dist)
Error in DTNdisstree(dissmatrix = dissmatrix, predictor = predictor, terms = tterms,  : 
[!] To permute replicate, you should specify integer weights

> seqtreedisplay(treereg, type="I", border=NA, sortv="from.start")
Error in inherits(seqdata, "stslist") : object 'treereg' not found
4

1 回答 1

2

您有以下错误:

  • as.seqtreeWeightedCluster包提供(因此您需要使用 加载它library(WeightedCluster))。
  • 您需要安装 GraphVizseqtreedisplay才能正常工作:请参阅http://www.graphviz.org/(安装 GraphViz 后需要重新启动 R)
  • 由于您的序列对象是加权的,因此您需要指定应如何置换权重(通常,我们使用weight.permutation = "diss"置换距离矩阵)。

希望这可以帮助。

于 2013-05-30T09:56:11.307 回答