理学療法士がまとめたノート

統計学備忘録(R言語のメモ)

since2016 ときどきTEXのメモ

表1の作り方 "tableone"

年齢 <- c(52,55,52,56,56,49,43,48,43,42,44,43,48,51,43,49,39,38,50,52,59,65,54,39,53,39,50,41,44,56,54,57,53,51,61,51,57,59,55,52)<- c("男","男","男","男","男","男","男","男","男","男","男","男","男","男","男","男","男","男","男","女","女","女","女","女","女","女","女","女","女","女","女","女","女","女","女","女","女","女","女","女")
運動習慣 <- c("NO","NO","NO","YES","NO","NO","NO","YES","NO","YES","NO","NO","NO","NO","NO","NO","YES","NO","YES","NO","YES","NO","YES","NO","NO","NO","NO","YES","YES","NO","YES","NO","NO","NO","YES","NO","NO","YES","YES","NO")
data01 <- data.frame(年齢,, 運動習慣)

パッケージtableoneをインストール

install.packages("tableone")
library(tableone)

#一覧にしたい変数名を記載
vars <- c("年齢","性")

#名義変数を指定
# 注意)IDがある場合にはファクターに入れないこと
facvars <- c("性")

#strataで分割する
table <- CreateTableOne(
  vars = vars, 
  strata = "運動習慣", 
  data = data01, 
  factorVars = facvars) 

table 

p値:連続変数=分散分析/t検定 , 名義変数=カイ二乗検定

                  Stratified by 運動習慣
                   NO            YES           p      test
  n                   27            13                    
  年齢 (mean (SD)) 49.67 (6.44)  50.92 (7.48)   0.586=(%)         14 (51.9)      5 (38.5)   0.648     

性をfisherの正確検定、年齢を正規分布に従わないとしてIQRを提示する場合
性別は一行に両レベル表示 quote = TRUEでエクセルで区切り位置設定で必要

print(table, nonnormal = c("年齢"),
      exact = c("性"), cramVars = "性",
      quote = TRUE)

                     Stratified by 運動習慣
                      NO                   YES                  p      test   
  n                      27                   13                              
  年齢 (median [IQR]) 51.00 [43.50, 53.00] 54.00 [44.00, 56.00]  0.478 nonnorm
  性 =/(%)      13/14 (48.1/51.9)      8/5 (61.5/38.5)     0.511 exact  

詳細は下記を参照ください

tableone: 医学研究で必要な"表1"を作成するRパッケージ