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

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

since2016 ときどきTEXのメモ

基準値の変更

df <- data.frame(c(rep("あり",20),rep("なし",10)),
           c(rep("あり",9),rep("なし",6),rep("あり",5),rep("なし",10)),
           c(30, 35, 29, 22, 32, 29, 30, 33, 35, 25, 
             30, 35, 29, 22, 32, 29, 30, 31, 25, 25, 
             16, 16, 18, 22, 10, 29, 20, 18, 12, 16))
colnames(df) <- c("筋トレ","歩行練習","効果")
library(tableone)
vars <- c("筋トレ", "歩行練習", "効果")
facvars <- c("筋トレ", "歩行練習")
table <- CreateTableOne(
    vars = vars, 
    #strata =
    data = df, 
    factorVars = facvars) 
print(table,quote = TRUE)

筋トレの基準を「なし」に変更

df$筋トレ <- as.factor(df$筋トレ)
df$筋トレ <- relevel(df$筋トレ, ref="なし")

vars <- c("筋トレ", "歩行練習", "効果")
facvars <- c("筋トレ", "歩行練習")
table <- CreateTableOne(
    vars = vars, 
    #strata =
    data = df, 
    factorVars = facvars) 
print(table,quote = TRUE)