【问题标题】:PST: Error in names(StCol) <- A : attempt to set an attribute on NULLPST:名称错误(StCol)<- A:尝试将属性设置为 NULL
【发布时间】:2019-01-11 18:57:46
【问题描述】:

考虑以下代码:

library(PST)
library(TraMineR)
library(RCurl)

x <- getURL("https://gist.githubusercontent.com/aronlindberg/c79be941bc86274f4526705600962789/raw/6e3ee8d464c97f1c26631d604de41ca97dc22159/sequence_data.csv")
data <- read.csv(text = x)
data.seq <- seqdef(data[,2:ncol(data)], missing = "%")
pstree(data.seq)

这会生成以下错误消息:

Error in names(StCol) <- A : attempt to set an attribute on NULL

我看不出这会产生错误的任何原因。该数据适用于多个TraMineR 函数,例如

seqient(data.seq)

此错误消息的原因是什么?我该如何克服它?

【问题讨论】:

  • StColpstree 使用的调色板。发生该错误的原因可能是您没有为 data.seq 对象分配调色板,该对象具有 12 个以上的状态。尝试使用seqdefcpal 参数分配一个。

标签: r markov traminer pst


【解决方案1】:

PSTpstree 函数需要一个具有有效非空 cpal 属性的状态序列对象。仅当字母表包含不超过 12 个元素时,TraMineR seqdef 函数才会自动分配默认的 cpal 调色板。在您的示例数据中,字母表的大小为 29。因此,您需要明确定义调色板。

您可以检查下面的代码(我使用包viridis 来定义调色板)运行时没有错误。

library(PST)
library(TraMineR)
library(RCurl)
library(viridis)
x <- getURL("https://gist.githubusercontent.com/aronlindberg/c79be941bc86274f4526705600962789/raw/6e3ee8d464c97f1c26631d604de41ca97dc22159/sequence_data.csv")
data <- read.csv(text = x)
data[data=="%"] <- NA
## n: size of alphabet 
n <- length(seqstatl(data[,2:ncol(data)]))
## defining color palette
cpal <- viridis_pal(option = "D")(n)
data.seq <- seqdef(data[,2:ncol(data)], cpal=cpal)
seqdplot(data.seq)
pst.tree <- pstree(data.seq)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-29
    • 2016-08-26
    • 2023-02-06
    • 1970-01-01
    • 2021-05-17
    • 2021-05-25
    • 2019-12-10
    • 1970-01-01
    相关资源
    最近更新 更多