Exercise on interpretation

Back to the main page

Interpretation

The tab Exercise introduction explains the context and the datasets - please read it carefully. Then proceed to the Questions tab and answer the questions.

You are part of a cohort study looking at neck pain in physiotherapy and chiropractic practice. The cohort study has collected data at baseline and 3 months follow-up on the Neck Disability Index (NDI). The 3 months follow-up also has a an external anchor (transition rating). You have decided to look at interpretation of the NDI scores.

The NDI

The NDI has 10 items (similar to the ODI), each item has 6 response options, and the scale range is 0-50 (high score equals high neck disability). It is based on a reflective model. You can view the NDI in full by clicking here:

Neck Disability Index

The dataset

The exercise uses a dataset called ndi_synthetic_teaching.rds. The dataset contains all 10 items of the NDI and a Global Perceived Effect scale (also called external anchor or transition rating). The items are named the following way:

  • n1 = item 1
  • _1 = time 1 (t1)
  • _2 = time 2 (t2)

The external anchor is rated as follows:

  • Much improved (1)
  • Improved (2)
  • Slightly improved (3)
  • No change (4)
  • Slightly worse (5)
  • Worse (6)
  • Much worse (7)

The dataset structure is shown in Table 1.

Code
# Opening ndi_synthetic_teaching.rds. The dataset is located in the data-folder.

ndi_data <- readRDS(here("files", "02_advanced_course", "day2", "exercises", "interpretation", "ndi_synthetic_teaching.rds")) |> 
  select(-synthetic)

ndi_data |>
  slice_head(n = 6) |>                     # show first 6 rows
  gt() |>
  tab_header(
    title = "Table 1. First 6 lines of the dataset"
  ) |> 
  cols_align(
    align = "center",
    columns = everything()) |>             # center short numbers
  cols_width(everything() ~ px(28)) |>     # narrow columns
  tab_options(
    table.font.size      = px(10),         # smaller font; try 9–11 px
    data_row.padding     = px(1),          # tight row padding
    column_labels.padding= px(2),
    table.width          = pct(100),       # use full content width
    heading.align = "left"
  )
Table 1. First 6 lines of the dataset
n1_1 n2_1 n3_1 n4_1 n5_1 n6_1 n7_1 n8_1 n9_1 n10_1 n1_2 n2_2 n3_2 n4_2 n5_2 n6_2 n7_2 n8_2 n9_2 n10_2 anchor
1 0 0 1 4 2 0 0 1 1 0 0 0 0 2 0 0 0 0 0 1
2 0 1 1 2 0 0 1 1 1 1 1 1 1 0 1 1 1 1 1 2
3 1 1 2 3 0 1 1 2 3 1 0 1 0 0 0 0 1 0 0 2
2 0 1 0 2 1 1 2 2 1 2 0 1 0 2 1 2 1 1 2 2
3 0 0 2 3 0 0 2 1 1 1 0 0 1 0 0 0 1 0 0 2
3 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

The variables are summarised below:

Code
# This is for showing a summary of the dataset

(summary <- skim(ndi_data))
Data summary
Name ndi_data
Number of rows 331
Number of columns 21
_______________________
Column type frequency:
numeric 21
________________________
Group variables None

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
n1_1 0 1 2.31 1.07 0 2 2 3.0 5 ▃▇▅▂▁
n2_1 0 1 1.07 1.09 0 0 1 2.0 5 ▇▂▁▁▁
n3_1 0 1 1.60 1.37 0 1 1 2.0 5 ▇▂▁▂▁
n4_1 0 1 1.81 1.30 0 1 2 3.0 5 ▇▅▅▁▁
n5_1 0 1 2.30 1.55 0 1 3 3.0 5 ▇▃▇▂▂
n6_1 0 1 1.16 1.18 0 0 1 2.0 5 ▇▂▁▁▁
n7_1 0 1 1.73 1.46 0 1 1 3.0 5 ▇▂▃▁▁
n8_1 0 1 1.87 1.35 0 1 2 3.0 5 ▇▃▅▁▁
n9_1 0 1 1.79 1.27 0 1 2 3.0 5 ▇▅▃▂▁
n10_1 0 1 2.33 1.47 0 1 2 3.0 5 ▇▅▃▃▂
n1_2 0 1 1.78 1.21 0 1 2 2.0 5 ▇▆▃▁▁
n2_2 0 1 1.00 1.21 0 0 1 1.5 5 ▇▂▁▁▁
n3_2 0 1 1.31 1.26 0 0 1 2.0 5 ▇▂▁▁▁
n4_2 0 1 1.55 1.31 0 0 1 2.0 5 ▇▅▂▁▁
n5_2 0 1 1.79 1.41 0 1 2 3.0 5 ▇▃▃▁▁
n6_2 0 1 1.21 1.30 0 0 1 2.0 5 ▇▂▁▁▁
n7_2 0 1 1.39 1.32 0 0 1 2.0 5 ▇▃▂▁▁
n8_2 0 1 1.50 1.44 0 0 1 3.0 5 ▇▃▂▁▁
n9_2 0 1 1.33 1.29 0 0 1 2.0 5 ▇▂▁▁▁
n10_2 0 1 1.72 1.45 0 1 2 3.0 5 ▇▃▂▂▁
anchor 0 1 3.15 1.57 1 2 3 5.0 7 ▇▃▃▅▁

Start with the questions in tab ‘1. The GPE’ and, when finished, continue to the next.

Please write your answers to the questions in a Word document. The exercise including answers can be downloaded after the course as a html-document from the webpage.

In your data collection you included the Global Perceived Effect (GPE) scale (the external anchor) which was answered 3 months after baseline. The question was:

How would you describe your general neck/arm problems now, compared now to how you were when the treatment started?

  • Much improved
  • Improved
  • Slightly improved
  • No change
  • Slightly worse
  • Worse
  • Much worse

Questions

1.1 What are the possible problems (biases) with a question like this?

1.2 How would you meaningfully dichotomise the GPE into ‘Improved patients’ and ‘No change patients’? Justify your answer.

1.3 If you were to design your study with a different GPE scale, discuss how you could do it?

Have a look at the distribution of the anchor categories which are shown in Figure 1.

Code
# Plotting anchor categories against NDI change score

# Identify items and anchor column
ndi_items_t1 <- paste0("n", 1:10, "_1")
ndi_items_t2 <- paste0("n", 1:10, "_2")
anchor_col <- "anchor"

# Compute NDI change (sum of items at T2 minus sum at T1)
ndi_data_change <- ndi_data |>
  mutate(
    t1 = rowSums(across(all_of(ndi_items_t1)), na.rm = FALSE),
    t2 = rowSums(across(all_of(ndi_items_t2)), na.rm = FALSE),
    ndi_change = t2 - t1,
    anchor_f = factor(
      .data[[anchor_col]],
      levels = 1:7,
      labels = c(
        "Much improved", "Improved", "Slightly improved",
        "No change", "Slightly worse", "Worse", "Much worse"
      )
    )
  ) |>
  drop_na(ndi_change, !!anchor_col)

# counts in *factor* order (keeps empty levels)
counts_df <- ndi_data_change |>
  group_by(anchor_f, .drop = FALSE) |>
  summarise(n = n(), .groups = "drop")

# named vector: names are the raw labels, values are "Label (n=..)"
x_labs <- counts_df |>
  mutate(lbl = paste0(as.character(anchor_f), " (n=", n, ")")) |>
  select(name = anchor_f, lbl) |>
  mutate(name = as.character(name)) |>
  tibble::deframe()   # vecorizing

# Plot: boxplots with jitter and mean marker
ggplot(ndi_data_change, aes(x = anchor_f, y = ndi_change)) +
  geom_boxplot(
    outlier.shape = NA,
    fill = "lightblue",
    color = "black",
    alpha = 0.7
    ) +
  geom_jitter(width = 0.15, alpha = 0.35, size = 1.6) +
  stat_summary(
    fun = mean,
    geom = "point",
    shape = 23,
    size = 3,
    fill = "blue"
    ) +
  labs(
    title = "Figure 1. NDI change score (T2 - T1) by anchor category",
    x = "Anchor category",
    y = "NDI change score (T2 - T1)",
    caption = "Note: Blue point = Mean value"
  ) +
  scale_x_discrete(labels = x_labs) +
  scale_y_continuous(
    breaks = seq(min(ndi_data_change$ndi_change, na.rm = TRUE), 
                 max(ndi_data_change$ndi_change, na.rm = TRUE), by = 5)) +
  theme_minimal(base_size = 13) +
  theme(
    panel.grid.minor.y = element_blank(),
    axis.text.x = element_text(angle = 20, hjust = 0.5, vjust = 1),
    plot.caption = element_text(
      hjust = 0,         # left-align caption
      face = "italic",   # italic style
      size = 10          # smaller font size
    )
    )

Questions

2.1 From Figure 1, what is the approximate MIC using the ‘Mean value techniques’?

2.2 What is the approximate MIC using ‘Difference in mean value techniques’?

Now you want to determine the MIC of the NDI using contemporary methods. You decide to look at both anchor properties and the MIC using various methods.

3.1 Anchor dichotomisation

In this exercise, you need to dichotomise the transition question into an improvement variable. We do this as follows:

Improved patients

  • Much improved (1)
  • Improved (2)

Unchanged patients

  • Slightly improve (3)
  • No change (4)
  • Slightly worse (5)

The categories Worse and Much worse are left out because only 12 patients showed clear deterioration, and therefore the MIC for deterioration will not be calculated.

Some authors argue that Slightly improved should be grouped with the improved patients, since this would make the MIC truly reflect the idea of “minimal improvement”. In this example, however, we deliberately place Slightly improved with the unchanged group, to keep the illustration simple.The dicotomous improvement variable you call trat.

To get an overview of the data you make a summary of the most important data and present the results in Table 2.

Code
# Generating improved variable (trat)

ndi_data_trat <- ndi_data_change |> 
  mutate(
    trat = case_when(
      anchor %in% c(1, 2) ~ 1L,      # improved = 1
      anchor %in% c(3, 4, 5) ~ 0L,   # no change = 0
      TRUE ~ NA_integer_             # Rest = NA
    )
  ) |> 
  select(-anchor_f) |> 
  relocate(anchor, .before = trat)

# Testing dichotomisation
# ctable(ndi_data_trat$anchor, ndi_data_trat$trat)

# Generating table 2

num_means_sds <- ndi_data_trat |>        # mean, sd of t1, t2 and change
  summarise(
    t1_mean = mean(t1, na.rm = TRUE),
    t1_sd = sd(t1, na.rm = TRUE),
    t2_mean = mean(t2, na.rm = TRUE),
    t2_sd = sd(t2, na.rm = TRUE),
    change_mean = mean(ndi_change, na.rm = TRUE),
    change_sd = sd(ndi_change, na.rm = TRUE)
  )

anch <- ndi_data_trat |>                 # median, IQR of anchor
  summarise(
    anchor_median = median(anchor, na.rm = TRUE),
    anchor_iqr    = IQR(anchor, na.rm = TRUE)
  )

trat_prop <- ndi_data_trat |>            # proportion of improved
  summarise(trat_prop = mean(trat == 1, na.rm = TRUE))

summary_tbl <- tibble(                   # Generating tibble
  variable   = c("t1", "t2", "ndi_change", "anchor", "trat"),
  mean       = c(num_means_sds$t1_mean, num_means_sds$t2_mean, num_means_sds$change_mean, NA, NA),
  sd         = c(num_means_sds$t1_sd,   num_means_sds$t2_sd,   num_means_sds$change_sd,   NA, NA),
  median     = c(NA, NA, NA, anch$anchor_median, NA),
  iqr        = c(NA, NA, NA, anch$anchor_iqr,    NA),
  proportion = c(NA, NA, NA, NA, trat_prop$trat_prop)
)

summary_tbl |>                           # Generating table
  gt(rowname_col = "variable") |>
  tab_header(title = "Table 2. NDI summary statistics") |>
  cols_label(
    mean = "Mean", sd = "SD",
    median = "Median", iqr = "IQR",
    proportion = "Proportion improved"
  ) |>
  fmt_number(columns = c(mean, sd), decimals = 2) |>
  fmt_percent(columns = proportion, decimals = 1) |>
  sub_missing(everything(), missing_text = "") |>
  cols_align(align = "center", columns = everything()) |> 
  tab_options(
    table.layout = "auto",
    heading.align = "left"
  ) |>
  tab_footnote(
    footnote = "Trat = Dichotomised anchor",
    locations = cells_stub(rows = "trat")
  )
Table 2. NDI summary statistics
Mean SD Median IQR Proportion improved
t1 17.96 9.10


t2 14.59 9.86


ndi_change −3.37 9.62


anchor

3 3
trat1



41.1%
1 Trat = Dichotomised anchor

Question

3.1.1 What is the proportion of improved patients in the population and why is it important?

3.2 Anchor correlation to the change score

The next step is to scrutinize the correlation between the change score and the external anchor. Therefore, you calculate the following correlations:

Code
# The correlation is calculated using two methods: Polyserial correlation (assumes continuous var to be normally distributed) and Spearman's correlation.

# -------Polyserial correlation--------------------

# Polyserial function and formatting function
polyserial_tidy <- function(x, y) {
  fit <- polycor::polyserial(x, y, ML = TRUE, std.err = TRUE)
  se  <- sqrt(fit$var[1, 1])
  tibble(
    r_polyserial = unname(fit$rho),
    se           = se,
    ci_low       = fit$rho + qnorm(0.025) * se,
    ci_high      = fit$rho + qnorm(0.975) * se,
    z            = fit$rho / se,
    p_value      = 2 * pnorm(-abs(fit$rho / se))
  )
}

fmt_p <- function(p) ifelse(is.na(p), NA_character_,
                            ifelse(p < .001, "<0.001", sprintf("%.3f", p)))

# Converting anchor into factor (required by polycor)
ndi_data_anc_fac <- ndi_data_trat |> 
  mutate(anchor_ord = ordered(anchor, levels = sort(unique(anchor))))


# Polyserial correlation (ML)
poly_test <- polyserial_tidy(ndi_data_anc_fac$ndi_change, ndi_data_anc_fac$anchor_ord)

# -------Spearman's correlation--------------------

spearman_test <- cor.test(ndi_data_anc_fac$ndi_change, as.numeric(ndi_data_anc_fac$anchor_ord),
                          method = "spearman", exact = FALSE)
r_s <- unname(spearman_test$estimate)  # Spearman's rho
p_s <- spearman_test$p.value
n   <- nrow(ndi_data_anc_fac)

# Generating tibble with correlations

corr_tbl_dta <- tibble(
  Coefficient = c("Spearman’s ρ", "Polyserial r"),
  Estimate    = c(r_s, poly_test$r_polyserial),
  SE          = c(NA_real_, poly_test$se),
  `95% CI (polyserial)` = c(NA_character_, sprintf("[%.2f, %.2f]", poly_test$ci_low, poly_test$ci_high)),
  `p-value`   = c(fmt_p(p_s), fmt_p(poly_test$p_value)),
  N           = c(n, n)
)

# gt table
cor_tbl <- corr_tbl_dta |>
  gt() |>
  fmt_number(columns = c(Estimate, SE), decimals = 2) |>
  cols_label(
    Coefficient = "Coefficient",
    Estimate    = "Estimate",
    SE          = "SE",
    `95% CI (polyserial)` = "95% CI",
    `p-value`   = "p-value",
    N           = "N"
  ) |>
  cols_align(
    align   = "center",
    columns = c(Estimate, SE, `95% CI (polyserial)`, `p-value`, N)
    ) |> 
  tab_header(
    title = "Association between NDI change score and 7-point anchor",
  ) |>
  tab_footnote(
    footnote = "Polyserial estimated via polycor::polyserial (ML); SE and CI from asymptotic normality.",
    locations = cells_column_labels(columns = `95% CI (polyserial)`)
  )

cor_tbl
Association between NDI change score and 7-point anchor
Coefficient Estimate SE 95% CI1 p-value N
Spearman’s ρ 0.76 NA NA <0.001 331
Polyserial r 0.75 0.02 [0.71, 0.80] <0.001 331
1 Polyserial estimated via polycor::polyserial (ML); SE and CI from asymptotic normality.

Question

3.2.1 Explain what the correlation coefficients means and why they are important.

3.3 Anchor reliability

Anchor reliability is estimated using confirmatory factor analysis.

Code
# Inspecting dataset for category frequencies

# dfSummary(ndi_data_trat)

# Recoding data from 0-5 to 0-4 as some items have too few responses in cat 5 (i.e. collapsing cat. 5 = 4).
ndi_data_trat <- ndi_data_trat |>
  mutate(
    across(
      .cols = c(
        num_range("n", 1:10, width = 0, suffix = "_1"),
        num_range("n", 1:10, width = 0, suffix = "_2")
        ),
        ~ case_when(
          .x %in% 4:5 ~ 4L,
          TRUE ~ (.x)
      )
    )
  )

# First we specify the model to estimate the anchor reliability

model <- '
  F1 =~ n1_1+n2_1+n3_1+n4_1+n5_1+n6_1+n7_1+n8_1+n9_1+n10_1+trat
  F2 =~ n1_2+n2_2+n3_2+n4_2+n5_2+n6_2+n7_2+n8_2+n9_2+n10_2+trat
  
  # Correlated errors over time
  
  n1_1 ~~ n1_2
  n2_1 ~~ n2_2
  n3_1 ~~ n3_2
  n4_1 ~~ n4_2
  n5_1 ~~ n5_2
  n6_1 ~~ n6_2
  n7_1 ~~ n7_2
  n8_1 ~~ n8_2
  n9_1 ~~ n9_2
  n10_1 ~~ n10_2
  
  # New residual covariance suggesed by MI
  
  '

# Then we apply the model to our dataset using tr_reliability from the MIC-package

reliability <- tr_reliability(data = ndi_data_trat, model = model)

glue("The anchor reliability is: {round(reliability$reliability, 2)}")
The anchor reliability is: 0.88

Questions

3.3.1 Discuss what the anchor reliability tells you?

3.3.2 What do you think of the anchor reliability?

3.4 Anchor present-state bias

Lastly, we will estimate present-state bias of the anchor using longitudinal CFA modelling as included in the MIC-package.

Code
# Using LCFA for estimating present-state bias (and other things)

model_cfa <- '
   # Factor specifications
   
   F1 =~ a1*n1_1+a2*n2_1+a3*n3_1+a4*n4_1+a5*n5_1+a6*n6_1+a7*n7_1+a8*n8_1+a9*n9_1+a10*n10_1+f1*trat
   F2 =~ a1*n1_2+a2*n2_2+a3*n3_2+a4*n4_2+a5*n5_2+a6*n6_2+a7*n7_2+a8*n8_2+a9*n9_2+a10*n10_2+f2*trat

   # Correlated errors over time

   n1_1 ~~ n1_2
   n2_1 ~~ n2_2
   n3_1 ~~ n3_2
   n4_1 ~~ n4_2
   n5_1 ~~ n5_2
   n6_1 ~~ n6_2
   n7_1 ~~ n7_2
   n8_1 ~~ n8_2
   n9_1 ~~ n9_2
   n10_1 ~~ n10_2

   # Thresholds

   n1_1 + n1_2 | b11*t1+b12*t2+b13*t3
   n2_1 + n2_2 | b21*t1+b22*t2+b23*t3
   n3_1 + n3_2 | b31*t1+b32*t2+b33*t3
   n4_1 + n4_2 | b41*t1+b42*t2+b43*t3
   n5_1 + n5_2 | b51*t1+b52*t2+b53*t3
   n6_1 + n6_2 | b61*t1+b62*t2+b63*t3
   n7_1 + n7_2 | b71*t1+b72*t2+b73*t3
   n8_1 + n8_2 | b81*t1+b82*t2+b83*t3
   n9_1 + n9_2 | b91*t1+b92*t2+b93*t3
   n10_1 + n10_2 | b101*t1+b102*t2+b103*t3

   # Variances/covariances

   F1 ~~ 1*F1
   F2 ~~ NA*F2
   F1 ~~ NA*F2
   
  # Residual variances at follow-up are freely estimated (by the data)
  # Baseline residual variance is implicitly fixed to 1 – that’s why there is no Item_1 ~~ 1*Item_1 line in the code.

   n1_2 ~~ NA*n1_2
   n2_2 ~~ NA*n2_2
   n3_2 ~~ NA*n3_2
   n4_2 ~~ NA*n4_2
   n5_2 ~~ NA*n5_2
   n6_2 ~~ NA*n6_2
   n7_2 ~~ NA*n7_2
   n8_2 ~~ NA*n8_2
   n9_2 ~~ NA*n9_2
   n10_2 ~~ NA*n10_2

   # Means/intercepts

   F1 ~  0*1
   F2 ~ NA*1

   # Equal-but-opposite constrained factor loadings TR
   # remove this for psb assessment
   # f1 == -f2

   # b_param for trt (trt = transition rating)

   trat | thr.trt*t1
   psb := (f1/f2) +1
   b_param := thr.trt/f2
   '

# Preparing dataset for mic_lcfa in MIC-package
# ndi_data_lcfa <- ndi_data_trat |> 
#  select(!c(t1, t2, ndi_change, anchor)) |> 
#  filter(!is.na(trat))     # Removing NA's = the patients who got worse

# Estimating present-state bias (and other things) using the MIC-package
# Code is commented out to save time when rendering document

# set.seed(22082025)
# mic_ndi_lcfa <- mic_lcfa(mydat = ndi_data_lcfa, model = model_cfa, B = 30) ## should actually do > 50 bootstrap iterations! 
# saveRDS(mic_ndi_lcfa, "mic_ndi_lcfa.rds") 

mic_ndi_lcfa <- readRDS("mic_ndi_lcfa.rds")

glue("The present state bias is: {round(mic_ndi_lcfa$psb, 2)}")
The present state bias is: 0.48

Questions

3.4.1 Discuss what present-state bias is?

3.4.2 How do you interpret the present-state bias coefficient?

3.5 MIC using the ROC method

The first MIC value we calculate is the MIC based on the Receiver Characteristic Curve method (\(MIC_{ROC}\)). From the MIC-package we get the results presented in Table 3:

Code
# MIC ROC
ndi_mic_roc <- mic_roc(ndi_data_trat, x = "t1", y = "t2", tr = "trat")

# MIC ROC CI's
ndi_mic_roc_ci <- bootCImic(ndi_data_trat, mic = "roc", x = "t1",  y = "t2", tr = "trat") |> 
  select(
    lower = ".lower",
    upper = ".upper"
    )

# Tibble with important values
ndi_mic_roc_tbl <- tibble(
  method   = md("MIC ROC"),
  mic      = round(ndi_mic_roc, 2),
  ci_lower = round(ndi_mic_roc_ci$lower, 2),
  ci_upper = round(ndi_mic_roc_ci$upper, 2)
)

# Table 3
ndi_mic_roc_tbl |>
  gt() |>
  cols_merge(
    columns = c(ci_lower, ci_upper),
    pattern = "[{1}; {2}]"
  ) |> 
  tab_header(title = "Table 3. MIC using ROC method with CI's") |>
  cols_label(
    method   = "Method",
    mic      = md("MIC (points)"),
    ci_lower = "95% CI"
  ) |>
  fmt_number(columns = c(mic, ci_lower), decimals = 2) |>
  cols_align(align = "center", columns = everything())
Table 3. MIC using ROC method with CI's
Method MIC (points) 95% CI
MIC ROC −4.50 [−4.50; 1.5]

Question

3.5.1 Describe what the \(MIC_{ROC}\) value with CI’s mean

3.6 MIC using predictive modelling

Next we look at MIC using predictive modelling. To get an overview, we calculate the different predictive modelling values with CI’s:

  • Predictive modelling (PM)
  • Adjusted predictive modelling (APM)
  • Improved adjusted predictive modelling (IAPM)

These are presented in Table 4.

Code
# Removing rows if trat == NA (the patients who got worse)
ndi_data_trat_IAPM <- ndi_data_trat |> 
  filter(!is.na(trat))

# MIC using predictive modelling
set.seed(22082025)
ndi_mic_IAPM <- mic_iapm(mypred= "ndi_change", anchor = "trat", mydata= ndi_data_trat_IAPM, tr_rel = reliability$reliability, nboot = 1000)

# Generating CI's for pm, apm, iapm manually

# 1. Bootstrap resamples of ndi_data_trat_IAPM
set.seed(22082025)
boots <- rsample::bootstraps(ndi_data_trat_IAPM, times = 1000, apparent = TRUE)

# 2. Generating MIC function
mics_fnc <- possibly(
  function(split) {
    dat <- rsample::analysis(split)
    out <- mic_iapm(
      mypred = "ndi_change",
      anchor = "trat",
      mydata = dat,
      tr_rel = reliability$reliability,
      nboot  = 0
    )
    c(pm = out$mic_pm, apm = out$mic_apm, iapm = out$mic_iapm)
  },
  otherwise = c(pm = NA_real_, apm = NA_real_, iapm = NA_real_)
)

# 3. Run across resamples
mic_draws <- boots |>
  mutate(est = map(splits, mics_fnc)) |>
  tidyr::unnest_wider(est, names_sep = "_") 

# 4. 95% CIs 
ci_tbl <- tibble(
  method = c("mic_pm", "mic_apm", "mic_iapm"),
  lower  = c(
    quantile(mic_draws$est_pm,  0.025, na.rm = TRUE),
    quantile(mic_draws$est_apm, 0.025, na.rm = TRUE),
    quantile(mic_draws$est_iapm,0.025, na.rm = TRUE)
  ),
  upper  = c(
    quantile(mic_draws$est_pm,  0.975, na.rm = TRUE),
    quantile(mic_draws$est_apm, 0.975, na.rm = TRUE),
    quantile(mic_draws$est_iapm,0.975, na.rm = TRUE)
  )
)

# 5. MIC estimates from the full sample (from MIC-package)
mic_IAPM_estimates <- tibble(
  method   = c("mic_pm","mic_apm","mic_iapm"),
  estimate = c(ndi_mic_IAPM$mic_pm, ndi_mic_IAPM$mic_apm, ndi_mic_IAPM$mic_iapm)
)

# 6. Joining MIC estimates with CI's
mic_IAPM_estimates_ci <- dplyr::left_join(mic_IAPM_estimates, ci_tbl, by = "method")

# 7. Generating gt table 4 for display

table4 <- mic_IAPM_estimates_ci |>
  # use mutate(.keep = "none") to rebuild only the columns we want
  mutate(
    method = recode(method,
      mic_pm   = "MIC<sub>PM</sub>",
      mic_apm  = "MIC<sub>APM</sub>",
      mic_iapm = "MIC<sub>IAPM</sub>"
    ),
    estimate = estimate,  # keep estimate explicitly when .keep = "none"
    ci_lower = lower,     
    ci_upper = upper,
    .keep = "none"        # drop everything not created above
  ) |>
  gt() |>
  fmt_markdown(columns = method) |>                      # render <sub> tags
  fmt_number(columns = c(estimate, ci_lower, ci_upper),
             decimals = 2) |>
  cols_merge(                                            # merge CI as [lower; upper]
    columns = c(ci_lower, ci_upper),
    pattern = "[{1}; {2}]"
  ) |>
  cols_label(
    method   = "Method",
    estimate = "MIC (points)",
    ci_lower = "95% CI"
  ) |>
  cols_align(align = "center", columns = c(estimate, ci_lower)) |>
  tab_header(title = "Table 4. MIC estimates with bootstrap CIs") |>
  tab_options(heading.align = "left")

table4
Table 4. MIC estimates with bootstrap CIs
Method MIC (points) 95% CI
MICPM −3.43 [−4.94; −3.15]
MICAPM −3.92 [−4.81; −3.06]
MICIAPM −4.83 [−5.93; −3.85]

Questions

3.6.1 Discuss what you see in Table 4.

3.6.2 What do you think about the \(MIC_{ROC}\) compared to the \(MIC_{IAPM}\) ?

3.7 MIC using longitudinal confirmatory factor analysis (LCFA)

Lastly, we calculate the MIC using longitudinal confirmatory factor analysis. The result is presented in Table 5.

Code
lcfa_tbl <- tibble(
  method   = md("MIC<sub>LCFA</sub>"),
  mic      = round(mic_ndi_lcfa$MIC.ets, 2),
  ci_lower = round(mic_ndi_lcfa$MIC_CI["MIC.ets_boot", "Lower"], 2),
  ci_upper = round(mic_ndi_lcfa$MIC_CI["MIC.ets_boot", "Upper"], 2)
)

table5 <- gt(lcfa_tbl) |>
  tab_header(title = "Table 5. MIC-lcfa estimate with bootstrap CI") |>
  cols_merge(
    columns = c(ci_lower, ci_upper),
    pattern = "[{1}; {2}]"               # merge into CI format
  ) |>
  cols_label(
    method   = "Method",
    mic      = "MIC (points)",
    ci_lower = "95% CI"                  # after merge, this becomes the CI col
  ) |>
  fmt_markdown(columns = method) |>
  cols_align("center", c(mic, ci_lower)) |>
  tab_options(heading.align = "left")

table5
Table 5. MIC-lcfa estimate with bootstrap CI
Method MIC (points) 95% CI
MICLCFA -5.86 [-6.53; -4.83]

Question

3.7.1 Compare the results of Table 4 and Table 5 and discuss what you see.

To download the answers provided to this exercise you need to open the html-file with the answers - see instructions in that file.

You can download the two datasets below:

(right-click the link and choose ‘Save as’)

To import it into R use the code below. R-code is provided throughout the exercise:

Code
# Importing the 'ndi_synthetic_teaching.rds':

ndi_data <- readRDS("ndi_synthetic_teaching.rds") |> 
  select(-synthetic)

# Importing the ''ndi_synthetic_teaching.rds'mic_ndi_lcfa.rds':

mic_ndi_lcfa <- readRDS("mic_ndi_lcfa.rds")

The R libraries used are these:

Code
library(tidyverse)  # data wrangling (dplyr/tidyr), plotting (ggplot2), tibbles, helpers
library(glue)       # Working with strings
library(gt)         # nicely formatted tables in Quarto
library(here)       # For locating root folder
library(skimr)      # quick dataset overviews with skim()
library(summarytools) # Frequency tables for variables
library(MIC)        # For calculating MIC-values
library(lavaan)     # Used by MIC-package
library(polycor)    # Used for polyserial correlations
library(mirt)       # Multidimensional Item Response Theory
library(rsample)    # for resampling with bootstrap