I. 「生物統計学II第2回20220929_sampledata.xlsx」を用いて,以下①~③における2群の比較を行い,R Markdownで簡潔に結果を報告せよ.ただし,Sitagliptin群(allocation=1)とConventional群(allocation=2)とする.

1-0a.必要なpackageの起動

## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6     ✔ purrr   0.3.4
## ✔ tibble  3.1.8     ✔ dplyr   1.0.9
## ✔ tidyr   1.2.0     ✔ stringr 1.4.1
## ✔ readr   2.1.2     ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
##  要求されたパッケージ ggpp をロード中です 
## 
## 
##  次のパッケージを付け加えます: 'ggpp' 
## 
## 
##  以下のオブジェクトは 'package:ggplot2' からマスクされています:
## 
##     annotate

1-0b.データの読み込み

setwd("C:/Users/eishin/Desktop/R_HDS")

ds1 <- read_excel("C:/Users/eishin/Desktop/R_HDS/生物統計学II第2回20220929_sampledata.xlsx", na = '.', 2)
ds2 <- ds1 %>% mutate(f_allocation = as_factor(allocation))

1-1 被験者背景(被験者数,年齢,性別,SBP)の一覧表

tmp01<- CreateTableOne(vars=c("age", "sex", "al_SBP"),
               strata="allocation", 
               factorVars="sex", 
               data=ds1)

tmp01
##                     Stratified by allocation
##                      1              2              p      test
##   n                     232            231                    
##   age (mean (SD))     69.22 (9.20)   69.72 (9.17)   0.559     
##   sex = 2 (%)            77 (33.2)      76 (32.9)   1.000     
##   al_SBP (mean (SD)) 128.72 (15.58) 127.83 (16.63)  0.553

Sitagliptin群(n=232例)とConventional群(n=231例)の間で、 年齢、性別、SBPに統計学的な有意差は認めなかった。

1-2 箱ひげ図の作成(年齢,SBP)

1-2a 年齢の箱ひげ図

g_box1<-ggplot(data=ds2, aes(x=f_allocation, y=age)) +
  geom_boxplot()
g_box1

1-2b SBPの箱ひげ図

g_box2<-ggplot(data=ds2, aes(x=f_allocation, y=al_SBP)) +
  geom_boxplot()
g_box2

1-3 散布図(年齢とSBP)

まずはallocationで層別化する

ds3 <- ds2 %>% filter(allocation == 1)
ds4 <- ds2 %>% filter(allocation == 2)

1-3a. Sitagliptin群での、年齢のSBPの散布図

g_point1 <- ggplot(data=ds3, aes(x = age, y= al_SBP)) +
  geom_point()
g_point1

1-3b. Conventional群での、年齢とSBPの散布図

g_point2<-ggplot(data=ds4, aes(x = age, y= al_SBP)) +
  geom_point()
g_point2

II. 「サンプルデータ.xls」の「Sheet1」を用いて,以下①~③における2群の比較を行い,R Markdownで簡潔に結果を報告せよ.ただし,標準治療群(治療法=1)と新治療群(治療法=2)とする.

2-0. データの読み込み

setwd("C:/Users/eishin/Desktop/R_HDS")

ds5 <- read_excel("C:/Users/eishin/Desktop/R_HDS/サンプルデータ.xls", 1)

2-1 被験者背景(被験者数,重症度,施設,身長,体重,BMI,TC)の一覧表

ds6 <- ds5 %>% mutate(BMI = (10^4)*(体重)/(身長^2), group=as_factor(治療法))

tmp02<- CreateTableOne(vars=c("重症度", "施設", "身長", "体重", "BMI", "TC"),
                       strata="治療法", 
                       factorVars="施設",
                       data=ds6)
tmp02
##                     Stratified by 治療法
##                      1              2              p      test
##   n                     126            112                    
##   重症度 (mean (SD))   2.75 (1.07)    2.62 (1.03)   0.314     
##   施設 (%)                                          0.341     
##      1                   38 (30.2)      31 (27.7)             
##      2                   24 (19.0)      29 (25.9)             
##      3                   29 (23.0)      30 (26.8)             
##      4                   35 (27.8)      22 (19.6)             
##   身長 (mean (SD))   174.56 (11.31) 175.27 (10.12)  0.616     
##   体重 (mean (SD))    69.85 (13.41)  68.71 (13.25)  0.510     
##   BMI (mean (SD))     22.82 (3.18)   22.22 (2.92)   0.133     
##   TC (mean (SD))     193.71 (37.80) 190.14 (35.38)  0.454

標準治療群(n=126例)と新規治療群(n=112例)の間で、重症度、 施設、身長、体重、BMI、TCは統計学的な有意差は認めなかった。

2-2 箱ひげ図(BMI,TC)

2-2a 箱ひげ図(BMI)

g_box3<-ggplot(data=ds6, aes(x=group, y=BMI)) +
  geom_boxplot()
g_box3

2-2b 箱ひげ図(TC)

g_box4<-ggplot(data=ds6, aes(x=group, y=TC)) +
  geom_boxplot()
g_box4

2-3. 推移図

2-3a. 推移図に向けたデータ整理

ds6l <- ds6 %>% 
  select(症例番号=1,治療法=5,TC_0y=12,TC_5y=15) %>% 
  pivot_longer(cols=c(TC_0y,TC_5y), 
               names_to="VISIT", values_to="VAL") %>%
  mutate(f.group = factor(治療法))

ds6ls <- ds6l %>% 
  group_by(VISIT, f.group) %>%
  summarize(mu=mean(VAL),
              SD=sd(VAL), .groups='drop')

2-3b. 推移図の作成

ggplot(ds6ls, aes(x=VISIT, y=mu, group=f.group, color=f.group)) + 
  geom_line() + 
  geom_errorbar(aes(ymax=mu+SD, ymin=mu-SD), width=0.2)+
  coord_cartesian(xlim=c(0.5,2.5), ylim=c(125, 250))