2017-04-13 3 views
1

データセット内のすべてのシーケンス(すなわちid)の遷移行列を生成する方法はありますか?TraMinerの各シーケンスの遷移率を計算する

私の場合、データはTSE形式であるため、TraMineRextrasパッケージのいくつかの機能を使用します。

私の意図は、各シーケンスをループにあるが、私は与えられたIDの遷移率を計算したいとき、私はTSE_to_STS()機能を実行した後、次のエラーを取得:「rownames」<で

エラー - ( 「TMP」、値=「1」):2つの配列の最小値は、TSE_to_STS()の引数に期待されているように見えない寸法

物体の「rownames」を設定する 試み。 TraMineRからTraMineRextrasseqtrateから

test.events <- c("A","B","C") 
test.stm <- seqe2stm(test.events, dropList=list("A"=test.events[-1], B=test.events[-2], C=test.events[-3])) 
test.tse <- data.frame(id = c(1,1,1), time = c(1,2,3), event = c("A","B","C")) 
test.sts <- TSE_to_STS(test.tse, id = "id", timestamp = "time", event = "event", stm=test.stm, tmin=1, tmax=4, firstState="None") 
test.seqdef <- seqdef(test.sts,informat = "STS") 
seqtrate(test.seqdef) 

答えて

0

機能TSE_to_STSは、シーケンスのセットのために意図されており、単一のシーケンスでは動作しません。これは、内部的には、ベクトルで動作しないテーブル用の関数を使用するためです。

ダミー・イベントを含むダミー・シーケンスを追加し、確率遷移の結果のマトリックスからダミー・イベントを削除することを回避します。

test.events <- c("A","B","C","X") 
test.stm <- seqe2stm(test.events, dropList=list("A"=test.events[-1], 
    B=test.events[-2], C=test.events[-3], X=test.events[-4])) 
test.tse <- data.frame(id = c(99,1,1,1), time = c(0,1,2,3), 
    event = c("X","A","B","C")) 
test.sts <- TSE_to_STS(test.tse, id = "id", timestamp = "time", 
    event = "event", stm=test.stm, tmin=1, tmax=4, firstState="None") 
test.seqdef <- seqdef(test.sts,informat = "STS") 
test.trate <- seqtrate(test.seqdef) 
test.trate[-nrow(test.trate),-ncol(test.trate)] 

これが役に立ちます。

+0

説明のためにありがとう。回避策として、私は異なるIdを持つ2つの同一のシーケンスを作成します。このように 'TSE_to_STS'は私に予想遷移マトリックスを与えます。 – Benoa411

1

ギルバートの説明に基づいて、ここに私の変更されたコードがあります。これは、異なるID(= 99)を持つ同一のシーケンスを作成します。 2つの配列の転移速度が同一である場合、転移の行列は1つの配列で計算されたものと同じです。ダミーイベントを作成せずに動作します。

test.events <- c("A","B","C") 
test.stm <- seqe2stm(test.events, dropList=list("A"=test.events[-1], B=test.events[-2], C=test.events[-3])) 
test.tse <- data.frame(id = c(1,1,1), time = c(1,2,3), event = c("A","B","C")) 
test.tse.bis <- test.tse 
test.tse.bis[,1] <- 99 
test.tse <- rbind(test.tse,test.tse.bis) 
test.sts <- TSE_to_STS(test.tse, id = "id", timestamp = "time", event = "event", stm=test.stm, tmin=1, tmax=4, firstState="None") 
test.seqdef <- seqdef(test.sts,informat = "STS") 
seqtrate(test.seqdef)