dat <- read_csv("colectomy-data.csv")
## Rows: 200 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): approach, diabetes
## dbl (5): patient_id, age, bmi, length_of_stay, qor15_30d
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
dat <- dat %>%
  mutate(
    approach = factor(approach),
    diabetes = factor(diabetes)
  )
str(dat)
## tibble [200 × 7] (S3: tbl_df/tbl/data.frame)
##  $ patient_id    : num [1:200] 1 2 3 4 5 6 7 8 9 10 ...
##  $ approach      : Factor w/ 2 levels "Laparoscopic",..: 1 2 1 2 1 1 1 1 1 1 ...
##  $ age           : num [1:200] 61 55 64 65 80 71 55 58 66 53 ...
##  $ bmi           : num [1:200] 37.1 28.5 39.1 30.4 26.5 20.2 22 29.1 22.1 32.5 ...
##  $ diabetes      : Factor w/ 2 levels "No","Yes": 1 1 1 1 2 1 2 1 1 1 ...
##  $ length_of_stay: num [1:200] 3 5 6 5 4 3 4 5 6 5 ...
##  $ qor15_30d     : num [1:200] 124 100 93 104 112 109 117 114 97 96 ...
summary(dat)
##    patient_id             approach        age             bmi        diabetes 
##  Min.   :  1.00   Laparoscopic:100   Min.   :36.00   Min.   :17.00   No :156  
##  1st Qu.: 50.75   Open        :100   1st Qu.:57.00   1st Qu.:26.43   Yes: 44  
##  Median :100.50                      Median :64.00   Median :29.60            
##  Mean   :100.50                      Mean   :62.88   Mean   :29.22            
##  3rd Qu.:150.25                      3rd Qu.:69.00   3rd Qu.:32.55            
##  Max.   :200.00                      Max.   :90.00   Max.   :39.20            
##  length_of_stay     qor15_30d    
##  Min.   : 1.000   Min.   : 68.0  
##  1st Qu.: 4.000   1st Qu.: 95.0  
##  Median : 5.000   Median :103.0  
##  Mean   : 5.425   Mean   :103.8  
##  3rd Qu.: 7.000   3rd Qu.:112.0  
##  Max.   :12.000   Max.   :135.0

Experimental Design

A surgical department randomized 200 adults scheduled for elective colectomy to either open surgery or laparoscopic surgery, 100 patients per approach. Before surgery, staff recorded each patient’s age, body mass index, and whether they had diabetes. The hospital’s records system also captured how many days each patient stayed in hospital after the operation.

Thirty days after surgery, patients completed the QoR-15, a quality-of-recovery questionnaire scored from 0 to 150, with higher scores meaning better recovery.

The department wants to know whether surgical approach affects quality of recovery at 30 days.

Analysis of Data

Our main independent variable is the surgical approach, and our main dependent variable is the QoR-15 score taken 30 days post surgery. Since our outcome variable is continuous, our main independent variable is categorical, and we also have other continuous variables we’d like to account for, we will use an ANCOVA approach to analyze this research question.

Examining the variables, it’s clear we must include qor15-30d and approach. Age, BMI, and diabetes status are all pre-existing variables that are measure prior to the surgery, so, if we’re interested in the effect of the surgery, these variables should be included in the model, so we can adjust for them. Length of stay, on the other hand, is measured after the surgery, and seems to be strongly related to quality of recovery. Patients who stay longer will tend to be patients who are having a more difficult recovery, and so adjusting for length of stay would be highly likely to obscure the true effect of the surgical approach on the QoR-15 score.

Assumption for ANCOVA

In order to use ANCOVA appropriate, we must ensure the following assumptions hold

  1. independence of observations,
  2. linearity of the data,
  3. homogeneity of regression slopes,
  4. homogeneity of variance between groups,
  5. normality of residuals,
  6. independence of covariates from treatment,
  7. collinearity among predictors,
  8. absence of outliers.

Assumptions 1 and 6 hold from the experimental design. One patient’s recovery shouldn’t impact another patient’s recovery, and the randomized selection of surgical approach ensures that approach is independent of a patient’s age, BMI, and diabetes status. We can strengthen our confidence with this assumption by checking the breakdown of the variables by approach.

dat %>%
  group_by(approach) %>%
  summarise(
    n = n(),
    age_mean = mean(age), age_sd = sd(age),
    bmi_mean = mean(bmi), bmi_sd = sd(bmi),
    pct_diabetes = mean(diabetes == "Yes") * 100
  ) %>%
  kable(digits = 1, caption = "Baseline characteristics by surgical approach")
Baseline characteristics by surgical approach
approach n age_mean age_sd bmi_mean bmi_sd pct_diabetes
Laparoscopic 100 61.7 9.5 29.6 4.4 24
Open 100 64.0 9.7 28.8 5.0 20

We see that the variables are evenly divided by surgical approach, as desired. We note that this table is not proof of independence. It’s just a nice sanity check on our randomization. To check linearity, we examine a scatterplot of our data.

ggplot(dat, aes(x = age, y = qor15_30d, color = approach)) +
 geom_point(alpha = 0.6) +
 geom_smooth(method = "lm", se = FALSE) +
 geom_smooth(method = "loess", se = FALSE, linetype = "dashed")
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'

ggplot(dat, aes(x = bmi, y = qor15_30d, color = approach)) +
 geom_point(alpha = 0.6) +
 geom_smooth(method = "lm", se = FALSE) +
 geom_smooth(method = "loess", se = FALSE, linetype = "dashed")
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'

We see that the data is not tightly packed on the regression line, but there’s no obvious nonlinearity outside of noise in the data, so we can proceed with the linear assumption.

For the other assumptions, we fit a model and examine each one.

fit <- lm(qor15_30d ~ approach + age + bmi + diabetes, data = dat)
fit_int <- lm(qor15_30d ~ approach * age + approach * bmi + approach * diabetes, data = dat)
Anova(fit_int, type = 3)        # look at the interaction rows
## Anova Table (Type III tests)
## 
## Response: qor15_30d
##                    Sum Sq  Df  F value    Pr(>F)    
## (Intercept)       26665.9   1 183.9194 < 2.2e-16 ***
## approach            171.2   1   1.1811 0.2785037    
## age                1654.2   1  11.4092 0.0008848 ***
## bmi                 464.9   1   3.2062 0.0749351 .  
## diabetes            961.1   1   6.6291 0.0107854 *  
## approach:age         12.7   1   0.0875 0.7677488    
## approach:bmi         65.6   1   0.4526 0.5019198    
## approach:diabetes    18.4   1   0.1272 0.7217516    
## Residuals         27837.4 192                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# or compare models directly:
anova(fit, fit_int)
## Analysis of Variance Table
## 
## Model 1: qor15_30d ~ approach + age + bmi + diabetes
## Model 2: qor15_30d ~ approach * age + approach * bmi + approach * diabetes
##   Res.Df   RSS Df Sum of Sq      F Pr(>F)
## 1    195 27931                           
## 2    192 27837  3     93.11 0.2141 0.8866
# Normality of residuals
res <- residuals(fit)
ggqqplot(res)

shapiro.test(res)
## 
##  Shapiro-Wilk normality test
## 
## data:  res
## W = 0.99684, p-value = 0.9582
# Homogeneity of variance across groups
leveneTest(res ~ approach, data = dat)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1  6.0145 0.01505 *
##       198                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Multicollinearity
vif(fit)
## approach      age      bmi diabetes 
## 1.022815 1.014476 1.011044 1.006929

Here, we see that the interaction effects have p-values comfortably above 0.05, so we can conclude the regression slopes are homogeneous. Shapiro-Wilk comfortably confirms our normality of residuals holds. Levene’s test shows a potential issue with our assumption of homogeneity of variance. The reported p-value of 0.015 provides strong evidence that our variances are not equal, so we must investigate further. We note that our subgroup sizes are equal, with 100 subjects in each. This provides some robustness against unequal variance. Furthermore, while the p-value says that a difference in variance is detectable, it doesn’t state how large the difference actually is.

dat %>%
  mutate(res = residuals(fit)) %>%
  group_by(approach) %>%
  summarise(sd_res = sd(res), var_res = var(res))
## # A tibble: 2 × 3
##   approach     sd_res var_res
##   <fct>         <dbl>   <dbl>
## 1 Laparoscopic   13.2    175.
## 2 Open           10.4    108.

This gives a ratio of variance of about 1.62 between the Laparoscopic and Open surgery approaches. A variance ratio of less than 2 is typically treated as minor when the group sizes are equal. The variances are unequal, but the discrepency is considered minor and ordinary least squares is more robust to unequal variances when the group sizes are equal, so we will continue with an OLS approach instead of switching to a weighted least squares approach.

For multicollinearity among covariates, the results of vif() are all within the 1.0 to 1.025 range, which gives no cause for concern due to multicollinearity. For outliers, examining the scatterplots above also reveals no outliers to be concerned about.

We conclude that all necessary assumptions hold well-enough to continue with a standard ANCOVA model approach.

Fitting the Model

Anova(fit, type = 2) 
## Anova Table (Type II tests)
## 
## Response: qor15_30d
##            Sum Sq  Df F value    Pr(>F)    
## approach   2141.0   1 14.9474 0.0001505 ***
## age        2999.8   1 20.9432 8.409e-06 ***
## bmi         555.5   1  3.8781 0.0503362 .  
## diabetes   2153.1   1 15.0318 0.0001444 ***
## Residuals 27930.6 195                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
confint(pairs(emmeans(fit, ~ approach)))   # adjusted mean difference + 95% CI
##  contrast            estimate   SE  df lower.CL upper.CL
##  Laparoscopic - Open     6.62 1.71 195     3.24     9.99
## 
## Results are averaged over the levels of: diabetes 
## Confidence level used: 0.95
eta_squared(Anova(fit, type = 2), partial = TRUE, alternative = "two.sided")          # partial eta-squared
## # Effect Size for ANOVA (Type II)
## 
## Parameter | Eta2 (partial) |       95% CI
## -----------------------------------------
## approach  |           0.07 | [0.02, 0.15]
## age       |           0.10 | [0.03, 0.18]
## bmi       |           0.02 | [0.00, 0.07]
## diabetes  |           0.07 | [0.02, 0.15]
summary(fit)    # estimates, SEs, t-tests
## 
## Call:
## lm(formula = qor15_30d ~ approach + age + bmi + diabetes, data = dat)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -34.290  -6.698   0.259   8.498  34.451 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  144.72970    7.68514  18.832  < 2e-16 ***
## approachOpen  -6.61788    1.71173  -3.866 0.000151 ***
## age           -0.40643    0.08881  -4.576 8.41e-06 ***
## bmi           -0.35408    0.17980  -1.969 0.050336 .  
## diabetesYes   -7.94792    2.04997  -3.877 0.000144 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 11.97 on 195 degrees of freedom
## Multiple R-squared:  0.2303, Adjusted R-squared:  0.2145 
## F-statistic: 14.59 on 4 and 195 DF,  p-value: 1.935e-10
confint(fit)    # 95% CIs for each coefficient
##                    2.5 %        97.5 %
## (Intercept)  129.5730275  1.598864e+02
## approachOpen  -9.9937694 -3.241997e+00
## age           -0.5815793 -2.312766e-01
## bmi           -0.7086829  5.240235e-04
## diabetesYes  -11.9908873 -3.904956e+00

Interpretation of the Model

From the results of the ANCOVA test above, we may conclude that approach, age, and diabetes status all have a significant effect on the QoR15 score. We may not conclude that for BMI, however, we note that the p-value is marginal. While we can’t conclude an effect exists due to BMI from this test, we might note it as a candidate for future testing with more power.

We do note a minor to moderate difference in QoR15 score due to the surgical approach. Laparoscopic approaches yield an estimated 6.62 point increase over open approaches in QoR15 score, with a 95% confidence interval [3.24, 9.99] after accounting for age, BMI, and diabetes status.