Purpose

The purpose of this analysis is to compare the measurements obtained from an aberrometer and subjective refraction methods. This study focuses on three key parameters: Spherical Equivalent (SPE), J0, and J45. The goal is to determine if there are significant differences between the two measurement methods and to assess the agreement between them using Bland-Altman plots.

Load Data

# Load necessary libraries
library(readxl)
library(ggplot2)
library(dplyr)
library(kableExtra)

# Import data
data <- read.csv("C:/forus data/PROJECT 1/Clean Data/CSV DATA/R DATA.csv")

# Display the first few rows of the data
head(data) %>%
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
DEVICE EYE SPE J0 J45
ABERROMETER RIGHT -0.25 0.00 0.00
ABERROMETER RIGHT -1.12 -0.36 0.09
ABERROMETER RIGHT -2.75 0.19 0.16
ABERROMETER RIGHT 0.50 0.17 0.18
ABERROMETER RIGHT 0.75 -0.25 0.00
ABERROMETER RIGHT 0.25 -0.38 0.32

Descriptive Statistics

Descriptive statistics provide a summary of the data, giving an overview of the distribution and central tendency of the measurements for both the aberrometer and subjective refraction methods.

# Descriptive statistics
summary_data <- summary(data)
summary_data %>%
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
DEVICE EYE SPE J0 J45
Length:12736 Length:12736 Min. :-12.0000 Min. :-2.48000 Min. :-1.6100000
Class :character Class :character 1st Qu.: -0.7500 1st Qu.: 0.00000 1st Qu.: 0.0000000
Mode :character Mode :character Median : -0.2500 Median : 0.00000 Median : 0.0000000
NA NA Mean : -0.4968 Mean :-0.01773 Mean :-0.0003808
NA NA 3rd Qu.: 0.0000 3rd Qu.: 0.00000 3rd Qu.: 0.0000000
NA NA Max. : 22.0000 Max. : 2.46000 Max. : 2.1700000

T-Test Analysis

To statistically assess the differences between the aberrometer and subjective refraction methods, paired t-tests are performed for SPE, J0, and J45. The paired t-test is appropriate because measurements are taken from the same subjects using two different methods.

# Subset data for each device and eye
aberrometer_data <- subset(data, DEVICE == "ABERROMETER" & EYE == "RIGHT")
subjective_data <- subset(data, DEVICE == "SUBJECTIVE" & EYE == "RIGHT")

# Perform paired t-tests for SPE, J0, and J45
t_test_results <- list(
  SPE = t.test(aberrometer_data$SPE, subjective_data$SPE, paired = TRUE),
  J0 = t.test(aberrometer_data$J0, subjective_data$J0, paired = TRUE),
  J45 = t.test(aberrometer_data$J45, subjective_data$J45, paired = TRUE)
)

# Display the results of the t-tests
t_test_results %>%
  purrr::map_df(~broom::tidy(.)) %>%
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
estimate statistic p.value parameter conf.low conf.high method alternative
-0.1533386 -27.0244931 0.0000000 3183 -0.1644637 -0.1422134 Paired t-test two.sided
0.0013128 0.4255983 0.6704293 3183 -0.0047353 0.0073609 Paired t-test two.sided
0.0058229 2.7585611 0.0058388 3183 0.0016841 0.0099616 Paired t-test two.sided

Interpretation of P-Values

Based on the p-values obtained from the t-tests, we can interpret whether the differences between the methods are statistically significant.

# Extract p-values from the t-test results
p_values <- sapply(t_test_results, function(x) x$p.value)
names(p_values) <- c("SPE", "J0", "J45")

for (parameter in names(p_values)) {
  p_value <- p_values[parameter]
  
  if (p_value < 0.05) {
    cat("The p-value for", parameter, "is", round(p_value, 4), "which is less than 0.05. We reject the null hypothesis.\n")
    cat("There is evidence of a significant difference in", parameter, "between the two measurement methods.\n\n")
  } else {
    cat("The p-value for", parameter, "is", round(p_value, 4), "which is greater than or equal to 0.05. We fail to reject the null hypothesis.\n")
    cat("There is no significant difference in", parameter, "between the two measurement methods.\n\n")
  }
}
## The p-value for SPE is 0 which is less than 0.05. We reject the null hypothesis.
## There is evidence of a significant difference in SPE between the two measurement methods.
## 
## The p-value for J0 is 0.6704 which is greater than or equal to 0.05. We fail to reject the null hypothesis.
## There is no significant difference in J0 between the two measurement methods.
## 
## The p-value for J45 is 0.0058 which is less than 0.05. We reject the null hypothesis.
## There is evidence of a significant difference in J45 between the two measurement methods.

Bland-Altman Plots

Bland-Altman plots are used to visually assess the agreement between the two methods. These plots display the difference between the methods against their mean, and include lines for the mean difference and the limits of agreement (mean ± 1.96 standard deviations).

Bland-Altman Plot for SPE (Right Eye)

# Bland-Altman plot for SPE
bland_altman_data_spe <- data.frame(
  mean_spe = (aberrometer_data$SPE + subjective_data$SPE) / 2,
  diff_spe = aberrometer_data$SPE - subjective_data$SPE
)

# Calculate mean difference and limits of agreement
mean_diff_spe <- mean(bland_altman_data_spe$diff_spe)
upper_limit_spe <- mean_diff_spe + 1.96 * sd(bland_altman_data_spe$diff_spe)
lower_limit_spe <- mean_diff_spe - 1.96 * sd(bland_altman_data_spe$diff_spe)

# Generate Bland-Altman plot
ggplot(bland_altman_data_spe, aes(x = mean_spe, y = diff_spe)) +
  geom_point(color = "#0073C2FF") +
  geom_hline(yintercept = mean_diff_spe, col = "red", linetype = "solid") +
  geom_hline(yintercept = upper_limit_spe, linetype = "dashed", col = "blue") +
  geom_hline(yintercept = lower_limit_spe, linetype = "dashed", col = "blue") +
  labs(title = "Bland-Altman Plot for SPE (Right Eye)", x = "Mean of SPE", y = "Difference in SPE") +
  theme_minimal()

Bland-Altman Plot for J0 (Right Eye)

# Bland-Altman plot for J0
bland_altman_data_j0 <- data.frame(
  mean_j0 = (aberrometer_data$J0 + subjective_data$J0) / 2,
  diff_j0 = aberrometer_data$J0 - subjective_data$J0
)

# Calculate mean difference and limits of agreement
mean_diff_j0 <- mean(bland_altman_data_j0$diff_j0)
upper_limit_j0 <- mean_diff_j0 + 1.96 * sd(bland_altman_data_j0$diff_j0)
lower_limit_j0 <- mean_diff_j0 - 1.96 * sd(bland_altman_data_j0$diff_j0)

# Generate Bland-Altman plot
ggplot(bland_altman_data_j0, aes(x = mean_j0, y = diff_j0)) +
  geom_point(color = "#0073C2FF") +
  geom_hline(yintercept = mean_diff_j0, col = "red", linetype = "solid") +
  geom_hline(yintercept = upper_limit_j0, linetype = "dashed", col = "blue") +
  geom_hline(yintercept = lower_limit_j0, linetype = "dashed", col = "blue") +
  labs(title = "Bland-Altman Plot for J0 (Right Eye)", x = "Mean of J0", y = "Difference in J0") +
  theme_minimal()

Bland-Altman Plot for J45 (Right Eye)

# Bland-Altman plot for J45
bland_altman_data_j45 <- data.frame(
  mean_j45 = (aberrometer_data$J45 + subjective_data$J45) / 2,
  diff_j45 = aberrometer_data$J45 - subjective_data$J45
)

# Calculate mean difference and limits of agreement
mean_diff_j45 <- mean(bland_altman_data_j45$diff_j45)
upper_limit_j45 <- mean_diff_j45 + 1.96 * sd(bland_altman_data_j45$diff_j45)
lower_limit_j45 <- mean_diff_j45 - 1.96 * sd(bland_altman_data_j45$diff_j45)

# Generate Bland-Altman plot
ggplot(bland_altman_data_j45, aes(x = mean_j45, y = diff_j45)) +
  geom_point(color = "#0073C2FF") +
  geom_hline(yintercept = mean_diff_j45, col = "red", linetype = "solid") +
  geom_hline(yintercept = upper_limit_j45, linetype = "dashed", col = "blue") +
  geom_hline(yintercept = lower_limit_j45, linetype = "dashed", col = "blue") +
  labs(title = "Bland-Altman Plot for J45 (Right Eye)", x = "Mean of J45", y = "Difference in J45") +
theme_minimal()

### Conclusion In this analysis, we compared the measurements from an aberrometer and subjective refraction methods. The paired t-tests revealed significant differences in SPE and J45, but not in J0. The Bland-Altman plots further illustrated the agreement (or lack thereof) between the two methods, providing insights into the consistency of these measurement techniques.

This study highlights the importance of method comparison in clinical practice, particularly in determining the reliability and accuracy of diagnostic tools. The enhanced visualization and statistical analysis presented here offer a clear and comprehensive understanding of the performance of the aberrometer versus subjective refraction.