library(tidyverse)
## ── 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()
library(ggplot2)
library(rmarkdown)
library(readxl)
library(coin)
## 要求されたパッケージ survival をロード中です
library(exactRankTests)
## Package 'exactRankTests' is no longer under development.
## Please consider using package 'coin' instead.
##
##
## 次のパッケージを付け加えます: 'exactRankTests'
##
## 以下のオブジェクトは 'package:coin' からマスクされています:
##
## dperm, pperm, qperm, rperm
setwd("C:/Users/eishin/Desktop/biostat2")
ds <- read_excel("C:/Users/eishin/Desktop/biostat2/サンプルデータ.xls", na = '.', 1)
hist(ds$TC)
boxplot(ds$TC)
tmp1<- ds[c("TC", "治療法")] %>% filter(治療法==1)
tmp2<- ds[c("TC", "治療法")] %>% filter(治療法==2)
var.test(tmp1$TC, tmp2$TC)
##
## F test to compare two variances
##
## data: tmp1$TC and tmp2$TC
## F = 1.1416, num df = 125, denom df = 111, p-value = 0.4767
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.7923056 1.6383808
## sample estimates:
## ratio of variances
## 1.141601
t.test(tmp1$TC, tmp2$TC, var.equal=TRUE)
##
## Two Sample t-test
##
## data: tmp1$TC and tmp2$TC
## t = 0.74948, df = 236, p-value = 0.4543
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -5.814518 12.955049
## sample estimates:
## mean of x mean of y
## 193.7099 190.1397
hist(ds$TG)
boxplot(ds$TG)
shapiro.test(ds$TG)
##
## Shapiro-Wilk normality test
##
## data: ds$TG
## W = 0.66141, p-value < 2.2e-16
tmp3<- ds[c("TG", "治療法")] %>% filter(治療法==1)
tmp4<- ds[c("TG", "治療法")] %>% filter(治療法==2)
var.test(tmp3$TG, tmp4$TG)
##
## F test to compare two variances
##
## data: tmp3$TG and tmp4$TG
## F = 0.82935, num df = 125, denom df = 111, p-value = 0.3091
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.5755962 1.1902551
## sample estimates:
## ratio of variances
## 0.8293529
wilcox.test(tmp3$TG, tmp4$TG, paired=FALSE)
##
## Wilcoxon rank sum test with continuity correction
##
## data: tmp3$TG and tmp4$TG
## W = 7135, p-value = 0.8823
## alternative hypothesis: true location shift is not equal to 0
ds1<-mutate(ds, 変化量=(5年後のTC-TC))
ds2<-mutate(ds1, 変化量正負 = (変化量>=0)) %>%
mutate(正負= if_else(変化量正負, "1", "0"))
table<-table(ds2$変化量正負, ds2$治療法)
table
##
## 1 2
## FALSE 106 89
## TRUE 20 23
chisq.test(table)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: table
## X-squared = 0.58434, df = 1, p-value = 0.4446
chisq.test(table,correct=F)
##
## Pearson's Chi-squared test
##
## data: table
## X-squared = 0.87084, df = 1, p-value = 0.3507
#4. ④ 共変量を治療法とした有効性(1:有効,0:無効)に関するロジスティック回帰
ds3<-ds[c("治療法","有効性")]
fit1<-glm(ds3$有効性~.,data=ds3,family=binomial(link="logit"))
summary(fit1)
##
## Call:
## glm(formula = ds3$有効性 ~ ., family = binomial(link = "logit"),
## data = ds3)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.2858 -0.9925 -0.9925 1.0727 1.3744
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.1553 0.4121 -2.803 0.00506 **
## 治療法 0.7033 0.2640 2.664 0.00771 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 329.11 on 237 degrees of freedom
## Residual deviance: 321.91 on 236 degrees of freedom
## AIC: 325.91
##
## Number of Fisher Scoring iterations: 4