{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreiea5ghwnhajrnu744cs3s42w5plfby5bjhytc7q5jgjbj2gpqbt7e",
"uri": "at://did:plc:wwyqal4cnqhuwyacdj7rqq3n/app.bsky.feed.post/3miego2vovot2"
},
"path": "/t/sample-size-calculation-for-paired-data-using-ordinal-models/28685#post_1",
"publishedAt": "2026-03-31T11:37:09.000Z",
"site": "https://discourse.datamethods.org",
"tags": [
"Ordinal Models for Paired Data – Statistical Thinking"
],
"textContent": "I came across this blog post by Prof. Harrell Ordinal Models for Paired Data – Statistical Thinking.\n\nI was trying to replicate the simulation in order to estimate the sample size for my paired study. Eveyrthing works perfectly and I am getting a reasonable sample size estimation. I just want to make sure that I am not missing any important details or doing anything wrong.\n\nHere is my code\n\n\n # Key metrics for the simulation (dummy data)\n\n before <- c(1.2,2.3,3.5,2.1,4.2,2.2,4.2,5.4,2.5,5.6,5.7,2.8,5.3,2.2,1.2)\n after <- c(4.2,2.3,3.5,2.1,2.2,2.2,5.2,5.4,2.5,5.1,5.4,2.2,5.3,2.2,4.2)\n delta_obs <- mean(before) - mean(after)\n sd_obs <- sd(before)\n rho_obs <- 0.5 # used the same rho used by prof. Harrell\n\n\n get_paired_power <- function(n, reps = 500) {\n p_values <- replicate(reps, {\n y1 <- rnorm(n, mean = 0, sd = sd_obs)\n y2 <- rnorm(n, mean = delta_obs + rho_obs * y1, sd = sqrt(1 - rho_obs^2) * sd_obs)\n y_sim <- c(y1, y2)\n x_sim <- c(rep(0, n), rep(1, n))\n id_sim <- factor(c(1:n, 1:n))\n\n f <- orm(y_sim ~ x_sim, x=TRUE, y=TRUE)\n g <- robcov(f, id_sim)\n\n anova(g)['x_sim', 'P']\n })\n mean(p_values < 0.05, na.rm = TRUE)\n }\n\n targets <- c(0.80) # here I am using 0.8 only\n results <- data.frame(Power_Target = targets, Required_Pairs = NA)\n\n current_n <- 140\n for (i in 1:length(targets)) {\n while (get_paired_power(current_n) < targets[i]) {\n current_n <- current_n + 10 # Incrementing pairs\n print(current_n)\n }\n results$Required_Pairs[i] <- current_n\n }\n\n print(results)\n",
"title": "Sample size calculation for Paired Data using ordinal models"
}