ウェブ解析や疫学調査の結果を解析するとき、グループ間の解析を手軽に解析できればと考えたことはありませんか。そんな方へ、グループ間の解析が手軽にできる「compareGroups」パッケージを紹介します。バージョンは3.0.1です。
この、「compareGroups」パッケージは元データで適切にデータ性質(カテゴリーや数字などの情報)を設定していれば、自動でt-test、ANOVA、Kruskall-Wallis testなどの統計手法を適応してくれます。もちろん、手法は自身でも指定できます。
また、解析結果のテーブルもLaTexやPDFで出力ができます。
今回の紹介では、パッケージに付属の「PREDIMED」という心血管イベントの予防における地中海食の影響を調べた疫学調査データを利用しています。
ウェブ解析でも「compareGroups」パッケージの利用ができると思いますので、試してみてください。
パッケージのインストール
下記、コマンドを実行してください。
install.packages("compareGroups")
PREDIMEDデータの紹介
データはRでdata(predimed)と実行すると読み込むことができます。PREDIMEDは2003〜2011年にかけて実施された非常に大きな試験となります。なお、結果は、くるみを中心としたナッツ類やエキストラバージンオイルを摂取した群で心血管イベントの発症リスクが低下した「食事内容と健康の重要性を示した」画期的な内容です。
行名 | 内容 |
---|---|
group | 低脂肪食群、地中海食 + エキストラバージンオイル群、地中海食 + ミックスナッツ群 |
sex | 性別 |
age | 年齢 |
smoke | 喫煙の有無 |
bmi | BMI |
waist | 腹囲 |
wth | 腹囲と身長の比 |
htn | 高血圧症の有無(Yes/No) |
diab | 2型糖尿病の有無(Yes/No) |
hyperchol | 脂質異常症の有無(Yes/No) |
famhist | 家族性心疾患歴の有無(Yes/No) |
hormo | ホルモン療法の有無(Yes/No) |
p14 | 食事スコア |
toevent | 疾患を引き起こすまでの期間 |
event | 引き起こした疾患の種類(AMI, stroke, or CV Death) |
実行コマンドの紹介
詳細はコマンド内コメントならびにパッケージのヘルプを確認してください。
#パッケージの読み込み library("compareGroups") #参考データの読み込み data(predimed) #各臨床値結果の群間比較 compareGroups(group ~ . , data = predimed) -------- Summary of results by groups of 'Intervention group'--------- var N p.value method selection 1 Sex 6324 <0.001** categorical ALL 2 Age 6324 0.003** continuous normal ALL 3 Smoking 6324 0.444 categorical ALL 4 Body mass index 6324 <0.001** continuous normal ALL 5 Waist circumference 6324 0.045** continuous normal ALL 6 Waist-to-height ratio 6324 <0.001** continuous normal ALL 7 Hypertension 6324 0.249 categorical ALL 8 Type-2 diabetes 6324 0.017** categorical ALL 9 Dyslipidemia 6324 0.423 categorical ALL 10 Family history of premature CHD 6324 0.581 categorical ALL 11 Hormone-replacement therapy 5661 0.850 categorical ALL 12 MeDiet Adherence score 6324 <0.001** continuous normal ALL 13 follow-up to main event (years) 6324 <0.001** continuous normal ALL 14 AMI, stroke, or CV Death 6324 0.064* categorical ALL ----- Signif. codes: 0 '**' 0.05 '*' 0.1 ' ' 1 ###解析臨床値の除外と選択### #除外は項目名の前に"-"を加えます compareGroups(group ~ . -toevent -event, data = predimed) -------- Summary of results by groups of 'Intervention group'--------- var N p.value method selection 1 Sex 6324 <0.001** categorical ALL 2 Age 6324 0.003** continuous normal ALL 3 Smoking 6324 0.444 categorical ALL 4 Body mass index 6324 <0.001** continuous normal ALL 5 Waist circumference 6324 0.045** continuous normal ALL 6 Waist-to-height ratio 6324 <0.001** continuous normal ALL 7 Hypertension 6324 0.249 categorical ALL 8 Type-2 diabetes 6324 0.017** categorical ALL 9 Dyslipidemia 6324 0.423 categorical ALL 10 Family history of premature CHD 6324 0.581 categorical ALL 11 Hormone-replacement therapy 5661 0.850 categorical ALL 12 MeDiet Adherence score 6324 <0.001** continuous normal ALL ----- Signif. codes: 0 '**' 0.05 '*' 0.1 ' ' 1 #選択は項目名の前に"+"を加えます compareGroups(group ~ age + sex + smoke + waist + hormo, data = predimed) -------- Summary of results by groups of 'Intervention group'--------- var N p.value method selection 1 Age 6324 0.003** continuous normal ALL 2 Sex 6324 <0.001** categorical ALL 3 Smoking 6324 0.444 categorical ALL 4 Waist circumference 6324 0.045** continuous normal ALL 5 Hormone-replacement therapy 5661 0.850 categorical ALL ----- Signif. codes: 0 '**' 0.05 '*' 0.1 ' ' 1 ###項目の内容でサブセット解析も手軽に可能です### #性別で抽出 #オプション subset 項目名 == 対象で指定 compareGroups(group ~ age + smoke + waist + hormo, data = predimed, subset = sex == "Female") -------- Summary of results by groups of 'Intervention group'--------- var N p.value method selection 1 Age 3645 0.056* continuous normal sex == "Female" 2 Smoking 3645 0.907 categorical sex == "Female" 3 Waist circumference 3645 0.016** continuous normal sex == "Female" 4 Hormone-replacement therapy 3459 0.898 categorical sex == "Female" ----- Signif. codes: 0 '**' 0.05 '*' 0.1 ' ' 1 #複数項目で抽出 #オプション selec list(項目名 == 対象で指定, ...)で指定 compareGroups(group ~ age + sex + smoke + waist + hormo, data = predimed, selec = list(hormo = sex == "Female", waist = waist > 20 )) -------- Summary of results by groups of 'Intervention group'--------- var N p.value method selection 1 Age 6324 0.003** continuous normal ALL 2 Sex 6324 <0.001** categorical ALL 3 Smoking 6324 0.444 categorical ALL 4 Waist circumference 6324 0.045** continuous normal waist > 20 5 Hormone-replacement therapy 3459 0.898 categorical sex == "Female" ----- Signif. codes: 0 '**' 0.05 '*' 0.1 ' ' 1 #結果のテーブルは体裁を整えることができます #createTableコマンドを使用します createTable(compareGroups(group ~ age + sex + smoke + waist + hormo, data = predimed, selec = list(hormo = sex == "Female", waist = waist > 20 ))) --------Summary descriptives table by 'Intervention group'--------- ________________________________________________________________________________ Control MedDiet + Nuts MedDiet + VOO p.overall N=2042 N=2100 N=2182 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ Age 67.3 (6.28) 66.7 (6.02) 67.0 (6.21) 0.003 Sex: <0.001 Male 812 (39.8%) 968 (46.1%) 899 (41.2%) Female 1230 (60.2%) 1132 (53.9%) 1283 (58.8%) Smoking: 0.444 Never 1282 (62.8%) 1259 (60.0%) 1351 (61.9%) Current 270 (13.2%) 296 (14.1%) 292 (13.4%) Former 490 (24.0%) 545 (26.0%) 539 (24.7%) Waist circumference 101 (10.8) 100 (10.6) 100 (10.4) 0.045 Hormone-replacement therapy: 0.898 No 1143 (97.4%) 1036 (97.2%) 1183 (97.0%) Yes 31 (2.64%) 30 (2.81%) 36 (2.95%) ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ #欠損値はmissingTableコマンドを使用します。 missingTable(compareGroups(group ~ age + sex + smoke + waist + hormo, data = predimed, selec = list(hormo = sex == "Female", waist = waist > 20 ))) --------Missingness table by 'Intervention group'--------- ____________________________________________________________________________ Control MedDiet + Nuts MedDiet + VOO p.overall N=2042 N=2100 N=2182 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ Age 0 (0.00%) 0 (0.00%) 0 (0.00%) . Sex 0 (0.00%) 0 (0.00%) 0 (0.00%) . Smoking 0 (0.00%) 0 (0.00%) 0 (0.00%) . Waist circumference . . . . Hormone-replacement therapy . . . . ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ #結果をファイルへ出力 #latexはexport2latexコマンド、pdfはreportコマンドを使用します。 #詳しくはHELPを参照ください。
少しでも、あなたのウェブや実験の解析が楽になりますように!!