2

似乎PST无法预测由单个状态组成的上下文之后的下一个状态的条件概率,例如EX-EX

考虑这段代码:

# Load libraries
library(RCurl)
library(TraMineR)
library(PST)

# Get data
x <- getURL("https://gist.githubusercontent.com/aronlindberg/08228977353bf6dc2edb3ec121f54a29/raw/c2539d06771317c5f4c8d3a2052a73fc485a09c6/challenge_level.csv")
data <- read.csv(text = x)

# Load and transform data
data <- read.table("thread_level.csv", sep = ",", header = F, stringsAsFactors = F)

# Create sequence object
data.seq <- seqdef(data[2:nrow(data),2:ncol(data)], missing = NA, right= NA, nr = "*")

# Make a tree
S1 <- pstree(data.seq, ymin = 0.05, L = 6, lik = TRUE, with.missing = TRUE)

# Mine the context
context <- seqdef("EX-EX")
p_context <- predict(S1.p1, context, decomp = F, output = "prob")

该行context <- seqdef("EX-EX")产生:

[>] 1 distinct states appear in the data: 
     1 = EX
Error: 
 [!] alphabet contains only one state

这意味着predict()无法执行。

如何根据只有 1 个状态且可能重复多次的上下文预测下一个状态的条件概率?

4

1 回答 1

2

这是seqdef自 1.8-12 版以来已修复的问题。

这是我得到的TraMineR 1.8-13

> context <- seqdef("EX-EX")
 [>] 1 distinct states appear in the data: 
     1 = EX
 [>] state coding:
       [alphabet]  [label]  [long label] 
     1  EX          EX       EX
 [>] 1 sequences in the data set
 [>] min/max sequence length: 2/2
> p_context <- predict(S1, context, decomp = F, output = "prob")
 [>] 1 sequence(s) - min/max length: 2/2
 [>] max. context length: L=6
 [>] found 2 distinct context(s)
 [>] total time: 0.019 secs
> p_context
           prob
[1] 0.000476372

请注意,我将您的 undefined 替换S1.p1S1.

于 2017-01-27T18:37:03.860 回答