Load data
dta <- read.table("C:/Users/ASUS/Desktop/data/adas.txt", header=T, na.strings='.')
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library (tidyr)
library(ggplot2)
dta <- mutate(dta,
Treatment = factor(Treatment),
PID = factor(PID),
Baseline = adas02)
colnames(dta)<-c("Treatment", "PID", "2", "4", "6", "8", "10" , "12", "Baseline")
str(dta)
## 'data.frame': 80 obs. of 9 variables:
## $ Treatment: Factor w/ 3 levels "H","L","P": 2 2 2 2 2 2 2 2 2 2 ...
## $ PID : Factor w/ 80 levels "1","2","3","4",..: 1 5 8 12 13 15 19 21 24 28 ...
## $ 2 : int 22 34 40 24 29 31 22 43 18 25 ...
## $ 4 : int 30 35 41 NA 26 36 27 49 28 24 ...
## $ 6 : int NA 46 41 21 29 41 28 42 29 27 ...
## $ 8 : int 33 37 46 28 26 46 24 48 NA 18 ...
## $ 10 : int 28 31 52 30 NA 52 27 48 25 21 ...
## $ 12 : int 30 35 48 27 36 57 28 46 28 22 ...
## $ Baseline : int 22 34 40 24 29 31 22 43 18 25 ...
Reshape Data (wide to long)
dtaL <- gather(dta, Month, ADAS, "2":"12")
dtaL <- mutate(dtaL,
Baseline = as.numeric(Baseline),
ADAS = as.numeric(ADAS),
Time_f = factor(as.numeric(Month)-2),
Month = factor (Month))
str(dtaL)
## 'data.frame': 480 obs. of 6 variables:
## $ Treatment: Factor w/ 3 levels "H","L","P": 2 2 2 2 2 2 2 2 2 2 ...
## $ PID : Factor w/ 80 levels "1","2","3","4",..: 1 5 8 12 13 15 19 21 24 28 ...
## $ Baseline : num 22 34 40 24 29 31 22 43 18 25 ...
## $ Month : Factor w/ 6 levels "10","12","2",..: 3 3 3 3 3 3 3 3 3 3 ...
## $ ADAS : num 22 34 40 24 29 31 22 43 18 25 ...
## $ Time_f : Factor w/ 6 levels "0","2","4","6",..: 1 1 1 1 1 1 1 1 1 1 ...
p <- ggplot(dtaL, aes(Time_f, ADAS,
group = Treatment,
linetype = Treatment,
shape = Treatment)) +
stat_summary(fun = mean, geom = "line") +
stat_summary(fun = mean, geom = "point") +
stat_summary(fun.data = mean_se, geom = "errorbar", width = 0.2) +
scale_shape_manual(values=c(1, 2, 7)) +
scale_y_continuous(breaks=seq(20, 60, 10))+
labs(x = "Month", y = "ADAS", linetype = "Treatment", shape = "Treatment") +
theme_minimal() +
theme(legend.position=c(.15,.85))
suppressWarnings(suppressMessages(print(p)))
Reread Data to get data in wide format
dtaw <- read.table("C:/Users/ASUS/Desktop/data/adas.txt", h=T, na.strings='.')
dtaw <- dtaw %>%
mutate(Baseline= adas02)
dtaw %>%
dplyr::group_by(Treatment) %>%
dplyr::select(starts_with("adas")) %>%
furniture::table1(digits=2, total=FALSE, test=F, output="html")
## Adding missing grouping variables: `Treatment`
## Using dplyr::group_by() groups: Treatment
| H | L | P | |
|---|---|---|---|
| n = 18 | n = 17 | n = 21 | |
| adas02 | |||
| 30.22 (8.56) | 32.82 (7.51) | 29.62 (6.78) | |
| adas04 | |||
| 32.44 (7.33) | 35.12 (8.64) | 33.43 (6.42) | |
| adas06 | |||
| 33.56 (8.56) | 37.65 (9.09) | 34.86 (6.43) | |
| adas08 | |||
| 33.33 (9.06) | 36.41 (11.09) | 36.38 (6.34) | |
| adas10 | |||
| 33.72 (7.44) | 38.35 (11.19) | 37.57 (7.03) | |
| adas12 | |||
| 34.28 (7.10) | 39.18 (10.77) | 39.05 (8.80) |
Correlation matrix
knitr::kable(cor(dtaw[,3:8], use="pair"))
| adas02 | adas04 | adas06 | adas08 | adas10 | adas12 | |
|---|---|---|---|---|---|---|
| adas02 | 1.0000000 | 0.8954000 | 0.7544220 | 0.7740050 | 0.7006653 | 0.7496129 |
| adas04 | 0.8954000 | 1.0000000 | 0.8144181 | 0.7936916 | 0.7006978 | 0.7400989 |
| adas06 | 0.7544220 | 0.8144181 | 1.0000000 | 0.8628966 | 0.6716075 | 0.7615946 |
| adas08 | 0.7740050 | 0.7936916 | 0.8628966 | 1.0000000 | 0.8472388 | 0.8337049 |
| adas10 | 0.7006653 | 0.7006978 | 0.6716075 | 0.8472388 | 1.0000000 | 0.9153379 |
| adas12 | 0.7496129 | 0.7400989 | 0.7615946 | 0.8337049 | 0.9153379 | 1.0000000 |