1 Description

The new drug Novafylline is developed to reduce the symptoms of intermittent claudication, which is a medical term for pain caused by too little blood flow,
usually during exercise.Patients were randomly assigned to receive either Novafylline (active treatment) or a placebo in a double-blind study.
A total of 38 patients (20 for treatment, 18 for placebo) underwent treadmill testing at baseline and at each of 4 monthly follow-up visits.
Patients were stratified by gender (17 females, 21 males).
The primary measurement of efficacy is the walking distance on a treadmill until discontinuation due to claudication pain.
Is there any distinction in exercise tolerance profiles between patients who receive Novafylline and those on placebo?

Column 1: Treatment ID
Column 2: Patient ID
Column 3: Gender ID
Column 4: Walking distance at baseline (month 0)
Column 5: Walking distance at month 1
Column 6: Walking distance at month 2
Column 7: Walking distance at month 3
Column 8: Walking distance at month 4

2 Input Data

dta1 <- read.csv('C:/Users/HANK/Desktop/HOMEWORK/claudication.csv')
str(dta1)
## 'data.frame':    38 obs. of  8 variables:
##  $ Treatment: chr  "ACT" "ACT" "ACT" "ACT" ...
##  $ PID      : chr  "P101" "P105" "P109" "P112" ...
##  $ Gender   : chr  "M" "M" "M" "M" ...
##  $ D0       : int  190 98 155 245 182 140 196 162 195 167 ...
##  $ D1       : int  212 137 145 228 205 138 185 176 232 187 ...
##  $ D2       : int  213 185 196 280 218 187 185 192 199 228 ...
##  $ D3       : int  195 215 189 274 194 195 227 230 185 192 ...
##  $ D4       : int  248 225 176 260 193 205 180 215 200 210 ...
head(dta1)
##   Treatment  PID Gender  D0  D1  D2  D3  D4
## 1       ACT P101      M 190 212 213 195 248
## 2       ACT P105      M  98 137 185 215 225
## 3       ACT P109      M 155 145 196 189 176
## 4       ACT P112      M 245 228 280 274 260
## 5       ACT P117      M 182 205 218 194 193
## 6       ACT P122      M 140 138 187 195 205
dta1 <- mutate(dta1, 
               Treatment = factor(Treatment),
               Gender = factor(Gender),
               PID = factor(PID))

3 Wide to long format

dta1L <- gather(dta1, Month, Distance, D0:D4, factor_key=TRUE)

str(dta1L)
## 'data.frame':    190 obs. of  5 variables:
##  $ Treatment: Factor w/ 2 levels "ACT","PBO": 1 1 1 1 1 1 1 1 1 1 ...
##  $ PID      : Factor w/ 38 levels "P101","P102",..: 1 5 9 12 17 22 23 28 29 32 ...
##  $ Gender   : Factor w/ 2 levels "F","M": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Month    : Factor w/ 5 levels "D0","D1","D2",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Distance : int  190 98 155 245 182 140 196 162 195 167 ...
head(dta1L)
##   Treatment  PID Gender Month Distance
## 1       ACT P101      M    D0      190
## 2       ACT P105      M    D0       98
## 3       ACT P109      M    D0      155
## 4       ACT P112      M    D0      245
## 5       ACT P117      M    D0      182
## 6       ACT P122      M    D0      140

4 make ellipses in pairwise plot (by Treatment)

scatterplotMatrix(~ D0 + D1 + D2 + D3 + D4 | Treatment,
                  data = dta1, 
                  smooth = F, 
                  by.group = TRUE,
                  regLine = F, 
                  ellipse = T, 
                  diagonal = T, 
                  pch = c(1, 20))

5 Line chart(By treatment,By Gender)

ggplot(dta1L, aes(Month, Distance,
                  group = Treatment,
                  shape = Treatment, 
                  linetype = Treatment, 
                  color = 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)) +
  labs(x = "TIME (in months)", 
       y = "Walking distance (in meters)",
       linetype = "Treatment", shape = "Treatment") +
  theme(legend.justification = c(1, 1), 
        legend.position = c(1, 1),
        legend.background = element_rect(fill = "white",color = "black"))

treatment是ACT的組別,其每月行走距離會比PBO組別來的多。

ggplot(dta1L, aes(Month, Distance,
                  group = Treatment,
                  shape = Treatment, 
                  linetype = Treatment, 
                  color = Treatment)) +
  geom_point() +
  stat_summary(fun = mean, geom = "line") +
  stat_summary(fun = mean, geom = "point") +
  stat_summary(fun.data = mean_se, geom = "errorbar", width = 0.3) +
  scale_shape_manual(values = c(1, 2)) +
   facet_wrap( ~ Gender)+
  labs(x = "TIME (in months)", 
       y = "Walking distance (in meters)",
       linetype = "Treatment", shape = "Treatment") +
  theme(legend.justification = c(1, 1), 
        legend.position = c(1, 1),
        legend.background = element_rect(fill = "white",color = "black"))

若以性別分組會發現,行走距離增加的趨勢依然是ACT會高於PBO。

6 Analysis

# means & sd of differ Treatment and gender
dta1_nid <- dta1 %>% select(-2)
# mean
aggregate(.~ Treatment + Gender, data = dta1_nid, mean, na.rm=T)
##   Treatment Gender       D0       D1       D2       D3       D4
## 1       ACT      F 180.3750 193.3750 207.8750 196.7500 208.5000
## 2       PBO      F 165.5556 170.1111 175.7778 168.1111 171.2222
## 3       ACT      M 163.1667 179.5000 195.5833 204.0833 207.6667
## 4       PBO      M 178.3333 165.5556 173.3333 193.6667 194.2222
# sd
aggregate(.~ Treatment + Gender, data = dta1_nid, sd, na.rm=T)
##   Treatment Gender       D0       D1       D2       D3       D4
## 1       ACT      F 42.18306 33.10994 58.21006 41.65762 57.10892
## 2       PBO      F 41.52743 39.13261 47.25404 33.43443 45.34252
## 3       ACT      M 42.34669 34.51350 40.14623 28.40441 28.04001
## 4       PBO      M 45.00556 45.53051 43.68352 55.37824 47.35182

7 Correlation(Gender&treatment ACT)

cor(subset(dta1, Treatment == "ACT" & Gender == "F")[,-(1:3)])
##           D0        D1        D2        D3        D4
## D0 1.0000000 0.8021966 0.8724733 0.8483852 0.8757233
## D1 0.8021966 1.0000000 0.8645096 0.7073820 0.9054398
## D2 0.8724733 0.8645096 1.0000000 0.8937510 0.9159571
## D3 0.8483852 0.7073820 0.8937510 1.0000000 0.9251102
## D4 0.8757233 0.9054398 0.9159571 0.9251102 1.0000000
cor(subset(dta1, Treatment == "ACT" & Gender == "M")[,-(1:3)])
##           D0        D1        D2        D3        D4
## D0 1.0000000 0.8624819 0.8052568 0.5928303 0.4068980
## D1 0.8624819 1.0000000 0.6464277 0.3498338 0.4496799
## D2 0.8052568 0.6464277 1.0000000 0.6704930 0.6323603
## D3 0.5928303 0.3498338 0.6704930 1.0000000 0.5941441
## D4 0.4068980 0.4496799 0.6323603 0.5941441 1.0000000

8 Correlation(Gender&treatment PBO)

cor(subset(dta1, Treatment == "PBO" & Gender == "F")[,-(1:3)])
##           D0        D1        D2        D3        D4
## D0 1.0000000 0.9269134 0.6057892 0.8657560 0.7776916
## D1 0.9269134 1.0000000 0.6826171 0.7707920 0.7579993
## D2 0.6057892 0.6826171 1.0000000 0.3713199 0.4846551
## D3 0.8657560 0.7707920 0.3713199 1.0000000 0.7931043
## D4 0.7776916 0.7579993 0.4846551 0.7931043 1.0000000
cor(subset(dta1, Treatment == "PBO" & Gender == "M")[,-(1:3)])
##           D0        D1        D2        D3        D4
## D0 1.0000000 0.9271229 0.8530641 0.8833606 0.9202039
## D1 0.9271229 1.0000000 0.7036016 0.7846666 0.9031326
## D2 0.8530641 0.7036016 1.0000000 0.8292800 0.8073104
## D3 0.8833606 0.7846666 0.8292800 1.0000000 0.9197535
## D4 0.9202039 0.9031326 0.8073104 0.9197535 1.0000000

9 m1

summary(m1 <- gls(Distance ~ Month + Gender*Treatment + Month:Treatment,
                  weights = varIdent(form = ~ 1 | Month),
                  correlation = corSymm(form = ~ 1 | PID),
                  data = dta1L))
## Generalized least squares fit by REML
##   Model: Distance ~ Month + Gender * Treatment + Month:Treatment 
##   Data: dta1L 
##        AIC      BIC    logLik
##   1749.506 1835.414 -847.7529
## 
## Correlation Structure: General
##  Formula: ~1 | PID 
##  Parameter estimate(s):
##  Correlation: 
##   1     2     3     4    
## 2 0.878                  
## 3 0.781 0.718            
## 4 0.770 0.635 0.673      
## 5 0.746 0.736 0.715 0.837
## Variance function:
##  Structure: Different standard deviations per stratum
##  Formula: ~1 | Month 
##  Parameter estimates:
##        D0        D1        D2        D3        D4 
## 1.0000000 0.8915599 1.0795057 0.9486381 1.0287427 
## 
## Coefficients:
##                          Value Std.Error   t-value p-value
## (Intercept)          170.03789 13.440748 12.650925  0.0000
## MonthD1               15.00000  4.607348  3.255669  0.0014
## MonthD2               30.45000  6.661777  4.570852  0.0000
## MonthD3               31.10000  6.377944  4.876180  0.0000
## MonthD4               37.95000  6.955426  5.456172  0.0000
## GenderM                0.02018 15.640507  0.001290  0.9990
## TreatmentPBO           1.79485 18.675206  0.096109  0.9235
## GenderM:TreatmentPBO   0.20322 22.484646  0.009038  0.9928
## MonthD1:TreatmentPBO -19.11111  6.694322 -2.854824  0.0048
## MonthD2:TreatmentPBO -27.83889  9.679338 -2.876115  0.0045
## MonthD3:TreatmentPBO -22.15556  9.266937 -2.390817  0.0179
## MonthD4:TreatmentPBO -27.17222 10.106000 -2.688722  0.0079
## 
##  Correlation: 
##                      (Intr) MnthD1 MnthD2 MnthD3 MnthD4 GendrM TrtPBO GM:TPB
## MonthD1              -0.325                                                 
## MonthD2              -0.162  0.195                                          
## MonthD3              -0.291  0.076  0.252                                   
## MonthD4              -0.230  0.360  0.366  0.665                            
## GenderM              -0.698  0.000  0.000  0.000  0.000                     
## TreatmentPBO         -0.720  0.234  0.117  0.210  0.165  0.503              
## GenderM:TreatmentPBO  0.486  0.000  0.000  0.000  0.000 -0.696 -0.660       
## MonthD1:TreatmentPBO  0.223 -0.688 -0.134 -0.052 -0.248  0.000 -0.340  0.000
## MonthD2:TreatmentPBO  0.112 -0.134 -0.688 -0.174 -0.252  0.000 -0.170  0.000
## MonthD3:TreatmentPBO  0.200 -0.052 -0.174 -0.688 -0.457  0.000 -0.305  0.000
## MonthD4:TreatmentPBO  0.158 -0.248 -0.252 -0.457 -0.688  0.000 -0.240  0.000
##                      MD1:TP MD2:TP MD3:TP
## MonthD1                                  
## MonthD2                                  
## MonthD3                                  
## MonthD4                                  
## GenderM                                  
## TreatmentPBO                             
## GenderM:TreatmentPBO                     
## MonthD1:TreatmentPBO                     
## MonthD2:TreatmentPBO  0.195              
## MonthD3:TreatmentPBO  0.076  0.252       
## MonthD4:TreatmentPBO  0.360  0.366  0.665
## 
## Standardized residuals:
##        Min         Q1        Med         Q3        Max 
## -1.8562836 -0.6190432 -0.1082266  0.5224223  3.5519928 
## 
## Residual standard error: 43.03221 
## Degrees of freedom: 190 total; 178 residual

10 m2

summary(m2<- gls(Distance ~ Month + Treatment,
                  weights = varIdent(form = ~ 1 | Month),
                  correlation = corSymm(form = ~ 1 | PID),
                  data = dta1L))
## Generalized least squares fit by REML
##   Model: Distance ~ Month + Treatment 
##   Data: dta1L 
##        AIC      BIC    logLik
##   1789.923 1857.437 -873.9617
## 
## Correlation Structure: General
##  Formula: ~1 | PID 
##  Parameter estimate(s):
##  Correlation: 
##   1     2     3     4    
## 2 0.865                  
## 3 0.740 0.708            
## 4 0.752 0.633 0.666      
## 5 0.710 0.728 0.711 0.833
## Variance function:
##  Structure: Different standard deviations per stratum
##  Formula: ~1 | Month 
##  Parameter estimates:
##        D0        D1        D2        D3        D4 
## 1.0000000 0.8438931 1.0134753 0.8938903 0.9657476 
## 
## Coefficients:
##                  Value Std.Error   t-value p-value
## (Intercept)  184.69912  8.902720 20.746368  0.0000
## MonthD1        5.94737  3.651185  1.628887  0.1050
## MonthD2       17.26316  5.286598  3.265457  0.0013
## MonthD3       20.60526  4.913125  4.193922  0.0000
## MonthD4       25.07895  5.454259  4.598049  0.0000
## TreatmentPBO -29.03147 10.819479 -2.683260  0.0080
## 
##  Correlation: 
##              (Intr) MnthD1 MnthD2 MnthD3 MnthD4
## MonthD1      -0.440                            
## MonthD2      -0.282  0.345                     
## MonthD3      -0.398  0.223  0.371              
## MonthD4      -0.343  0.473  0.478  0.715       
## TreatmentPBO -0.576  0.000  0.000  0.000  0.000
## 
## Standardized residuals:
##        Min         Q1        Med         Q3        Max 
## -1.9320355 -0.5706269 -0.1401018  0.5628160  3.7326441 
## 
## Residual standard error: 44.87449 
## Degrees of freedom: 190 total; 184 residual
m_aov <- afex::aov_car(Distance ~ Treatment*Month + Error(PID/Month), data=dta1L)
## Contrasts set to contr.sum for the following variables: Treatment
knitr::kable(nice(m_aov))
Effect df MSE F ges p.value
Treatment 1, 36 6925.36 2.06 .043 .160
Month 3.18, 114.49 584.58 8.49 *** .048 <.001
Treatment:Month 3.18, 114.49 584.58 2.63 + .015 .050
emmeans(m_aov, ~ Month | Treatment)
## Treatment = ACT:
##  Month emmean   SE   df lower.CL upper.CL
##  D0       171 9.57 55.8      151      190
##  D1       186 9.57 55.8      166      205
##  D2       201 9.57 55.8      182      220
##  D3       202 9.57 55.8      182      221
##  D4       208 9.57 55.8      189      228
## 
## Treatment = PBO:
##  Month emmean   SE   df lower.CL upper.CL
##  D0       172 9.68 58.1      153      192
##  D1       168 9.68 58.1      149      188
##  D2       175 9.68 58.1      156      194
##  D3       181 9.68 58.1      162      201
##  D4       183 9.68 58.1      164      203
## 
## Warning: EMMs are biased unless design is perfectly balanced 
## Confidence level used: 0.95
dta1_b <- gather(dta1, Month, Distance, D1:D4, factor_key=TRUE)

xyplot(Distance ~ D0 | as.factor(Month), groups=Treatment, data=dta1_b,
       type=c("p","r","g"), layout=c(5,1),
       xlab="Baseline distance (in meters)",
       ylab="Distance (in meters)",
       auto.key = TRUE)