## ── 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
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))
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に統計学的な有意差は認めなかった。
g_box1<-ggplot(data=ds2, aes(x=f_allocation, y=age)) +
geom_boxplot()
g_box1
g_box2<-ggplot(data=ds2, aes(x=f_allocation, y=al_SBP)) +
geom_boxplot()
g_box2
ds3 <- ds2 %>% filter(allocation == 1)
ds4 <- ds2 %>% filter(allocation == 2)
g_point1 <- ggplot(data=ds3, aes(x = age, y= al_SBP)) +
geom_point()
g_point1
g_point2<-ggplot(data=ds4, aes(x = age, y= al_SBP)) +
geom_point()
g_point2
setwd("C:/Users/eishin/Desktop/R_HDS")
ds5 <- read_excel("C:/Users/eishin/Desktop/R_HDS/サンプルデータ.xls", 1)
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は統計学的な有意差は認めなかった。
g_box3<-ggplot(data=ds6, aes(x=group, y=BMI)) +
geom_boxplot()
g_box3
g_box4<-ggplot(data=ds6, aes(x=group, y=TC)) +
geom_boxplot()
g_box4
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')
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))