2

私は、100 人の人々と 5 つの病状の診断を含むデータ セットを持っています。条件の任意の組み合わせが発生する可能性がありますが、条件 D の確率が条件 A に依存し、E が条件 B に依存するように設定しました。

set.seed(14)
numpeople <- 100
diagnoses <- data.frame(A=rbinom(100, 1, .15), 
                        B=rbinom(100, 1, .1),
                        C=rbinom(100, 1, .2)
                        )
# Probability of diagnosis for D increases by .4 if patient has A, otherwise .5
diagnoses$D <- sapply(diagnoses$A, function(x) rbinom(1, 1, .4*x+.2))
# Probability of diagnosis for E increases by .3 if patient has B, otherwise rare
diagnoses$E <- sapply(diagnoses$B, function(x) rbinom(1, 1, .7*x+.1))

各セルが行と列の両方の診断を持つ人の数である共起行列を作成するには、行列代数を使用します。

diagnoses.dist <- t(as.matrix(diagnoses))%*%as.matrix(diagnoses)
diag(diagnoses.dist) <- 0
diagnoses.dist
> diagnoses.dist
   A B C  D E
A  0 1 1 11 3
B  1 0 0  1 7
C  1 0 0  5 4
D 11 1 5  0 4
E  3 7 4  4 0

次に、コード ダイアグラムを使用して、各診断の共同診断の割合を示したいと思います。

circos.clear()
circos.par(gap.after=10)
chordDiagram(diagnoses.dist, symmetric=TRUE)

5 グループのコード ダイアグラムの例

デフォルトでは、各グループに割り当てられるセクター (パイ スライス) のサイズは、リンクの数に比例します。

> colSums(diagnoses.dist) #Number of links related to each diagnosis
 A  B  C  D  E 
16  9 10 21 18 

セクター幅を設定して、各診断者の数を示すことはできますか?

> colSums(diagnoses) #Number of people with each diagnosis
 A  B  C  D  E 
16  8 20 29 18 

この問題は、サークライズの本のセクション 14.5に多少関連しているようですが、gap.after引数 の計算方法がわかりません。

サークライズの本のセクション2.3に基づいて、セクターサイズを使用して設定しようとしましたが、外側のスケールがまったく同じであるため、関数がこれをオーバーライドするcircos.initalizeと思います。chordDiagram

circos.clear()
circos.par(gap.after=10)
circos.initialize(factors=names(diagnoses), x=colSums(diagnoses)/sum(diagnoses), xlim=c(0,1))
chordDiagram(diagnoses.dist, symmetric=TRUE)

ここに画像の説明を入力

トラックを微調整するオプションはたくさんありますがchordDiagram、セクターにはあまりありません。これを行う方法はありますか?

4

1 に答える 1