gpt4 book ai didi

r - Traminer seqtree 和 seqtreedisplay 的错误消息

转载 作者:行者123 更新时间:2023-12-04 09:24:47 25 4
gpt4 key购买 nike

我在 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

最佳答案

您有以下错误:

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

希望这对您有所帮助。

关于r - Traminer seqtree 和 seqtreedisplay 的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16827168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com