2

ライブラリ Sleuth2 の ex0622 データを使用しています

library(Sleuth2)

library(lattice)

attach(ex0622)

#Using the 'rep()' function to create a vector for the sexual preference variable ('Hetero' or 'Homo')
sex.pref=as.factor(c(rep("Hetero", 16), rep("Homo", 19), rep("Hetero", 6)))


#Using the 'rep()' function to create a vector for the Type of Death variable ('AIDS' or 'Non-AIDS')

death.type=c(rep("Aids",6), rep("Non-Aids",10), rep("Aids", 19), "Aids", rep("Non-Aids", 5))

#creating a vector of gender variable
gender=(c(rep("Male", 35), rep("Female", 6)))

length(death.type)

ex0622_alt=as.data.frame(cbind(ex0622, gender, sex.pref, death.type))
ex0622_alt

上記のコードを実行して、いくつかの要素をデータ セットに追加します。次に、格子パッケージで変数の特定の組み合わせを表示したい

histogram(~Volume[sex.pref=="Hetero"]|gender, data=ex0622_alt, main="Heterosexuals")
dotplot(Volume[sex.pref=="Hetero"]~gender,  col=1)

これらの試みは両方とも、gender と sex.pref の要素の空の組み合わせを生成してはならない場合に生成します。何が起こっているのかわかりません。

どんな助けでも大歓迎です!

ありがとう!

4

1 に答える 1

3

あなたの問題はhistogram呼び出しにあります:ex0622_altデータフレーム内では、Volume変数をでサブセット化してsex.pref == "Hetero"いますが、変数をまったくサブセット化していないgenderため、Volumeサブベクトルとgender変数の長さが同じではないため、結果は次のようになります。変。次の場合に機能します。

histogram(~Volume[sex.pref=="Hetero"] | 
           gender[sex.pref=='Hetero'], data=ex0622_alt, main="Heterosexuals")

またはsubset、より自然な arg を使用することもできます。

histogram(~Volume | gender, 
          data = ex0622_alt, subset = sex.pref == 'Hetero', main="Heterosexuals")

同じコメント (および修正) がdotplotコマンドに適用されます。

于 2011-02-20T00:26:49.100 に答える