データの読み込み

ds1 <- read_excel("生物統計学II第2回20220929_sampledata.xlsx", na='.', 2) 
colnames(ds1) <- c("ID", "Group", "Stain", "Age", "Sex", "SBP", "HbA1c", "IMT", "Allocation")    
ds2<-mutate(ds1,Sex=ifelse(Sex==1,"Male","Female"))
ds3 <-mutate(ds2, Allocation= if_else(Allocation==1,"Sitagliptin","Conventional"))

ds4 <- read_excel("サンプルデータ.xlsx", na='.', 1) 
ds5 <- mutate(ds4, BMI=体重*10000/身長^2)
ds6 <- mutate(ds5, 治療法=if_else(治療法==1,"Standard","New"))
ds6 <- rename(ds6,Treatment=治療法)

I.以下①〜③の結果を報告せよ

①被験者背景(被験者数、年齢、性別、SBP) の一覧表

CreateTableOne(vars=c("Age","Sex","SBP"),
                        strata="Allocation", 
                        factorVars=c("Sex", "Allocation"), 
                        data=ds3)
##                  Stratified by Allocation
##                   Conventional   Sitagliptin    p      test
##   n                  231            232                    
##   Age (mean (SD))  69.72 (9.17)   69.22 (9.20)   0.559     
##   Sex = Male (%)     155 (67.1)     155 (66.8)   1.000     
##   SBP (mean (SD)) 127.83 (16.63) 128.72 (15.58)  0.553

②箱ひげ図(年齢)

ggplot(ds3, aes(x=Allocation, y=Age)) +
  geom_boxplot()

②箱ひげ図(SBP)

ggplot(ds3, aes(x=Allocation, y=SBP)) +
  geom_boxplot()

③散布図(年齢)

ggplot(ds3, aes(x=Age, y=SBP, color=Allocation)) +
  geom_point(size=0.5) + 
  geom_smooth(method="lm", formula="y~x")+
  ylim(75,210) +
  stat_regline_equation()+
  stat_cor(aes(label = paste(..rr.label.., sep = "*`,`~")),
           label.x.npc = "center")

Ⅱ.以下①〜③の結果を報告せよ

箱ひげ図では日本語が正確に記載されないため、以下においては治療法をTreatmentと変更した。

①Treatmentで群別した被験者背景(被験者数、重症度、施設、身長、体重、BMI、TC) の一覧表

CreateTableOne(vars=c("重症度","施設","身長","体重","BMI","TC"),
                        strata="Treatment", 
                        factorVars=c("重症度", "施設"), 
                        data=ds6)
##                   Stratified by Treatment
##                    New            Standard       p      test
##   n                   112            126                    
##   重症度 (%)                                      0.639     
##      1                 18 (16.1)      19 (15.1)             
##      2                 35 (31.2)      34 (27.0)             
##      3                 31 (27.7)      32 (25.4)             
##      4                 28 (25.0)      41 (32.5)             
##   施設 (%)                                        0.341     
##      1                 31 (27.7)      38 (30.2)             
##      2                 29 (25.9)      24 (19.0)             
##      3                 30 (26.8)      29 (23.0)             
##      4                 22 (19.6)      35 (27.8)             
##   身長 (mean (SD)) 175.27 (10.12) 174.56 (11.31)  0.616     
##   体重 (mean (SD))  68.71 (13.25)  69.85 (13.41)  0.510     
##   BMI (mean (SD))   22.22 (2.92)   22.82 (3.18)   0.133     
##   TC (mean (SD))   190.14 (35.38) 193.71 (37.80)  0.454

②箱ひげ図(BMI)

ggplot(ds6, aes(x=Treatment, y=BMI)) +
  geom_boxplot()

②箱ひげ図(TC)

ggplot(ds6, aes(x=Treatment, y=TC)) +
  geom_boxplot()

③平均±SDを用いた推移図(TC)

ds6l <- ds6 %>% 
  select(ID=1,Treatment=5,TC0=12,TC5=15) %>% 
   pivot_longer(cols=c(TC0,TC5), 
               names_to="time", values_to="VAL") %>% 
  mutate(year=case_when(time=="TC0" ~ 0,
                          time=="TC5" ~ 5,
                          TRUE ~ NaN)) 

ds6ls <- ds6l %>% 
  group_by(Treatment, year) %>%
  summarize(mean_TC=mean(VAL),
            SD=sd(VAL))

ggplot(ds6ls, aes(x=year, y=mean_TC, group=Treatment, color=Treatment)) + 
  geom_line() +
  geom_errorbar(aes(ymax=mean_TC+SD, ymin=mean_TC-SD), width=1) +
  coord_cartesian(xlim=c(0, 5), ylim=c(150, 230))