Glucose = read.csv("C:/Users/Paul Vo/Desktop/Textbook/TDTU Datasets for 2020 Workshop/glucose.csv")
Nhóm nghiên cứu muốn đánh giá xem liệu sử dụng thuốc A có hiệu quả làm giảm đường huyết không. Nghiên cứu thực hiện trên 19 chuột, trong đó 10 chuột không dùng thuốc và 9 chuột được dùng thuốc. Nồng độ đường huyết của chuột được đo ở thời điểm trước và 3 thời điểm sau dùng thuốc. Giới thiệu tập tin số liệu glucose.csv: - id: mã số của chuột - time: thời điểm đo nồng độ đường huyết (trước khi dùng thuốc (T0), 2 (T2), 3 (T3) và 4 giờ (T4) sau dùng thuốc). - treatment: can thiệp (1= có dùng thuốc, 0= không dùng thuốc)
head(Glucose)
## id treatment time glucose
## 1 1 1 0 5.9
## 2 1 1 2 3.9
## 3 1 1 3 3.9
## 4 1 1 4 3.6
## 5 2 1 0 5.3
## 6 2 1 2 4.7
summary(Glucose)
## id treatment time glucose
## Min. : 1 Min. :0.0000 Min. :0.00 Min. :2.900
## 1st Qu.: 5 1st Qu.:0.0000 1st Qu.:1.50 1st Qu.:4.000
## Median :10 Median :0.0000 Median :2.50 Median :4.850
## Mean :10 Mean :0.4605 Mean :2.25 Mean :4.991
## 3rd Qu.:15 3rd Qu.:1.0000 3rd Qu.:3.25 3rd Qu.:5.900
## Max. :19 Max. :1.0000 Max. :4.00 Max. :8.000
attach(Glucose)
library(ggplot2)
ggplot(data=Glucose)+
geom_point(aes(x=time, y=glucose, fill=factor(treatment), col=factor(treatment)), size=3)+
geom_line(aes(x=time, y=glucose, group=id))
## sprit
library(ggplot2)
ggplot(data=Glucose)+
geom_point(aes(x=time, y=glucose, fill=factor(treatment), col=factor(treatment)), size=3)+
geom_line(aes(x=time, y=glucose, group=id)) + facet_grid(~treatment) +
stat_smooth((aes(x=time, y=glucose)))
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 3.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 1.6401e-016
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used at
## -0.02
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius 3.02
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : reciprocal condition
## number 1.6401e-016
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : There are other near
## singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 3.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 2.2134e-016
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used at
## -0.02
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius 3.02
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : reciprocal condition
## number 2.2134e-016
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : There are other near
## singularities as well. 4.0804
ggplot(data=Glucose, aes(x=factor(treatment), y=glucose, color=factor(treatment))) + geom_boxplot(alpha=0.5) + geom_jitter(alpha=0.2)
#t.test(glucose~factor(treatment))
library(coin)
## Loading required package: survival
oneway_test(glucose~factor(treatment))
##
## Asymptotic Two-Sample Fisher-Pitman Permutation Test
##
## data: glucose by factor(treatment) (0, 1)
## Z = 1.5636, p-value = 0.1179
## alternative hypothesis: true mu is not equal to 0
t1=subset(Glucose, time==0)
t2=subset(Glucose, time==2)
t1$glucose = Glucose$t1
t2$glucose = Glucose$t2
library(tidyverse)
## -- Attaching packages ------------------------------------------------------ tidyverse 1.3.0 --
## <U+2713> tibble 2.1.3 <U+2713> dplyr 0.8.3
## <U+2713> tidyr 1.0.0 <U+2713> stringr 1.4.0
## <U+2713> readr 1.3.1 <U+2713> forcats 0.4.0
## <U+2713> purrr 0.3.3
## -- Conflicts --------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
#g2=filter_(.data=glucose, time==0|time==2)
#library(reshape2)
#g3 = dcast(g2, id + treatment~time)
#head (g3)