according to Spearman Brown’s formula, 56 adolescents were excluded because they had incom plete data. what does spearman browns formula means?
Spearman Brown formula reliability psychometrics explanation
What is directed acyclic graph?
directed acyclic graph DAG explained with examples
| Term | Meaning |
|---|---|
| Directed | Every connection (edge) has a direction - it goes FROM one node TO another (like a one-way street) |
| Acyclic | There are no cycles - you can never follow the arrows and end up back where you started |
| Graph | A structure made of nodes (points) connected by edges (lines/arrows) |
A --> B --> D
| ^
v |
C ---------
Descriptive analyses were performed with estimates of absolute frequencies and percentages. The mean out comes between the groups were compared using the Stu dent’s t-test or Wilcoxon Test and one-way ANOVA or Kruskal–Wallis Test. Regarding the covariates of the study, a directed acy clic graph (DAG) was built from the literature review on the study theme, which shows the complex relationship between the different risk factors (Figs. 1, 2, and 3). DAG is a visual and qualitative tool for selecting confounding variables identified from a theoretical model. The arrow heads inform a path between two variables, and it is possible, through pre-established rules, to identify a min imum set of variables for adjustment. After application of DAG’s rules, the minimum adjustment set of variables for analysis of association between sleep duration and cardi ometabolic outcomes (blood pressure, dyslipidemia and glycemia) were: For the associations between sleep and diabetes, the following variables were selected: age, gen der, adolescent years of study, skin color, economic class, current work, alcohol consumption, smoking, physi cal activity, screen time, food consumption. For sleep and blood pressure, in turn, the variables selected were adjusted for: age, gender, adolescent years of study, skin color, economic class, current work, alcohol consump tion, smoking, physical activity, screen time, food con sumption, depression. In the association between sleep and dyslipidemias, the adjustment variables were: age, gender, adolescent years of study, skin color, economic class, current work, alcohol consumption, smoking, physical activity, screen time, food consumption. To analyze the relationship between sleep duration and cardiometabolic outcomes, a weighted by propensity score was used from the Inverse Probability of Treatment Weighting (IPTW). This study used the propensity score as a way to correct the imbalance in the distribution of predictors (covariate) that occur in observational studies, thus making the groups comparable and avoiding biased estimates of the effect of sleep duration and cardiometa bolic outcomes. The propensity score calculation was performed using the linear regression. The application of linear regression allowed the estimation of the selection probability of ado lescents, conditional on the values of covariates identified in the DAG (Figs. 1, 2 and 3). Checking the common support area and balancing the groups verified adequate propensity score estimation. A balance in the distribution of observed covariates was achieved, obtaining standardized differences between means and proportions less than 0.1 and for variances between 0.18–1.2. The effect of of sleep duration on car diometabolic outcomes was calculated using the beta coefficient with 95% confidence intervals (95% CI) for each cardiometabolic outcome considered in the analysis. No interaction was observed between sleep duration and gender concerning glycemia, blood pressure, and dyslipi demia outcomes evaluated by the gender/sleep duration ratio. Therefore, the sample was not stratified by gender. explain everything about this data analysis in a very understandable way.
| Test | When Used |
|---|---|
| Student's t-test | When data is normally distributed (bell-shaped curve) |
| Wilcoxon Test | When data is NOT normally distributed (skewed) |
| Test | When Used |
|---|---|
| One-way ANOVA | When data is normally distributed |
| Kruskal-Wallis Test | When data is NOT normally distributed |
Physical Activity --> Blood Pressure
^
|
Sleep Duration --> Blood Pressure
|
v
Food Consumption --> Blood Pressure
| Outcome | Variables Adjusted For |
|---|---|
| Sleep & Diabetes (Glycemia) | Age, gender, years of study, skin color, economic class, work status, alcohol, smoking, physical activity, screen time, food consumption |
| Sleep & Blood Pressure | All of the above + depression |
| Sleep & Dyslipidemia (Cholesterol) | Same as diabetes (without depression) |
Describe the sample (frequencies & %)
↓
Compare groups (t-test / ANOVA or non-parametric equivalents)
↓
Build DAG → identify confounders to control for
↓
Calculate propensity scores (linear regression)
↓
Apply IPTW → balance the groups
↓
Check balance (standardized differences < 0.1)
↓
Estimate effect (beta coefficient + 95% CI)
↓
Test for gender interaction → none found → analyze combined
Create a visual summary document explaining this statistical method
ls -la /home/daytona/workspace/ && mkdir -p /home/daytona/workspace/stats-summary
~/stats-summary/create_pptx.js
const pptxgen = require("pptxgenjs");
const pres = new pptxgen();
pres.layout = "LAYOUT_16x9";
pres.title = "Statistical Methods – Sleep & Cardiometabolic Health";
// ─── COLOR PALETTE ───────────────────────────────────────────────────────────
const C = {
navy: "0D1F3C", // dominant dark
teal: "1B7F8A", // primary accent
mint: "2EC4B6", // highlight
amber: "F4A300", // warm accent
light: "F0F4F8", // light bg
white: "FFFFFF",
gray: "6B7A8D",
lgray: "D6DDE8",
red: "E84855",
};
// ─── HELPERS ─────────────────────────────────────────────────────────────────
function headerBar(slide, title, subtitle) {
// dark header band
slide.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 1.15, fill: { color: C.navy } });
slide.addShape(pres.ShapeType.rect, { x: 0, y: 1.15, w: 10, h: 0.06, fill: { color: C.mint } });
slide.addText(title, { x: 0.35, y: 0.08, w: 7.5, h: 0.65, fontSize: 22, bold: true, color: C.white, fontFace: "Calibri", margin: 0 });
if (subtitle) slide.addText(subtitle, { x: 0.35, y: 0.72, w: 8, h: 0.38, fontSize: 11, color: C.mint, fontFace: "Calibri", margin: 0 });
}
function stepBox(slide, x, y, w, h, num, title, body, bg) {
slide.addShape(pres.ShapeType.roundRect, { x, y, w, h, fill: { color: bg || C.light }, line: { color: C.lgray, width: 1 }, rectRadius: 0.08 });
// number circle
slide.addShape(pres.ShapeType.ellipse, { x: x + 0.1, y: y + 0.1, w: 0.42, h: 0.42, fill: { color: C.teal } });
slide.addText(String(num), { x: x + 0.1, y: y + 0.1, w: 0.42, h: 0.42, fontSize: 13, bold: true, color: C.white, align: "center", valign: "middle", fontFace: "Calibri", margin: 0 });
slide.addText(title, { x: x + 0.6, y: y + 0.1, w: w - 0.7, h: 0.4, fontSize: 12, bold: true, color: C.navy, fontFace: "Calibri", margin: 0 });
slide.addText(body, { x: x + 0.15, y: y + 0.55, w: w - 0.25, h: h - 0.65, fontSize: 10, color: C.navy, fontFace: "Calibri", margin: 0, valign: "top" });
}
function arrowRight(slide, x, y) {
slide.addShape(pres.ShapeType.rightArrow, { x, y, w: 0.4, h: 0.3, fill: { color: C.teal } });
}
function arrowDown(slide, x, y) {
slide.addShape(pres.ShapeType.downArrow, { x, y, w: 0.3, h: 0.35, fill: { color: C.teal } });
}
// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 1 – TITLE
// ═══════════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.navy } });
// accent stripe
s.addShape(pres.ShapeType.rect, { x: 0, y: 2.7, w: 10, h: 0.07, fill: { color: C.mint } });
s.addShape(pres.ShapeType.rect, { x: 0, y: 2.77, w: 10, h: 0.03, fill: { color: C.amber } });
s.addText("Statistical Methods", { x: 0.6, y: 0.7, w: 8.8, h: 0.8, fontSize: 36, bold: true, color: C.white, fontFace: "Calibri", align: "center" });
s.addText("Sleep Duration & Cardiometabolic Outcomes in Adolescents", { x: 0.6, y: 1.55, w: 8.8, h: 0.6, fontSize: 18, color: C.mint, fontFace: "Calibri", align: "center" });
s.addText("A Visual Step-by-Step Summary", { x: 0.6, y: 2.2, w: 8.8, h: 0.4, fontSize: 13, color: C.lgray, fontFace: "Calibri", align: "center", italic: true });
// steps overview boxes
const steps = ["1. Describe", "2. Compare", "3. DAG", "4. Propensity Score", "5. IPTW", "6. Results"];
const bw = 1.42, bx0 = 0.3;
steps.forEach((t, i) => {
s.addShape(pres.ShapeType.roundRect, { x: bx0 + i * (bw + 0.07), y: 3.0, w: bw, h: 0.65, fill: { color: C.teal }, line: { color: C.mint, width: 1 }, rectRadius: 0.07 });
s.addText(t, { x: bx0 + i * (bw + 0.07), y: 3.0, w: bw, h: 0.65, fontSize: 10, bold: true, color: C.white, align: "center", valign: "middle", fontFace: "Calibri", margin: 0 });
});
s.addText("Study Goal: Does how long adolescents sleep affect their blood pressure, blood sugar, and cholesterol?", {
x: 0.6, y: 3.85, w: 8.8, h: 0.55, fontSize: 12, color: C.amber, fontFace: "Calibri", align: "center", italic: true, bold: true
});
s.addText("Each slide breaks down one analytical step — what it is, why it was done, and what it tells us.", {
x: 0.6, y: 4.45, w: 8.8, h: 0.4, fontSize: 10, color: C.lgray, fontFace: "Calibri", align: "center"
});
}
// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 2 – STEP 1: DESCRIPTIVE ANALYSIS
// ═══════════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.light } });
headerBar(s, "STEP 1 — Descriptive Analysis", "Getting to know the sample before any testing");
// left explanation
s.addShape(pres.ShapeType.roundRect, { x: 0.25, y: 1.4, w: 4.5, h: 3.8, fill: { color: C.white }, line: { color: C.lgray, width: 1 }, rectRadius: 0.1 });
s.addText("What is it?", { x: 0.4, y: 1.5, w: 4.2, h: 0.35, fontSize: 13, bold: true, color: C.teal, fontFace: "Calibri", margin: 0 });
s.addText([
{ text: "Before any complex statistics, researchers simply described who was in the study using:\n\n", options: {} },
{ text: "• Absolute Frequency:", options: { bold: true } },
{ text: " The raw count of people in each category\n (e.g., 120 had high blood pressure)\n\n", options: {} },
{ text: "• Percentage:", options: { bold: true } },
{ text: " That count as a proportion of the whole\n (e.g., 25% of the sample)\n\n", options: {} },
{ text: "Think of it like a class roll-call summary:\n\"30 students — 18 girls (60%), 12 boys (40%)\"", options: { italic: true, color: C.gray } },
], { x: 0.4, y: 1.9, w: 4.2, h: 3.1, fontSize: 10.5, color: C.navy, fontFace: "Calibri", valign: "top" });
// right: visual icons
s.addShape(pres.ShapeType.rect, { x: 5.1, y: 1.4, w: 4.6, h: 1.55, fill: { color: C.teal }, line: { color: C.teal }, rectRadius: 0.08 });
s.addText("ABSOLUTE FREQUENCY", { x: 5.2, y: 1.48, w: 4.4, h: 0.35, fontSize: 11, bold: true, color: C.white, fontFace: "Calibri", charSpacing: 2 });
s.addText("\"How many?\" → 120 adolescents had high BP", { x: 5.2, y: 1.85, w: 4.4, h: 0.35, fontSize: 11, color: C.mint, fontFace: "Calibri" });
s.addText("Raw count of people per group or category", { x: 5.2, y: 2.2, w: 4.4, h: 0.35, fontSize: 10, color: C.lgray, fontFace: "Calibri", italic: true });
s.addShape(pres.ShapeType.rect, { x: 5.1, y: 3.1, w: 4.6, h: 1.55, fill: { color: C.navy }, line: { color: C.navy }, rectRadius: 0.08 });
s.addText("PERCENTAGE (%)", { x: 5.2, y: 3.18, w: 4.4, h: 0.35, fontSize: 11, bold: true, color: C.white, fontFace: "Calibri", charSpacing: 2 });
s.addText("\"What proportion?\" → 25% of the sample", { x: 5.2, y: 3.55, w: 4.4, h: 0.35, fontSize: 11, color: C.amber, fontFace: "Calibri" });
s.addText("Puts the count in context relative to the whole group", { x: 5.2, y: 3.9, w: 4.4, h: 0.35, fontSize: 10, color: C.lgray, fontFace: "Calibri", italic: true });
s.addText("PURPOSE: Paint a clear picture of the sample's demographics before testing begins", {
x: 0.25, y: 5.1, w: 9.5, h: 0.38, fontSize: 10, color: C.gray, fontFace: "Calibri", italic: true, align: "center"
});
}
// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 3 – STEP 2: COMPARING GROUPS
// ═══════════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.light } });
headerBar(s, "STEP 2 — Comparing Group Means", "Choosing the right statistical test based on data distribution");
// decision question
s.addShape(pres.ShapeType.roundRect, { x: 3.2, y: 1.35, w: 3.6, h: 0.65, fill: { color: C.amber }, rectRadius: 0.08 });
s.addText("Is the data normally distributed?", { x: 3.2, y: 1.35, w: 3.6, h: 0.65, fontSize: 12, bold: true, color: C.navy, align: "center", valign: "middle", fontFace: "Calibri" });
// YES branch
s.addShape(pres.ShapeType.rect, { x: 0.15, y: 1.35, w: 0.7, h: 0.65, fill: { color: C.mint }, line: { color: C.mint } });
s.addText("YES", { x: 0.15, y: 1.35, w: 0.7, h: 0.65, fontSize: 13, bold: true, color: C.white, align: "center", valign: "middle", fontFace: "Calibri" });
// NO branch
s.addShape(pres.ShapeType.rect, { x: 9.15, y: 1.35, w: 0.7, h: 0.65, fill: { color: C.red }, line: { color: C.red } });
s.addText("NO", { x: 9.15, y: 1.35, w: 0.7, h: 0.65, fontSize: 13, bold: true, color: C.white, align: "center", valign: "middle", fontFace: "Calibri" });
// lines connecting
s.addShape(pres.ShapeType.line, { x: 0.85, y: 1.67, w: 2.35, h: 0, line: { color: C.mint, width: 2, dashType: "solid" } });
s.addShape(pres.ShapeType.line, { x: 6.8, y: 1.67, w: 2.35, h: 0, line: { color: C.red, width: 2, dashType: "solid" } });
// Parametric (YES) side
s.addShape(pres.ShapeType.roundRect, { x: 0.15, y: 2.2, w: 4.4, h: 1.3, fill: { color: C.mint }, rectRadius: 0.08 });
s.addText("PARAMETRIC TESTS", { x: 0.25, y: 2.26, w: 4.2, h: 0.35, fontSize: 11, bold: true, color: C.white, fontFace: "Calibri", charSpacing: 2 });
s.addText([
{ text: "2 groups: ", options: {} }, { text: "Student's t-test", options: { bold: true } }, { text: "\n", options: {} },
{ text: "3+ groups: ", options: {} }, { text: "One-Way ANOVA", options: { bold: true } }
], { x: 0.25, y: 2.62, w: 4.2, h: 0.75, fontSize: 11, color: C.white, fontFace: "Calibri" });
// Non-Parametric (NO) side
s.addShape(pres.ShapeType.roundRect, { x: 5.45, y: 2.2, w: 4.4, h: 1.3, fill: { color: C.red }, rectRadius: 0.08 });
s.addText("NON-PARAMETRIC TESTS", { x: 5.55, y: 2.26, w: 4.2, h: 0.35, fontSize: 11, bold: true, color: C.white, fontFace: "Calibri", charSpacing: 2 });
s.addText([
{ text: "2 groups: ", options: {} }, { text: "Wilcoxon Test", options: { bold: true } }, { text: "\n", options: {} },
{ text: "3+ groups: ", options: {} }, { text: "Kruskal-Wallis Test", options: { bold: true } }
], { x: 5.55, y: 2.62, w: 4.2, h: 0.75, fontSize: 11, color: C.white, fontFace: "Calibri" });
// analogy box
s.addShape(pres.ShapeType.roundRect, { x: 0.15, y: 3.7, w: 9.7, h: 1.6, fill: { color: C.white }, line: { color: C.lgray, width: 1 }, rectRadius: 0.08 });
s.addText("Why two sets of tests?", { x: 0.35, y: 3.78, w: 4, h: 0.35, fontSize: 12, bold: true, color: C.teal, fontFace: "Calibri", margin: 0 });
s.addText("Parametric tests assume a bell-shaped (normal) distribution. When data is skewed (bunched to one side), those assumptions break down and non-parametric alternatives are used instead. Both pairs ask the same question — \"Are the group means different?\" — but are suited to different data shapes. It's like choosing the right tool for the job.", {
x: 0.35, y: 4.15, w: 9.35, h: 0.95, fontSize: 10.5, color: C.navy, fontFace: "Calibri", valign: "top"
});
}
// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 4 – STEP 3: DAG
// ═══════════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.light } });
headerBar(s, "STEP 3 — Directed Acyclic Graph (DAG)", "A causal map to identify which variables need to be controlled for");
// left: what & why
s.addShape(pres.ShapeType.roundRect, { x: 0.2, y: 1.35, w: 4.2, h: 3.9, fill: { color: C.white }, line: { color: C.lgray, width: 1 }, rectRadius: 0.1 });
s.addText("What is a DAG?", { x: 0.35, y: 1.45, w: 3.9, h: 0.35, fontSize: 13, bold: true, color: C.teal, fontFace: "Calibri", margin: 0 });
s.addText([
{ text: "A DAG is a diagram where:\n\n", options: {} },
{ text: "• Nodes", options: { bold: true } },
{ text: " = variables (sleep, age, diet…)\n\n", options: {} },
{ text: "• Arrows", options: { bold: true } },
{ text: " = assumed causal direction\n\n", options: {} },
{ text: "• No loops", options: { bold: true } },
{ text: " — arrows never circle back\n\n", options: {} },
{ text: "By following DAG rules, researchers identify the ", options: {} },
{ text: "minimum set of variables", options: { bold: true, color: C.teal } },
{ text: " to adjust for — not too few (bias), not too many (over-control).", options: {} },
], { x: 0.35, y: 1.85, w: 3.9, h: 3.2, fontSize: 10.5, color: C.navy, fontFace: "Calibri", valign: "top" });
// right: mini DAG diagram
s.addShape(pres.ShapeType.roundRect, { x: 4.65, y: 1.35, w: 5.1, h: 2.6, fill: { color: C.navy }, rectRadius: 0.1 });
s.addText("Example Causal Pathway", { x: 4.75, y: 1.42, w: 4.9, h: 0.35, fontSize: 11, bold: true, color: C.mint, fontFace: "Calibri" });
// nodes
const nodes = [
{ label: "Physical\nActivity", x: 4.85, y: 1.95, w: 1.2, h: 0.6, col: C.teal },
{ label: "Sleep\nDuration", x: 6.4, y: 2.4, w: 1.2, h: 0.6, col: C.amber },
{ label: "Blood\nPressure", x: 7.95, y: 1.95, w: 1.2, h: 0.6, col: C.red },
{ label: "Diet /\nFood", x: 4.85, y: 2.85, w: 1.2, h: 0.6, col: C.teal },
];
nodes.forEach(n => {
s.addShape(pres.ShapeType.roundRect, { x: n.x, y: n.y, w: n.w, h: n.h, fill: { color: n.col }, rectRadius: 0.07 });
s.addText(n.label, { x: n.x, y: n.y, w: n.w, h: n.h, fontSize: 9, bold: true, color: C.white, align: "center", valign: "middle", fontFace: "Calibri", margin: 0 });
});
// arrows (lines)
s.addShape(pres.ShapeType.line, { x: 6.05, y: 2.25, w: 1.9, h: -0.05, line: { color: C.mint, width: 1.5 } });
s.addShape(pres.ShapeType.line, { x: 6.05, y: 3.15, w: 1.9, h: -0.95, line: { color: C.mint, width: 1.5 } });
s.addShape(pres.ShapeType.line, { x: 5.45, y: 1.95, w: 0.95, h: 0.45, line: { color: C.lgray, width: 1, dashType: "dash" } });
// adjustment sets table
s.addShape(pres.ShapeType.roundRect, { x: 4.65, y: 4.1, w: 5.1, h: 1.2, fill: { color: C.white }, line: { color: C.lgray, width: 1 }, rectRadius: 0.08 });
s.addText("Minimum Adjustment Sets Identified:", { x: 4.8, y: 4.16, w: 4.8, h: 0.3, fontSize: 10, bold: true, color: C.navy, fontFace: "Calibri", margin: 0 });
s.addText([
{ text: "Sleep & Diabetes / Dyslipidemia: ", options: { bold: true } },
{ text: "age, gender, education, skin color, income, work, alcohol, smoking, physical activity, screen time, diet\n", options: {} },
{ text: "Sleep & Blood Pressure: ", options: { bold: true } },
{ text: "All above + depression", options: { color: C.red } },
], { x: 4.8, y: 4.5, w: 4.85, h: 0.72, fontSize: 9.5, color: C.navy, fontFace: "Calibri", valign: "top" });
}
// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 5 – STEP 4: PROPENSITY SCORE
// ═══════════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.light } });
headerBar(s, "STEP 4 — Propensity Score", "Estimating each participant's probability of being a short sleeper");
// problem box
s.addShape(pres.ShapeType.roundRect, { x: 0.2, y: 1.35, w: 9.6, h: 1.1, fill: { color: C.red }, rectRadius: 0.08 });
s.addText("THE PROBLEM IN OBSERVATIONAL STUDIES", { x: 0.35, y: 1.4, w: 5, h: 0.3, fontSize: 10, bold: true, color: C.white, fontFace: "Calibri", charSpacing: 1 });
s.addText("Unlike clinical trials, researchers didn't randomly assign sleep durations. Short sleepers may naturally differ from normal sleepers in many ways (poorer, more stressed, less active) — creating an unfair, biased comparison.", {
x: 0.35, y: 1.72, w: 9.3, h: 0.55, fontSize: 10.5, color: C.white, fontFace: "Calibri"
});
// solution
s.addText("THE SOLUTION: Propensity Score", { x: 0.25, y: 2.6, w: 9.5, h: 0.35, fontSize: 13, bold: true, color: C.teal, fontFace: "Calibri" });
// three boxes
const boxes = [
{ x: 0.2, label: "1. Collect Covariates", body: "Gather all background variables identified by the DAG (age, income, physical activity, diet, etc.)" },
{ x: 3.45, label: "2. Run Linear Regression", body: "Feed all covariates into a linear regression model to calculate each person's probability of being a short sleeper" },
{ x: 6.7, label: "3. Propensity Score", body: "One number per participant: the estimated probability (0–1) of being a short sleeper given their profile" },
];
boxes.forEach(b => {
s.addShape(pres.ShapeType.roundRect, { x: b.x, y: 3.05, w: 3.1, h: 1.8, fill: { color: C.white }, line: { color: C.teal, width: 1.5 }, rectRadius: 0.08 });
s.addText(b.label, { x: b.x + 0.12, y: 3.12, w: 2.86, h: 0.4, fontSize: 11, bold: true, color: C.teal, fontFace: "Calibri", margin: 0 });
s.addText(b.body, { x: b.x + 0.12, y: 3.55, w: 2.86, h: 1.2, fontSize: 10, color: C.navy, fontFace: "Calibri", valign: "top" });
});
// arrows between boxes
arrowRight(s, 3.3, 3.85);
arrowRight(s, 6.55, 3.85);
s.addText("Analogy: Two students with identical backgrounds — same grades, habits, and family income. One studies 8h, the other 4h. The propensity score makes these two comparable, because their profiles are virtually the same.", {
x: 0.2, y: 5.08, w: 9.6, h: 0.42, fontSize: 10, color: C.gray, fontFace: "Calibri", italic: true, align: "center"
});
}
// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 6 – STEP 5: IPTW
// ═══════════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.light } });
headerBar(s, "STEP 5 — IPTW: Inverse Probability of Treatment Weighting", "Re-balancing groups to simulate a randomized trial");
s.addText("What is IPTW?", { x: 0.25, y: 1.38, w: 9.5, h: 0.38, fontSize: 14, bold: true, color: C.navy, fontFace: "Calibri" });
s.addText("Once propensity scores are calculated, IPTW uses them as weights to mathematically balance the groups — making short sleepers and normal sleepers similar in background characteristics.", {
x: 0.25, y: 1.78, w: 9.5, h: 0.5, fontSize: 11, color: C.navy, fontFace: "Calibri"
});
// weighting diagram
const wboxes = [
{ x: 0.2, bg: C.teal, title: "SHORT SLEEPER\nHigh Probability", body: "Expected to be short sleeper\n→ LOW weight\n(common, less informative)", w_label: "Weight: LOW", wc: C.amber },
{ x: 3.45, bg: C.navy, title: "SHORT SLEEPER\nLow Probability", body: "NOT expected to be short sleeper, but is\n→ HIGH weight\n(unusual, highly informative)", w_label: "Weight: HIGH", wc: C.mint },
{ x: 6.7, bg: C.red, title: "RESULT", body: "Groups become statistically equivalent in background — like a randomised trial", w_label: "Balanced Groups ✓", wc: C.white },
];
wboxes.forEach(b => {
s.addShape(pres.ShapeType.roundRect, { x: b.x, y: 2.45, w: 3.1, h: 2.0, fill: { color: b.bg }, rectRadius: 0.08 });
s.addText(b.title, { x: b.x + 0.1, y: 2.52, w: 2.9, h: 0.55, fontSize: 10, bold: true, color: C.white, fontFace: "Calibri", align: "center", valign: "middle" });
s.addText(b.body, { x: b.x + 0.1, y: 3.1, w: 2.9, h: 0.9, fontSize: 10, color: C.lgray, fontFace: "Calibri", align: "center" });
s.addText(b.w_label, { x: b.x + 0.1, y: 4.05, w: 2.9, h: 0.3, fontSize: 11, bold: true, color: b.wc, fontFace: "Calibri", align: "center" });
});
arrowRight(s, 3.3, 3.35);
arrowRight(s, 6.55, 3.35);
// balance check
s.addShape(pres.ShapeType.roundRect, { x: 0.2, y: 4.56, w: 9.6, h: 0.88, fill: { color: C.white }, line: { color: C.mint, width: 1.5 }, rectRadius: 0.08 });
s.addText([
{ text: "Balance Check Passed: ", options: { bold: true, color: C.teal } },
{ text: "Standardized differences < 0.1 ", options: {} },
{ text: "✓ ", options: { bold: true, color: C.mint } },
{ text: " | Variance ratios 0.18–1.2 ", options: {} },
{ text: "✓", options: { bold: true, color: C.mint } },
], { x: 0.35, y: 4.62, w: 9.3, h: 0.38, fontSize: 11, color: C.navy, fontFace: "Calibri", align: "center" });
s.addText("Both metrics confirm that groups are now equivalent in background characteristics — the weighting worked.", {
x: 0.35, y: 5.0, w: 9.3, h: 0.3, fontSize: 9.5, color: C.gray, fontFace: "Calibri", align: "center", italic: true
});
}
// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 7 – STEP 6: RESULTS & GENDER INTERACTION
// ═══════════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.light } });
headerBar(s, "STEP 6 — Effect Estimation & Gender Interaction Test", "Measuring the impact of sleep and checking if gender changes the story");
// beta coefficient box
s.addShape(pres.ShapeType.roundRect, { x: 0.2, y: 1.38, w: 4.6, h: 2.5, fill: { color: C.navy }, rectRadius: 0.1 });
s.addText("Beta Coefficient (β)", { x: 0.35, y: 1.48, w: 4.3, h: 0.38, fontSize: 13, bold: true, color: C.mint, fontFace: "Calibri", margin: 0 });
s.addText([
{ text: "Measures how much a cardiometabolic outcome changes for each unit change in sleep duration, after balancing.\n\n", options: {} },
{ text: "Example: ", options: { bold: true, color: C.amber } },
{ text: "β = −2.3 mmHg means each extra hour of sleep is associated with a 2.3 mmHg drop in systolic blood pressure.\n\n", options: {} },
{ text: "If β = 0, there is no association.", options: { italic: true, color: C.lgray } },
], { x: 0.35, y: 1.9, w: 4.3, h: 1.85, fontSize: 10.5, color: C.white, fontFace: "Calibri", valign: "top" });
// 95% CI box
s.addShape(pres.ShapeType.roundRect, { x: 5.2, y: 1.38, w: 4.6, h: 2.5, fill: { color: C.teal }, rectRadius: 0.1 });
s.addText("95% Confidence Interval (CI)", { x: 5.35, y: 1.48, w: 4.3, h: 0.38, fontSize: 13, bold: true, color: C.white, fontFace: "Calibri", margin: 0 });
s.addText([
{ text: "The range where the true effect likely falls, 95% of the time.\n\n", options: {} },
{ text: "Significant: ", options: { bold: true, color: C.amber } },
{ text: "CI does NOT include zero\n e.g., β = −2.3 [−4.1, −0.5] ✓\n\n", options: {} },
{ text: "Not Significant: ", options: { bold: true, color: C.lgray } },
{ text: "CI crosses zero\n e.g., β = −0.5 [−2.1, 1.1] ✗", options: {} },
], { x: 5.35, y: 1.9, w: 4.3, h: 1.85, fontSize: 10.5, color: C.white, fontFace: "Calibri", valign: "top" });
// gender interaction
s.addShape(pres.ShapeType.roundRect, { x: 0.2, y: 4.05, w: 9.6, h: 1.35, fill: { color: C.white }, line: { color: C.amber, width: 1.5 }, rectRadius: 0.08 });
s.addText("Gender Interaction Test — Result: NO Interaction Found", { x: 0.35, y: 4.1, w: 6, h: 0.38, fontSize: 12, bold: true, color: C.amber, fontFace: "Calibri", margin: 0 });
s.addText("Researchers tested whether the effect of sleep on outcomes differed between boys and girls (gender × sleep interaction). No significant difference was found — sleep affected blood pressure, blood sugar, and cholesterol similarly in both sexes. Therefore, the sample was NOT split by gender, and boys and girls were analysed together.", {
x: 0.35, y: 4.5, w: 9.3, h: 0.78, fontSize: 10.5, color: C.navy, fontFace: "Calibri"
});
}
// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 8 – FULL PIPELINE SUMMARY
// ═══════════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.navy } });
s.addShape(pres.ShapeType.rect, { x: 0, y: 1.1, w: 10, h: 0.05, fill: { color: C.mint } });
s.addText("THE FULL ANALYTICAL PIPELINE", { x: 0.3, y: 0.12, w: 9.4, h: 0.55, fontSize: 20, bold: true, color: C.white, fontFace: "Calibri", align: "center", charSpacing: 3 });
s.addText("Sleep Duration → Cardiometabolic Outcomes in Adolescents", { x: 0.3, y: 0.65, w: 9.4, h: 0.35, fontSize: 11, color: C.mint, fontFace: "Calibri", align: "center", italic: true });
const pipeline = [
{ n: "1", title: "DESCRIBE", sub: "Frequencies & %", col: C.teal },
{ n: "2", title: "COMPARE", sub: "t-test / ANOVA\nWilcoxon / Kruskal-Wallis", col: "#1B7F8A" },
{ n: "3", title: "DAG", sub: "Select confounders\nvia causal map", col: "#156C76" },
{ n: "4", title: "PROPENSITY\nSCORE", sub: "Linear regression\nper participant", col: "#0F5A62" },
{ n: "5", title: "IPTW", sub: "Balance groups\nwith weights", col: "#094750" },
{ n: "6", title: "RESULTS", sub: "β coefficient\n+ 95% CI", col: C.amber },
];
pipeline.forEach((p, i) => {
const bx = 0.22 + i * 1.62;
s.addShape(pres.ShapeType.roundRect, { x: bx, y: 1.35, w: 1.45, h: 3.5, fill: { color: p.col }, rectRadius: 0.1 });
s.addShape(pres.ShapeType.ellipse, { x: bx + 0.5, y: 1.48, w: 0.45, h: 0.45, fill: { color: C.white } });
s.addText(p.n, { x: bx + 0.5, y: 1.48, w: 0.45, h: 0.45, fontSize: 14, bold: true, color: p.col, align: "center", valign: "middle", fontFace: "Calibri", margin: 0 });
s.addText(p.title, { x: bx + 0.05, y: 2.05, w: 1.35, h: 0.7, fontSize: 10, bold: true, color: C.white, align: "center", valign: "middle", fontFace: "Calibri", margin: 0 });
s.addText(p.sub, { x: bx + 0.05, y: 2.8, w: 1.35, h: 1.8, fontSize: 9, color: C.lgray, align: "center", valign: "top", fontFace: "Calibri", margin: 0 });
});
s.addText("GOAL: Determine whether sleep duration causally affects cardiometabolic health — controlling for confounders and balancing groups to avoid biased conclusions.", {
x: 0.25, y: 5.05, w: 9.5, h: 0.48, fontSize: 10.5, color: C.lgray, fontFace: "Calibri", align: "center", italic: true
});
}
// ─── WRITE FILE ──────────────────────────────────────────────────────────────
pres.writeFile({ fileName: "/home/daytona/workspace/stats-summary/Statistical_Methods_Sleep_Study.pptx" })
.then(() => console.log("DONE: /home/daytona/workspace/stats-summary/Statistical_Methods_Sleep_Study.pptx"))
.catch(e => { console.error(e); process.exit(1); });
node /home/daytona/workspace/stats-summary/create_pptx.js
Statistical Methods Sleep Study
Presentation · PPTX
| Slide | Content |
|---|---|
| 1 - Title | Overview of the study goal and all 6 steps at a glance |
| 2 - Step 1 | Descriptive Analysis - frequencies and percentages explained |
| 3 - Step 2 | Group Comparison tests - visual decision tree (parametric vs. non-parametric) |
| 4 - Step 3 | DAG - causal map diagram with minimum adjustment sets listed |
| 5 - Step 4 | Propensity Score - the problem + 3-step solution flow |
| 6 - Step 5 | IPTW - weighting logic with balance check results |
| 7 - Step 6 | Beta coefficient, 95% CI, and gender interaction test |
| 8 - Summary | Full pipeline visual from start to finish |
can you not create a single slide?
~/stats-summary/create_single_slide.js
const pptxgen = require("pptxgenjs");
const pres = new pptxgen();
pres.layout = "LAYOUT_WIDE"; // 13.3" x 7.5" — more room for content
const C = {
navy: "0D1F3C",
teal: "1B7F8A",
mint: "2EC4B6",
amber: "F4A300",
light: "F0F4F8",
white: "FFFFFF",
gray: "6B7A8D",
lgray: "D6DDE8",
red: "C0392B",
};
const s = pres.addSlide();
// ── BACKGROUND ────────────────────────────────────────────────────────────────
s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 13.3, h: 7.5, fill: { color: C.navy } });
// ── TOP HEADER ────────────────────────────────────────────────────────────────
s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 13.3, h: 0.9, fill: { color: C.teal } });
s.addShape(pres.ShapeType.rect, { x: 0, y: 0.9, w: 13.3, h: 0.06, fill: { color: C.mint } });
s.addText("Statistical Methods: Sleep Duration & Cardiometabolic Outcomes in Adolescents", {
x: 0.2, y: 0.08, w: 9.5, h: 0.72, fontSize: 18, bold: true, color: C.white, fontFace: "Calibri", valign: "middle", margin: 0
});
s.addText("Study Goal: Does sleep duration affect blood pressure, blood sugar & cholesterol?", {
x: 9.8, y: 0.08, w: 3.3, h: 0.72, fontSize: 9.5, color: C.mint, fontFace: "Calibri", italic: true, valign: "middle", align: "right", margin: 0
});
// ── HELPER: step card ─────────────────────────────────────────────────────────
function card(x, y, w, h, num, title, titleColor, bg, lines) {
s.addShape(pres.ShapeType.roundRect, { x, y, w, h, fill: { color: bg }, rectRadius: 0.08 });
// number pill
s.addShape(pres.ShapeType.roundRect, { x: x + 0.1, y: y + 0.1, w: 0.38, h: 0.32, fill: { color: C.navy }, rectRadius: 0.05 });
s.addText(num, { x: x + 0.1, y: y + 0.1, w: 0.38, h: 0.32, fontSize: 10, bold: true, color: C.mint, align: "center", valign: "middle", fontFace: "Calibri", margin: 0 });
// title
s.addText(title, { x: x + 0.55, y: y + 0.1, w: w - 0.65, h: 0.32, fontSize: 11, bold: true, color: titleColor, fontFace: "Calibri", margin: 0, valign: "middle" });
// body lines
s.addText(lines, { x: x + 0.12, y: y + 0.48, w: w - 0.22, h: h - 0.58, fontSize: 9.5, color: C.navy, fontFace: "Calibri", valign: "top", margin: 0 });
}
// ── HELPER: connector arrow ───────────────────────────────────────────────────
function arrowR(x, y) {
s.addShape(pres.ShapeType.rightArrow, { x, y, w: 0.28, h: 0.22, fill: { color: C.mint } });
}
function arrowD(x, y) {
s.addShape(pres.ShapeType.downArrow, { x, y, w: 0.22, h: 0.28, fill: { color: C.amber } });
}
// ═══════════════════════════════════════════════════════════════
// ROW 1 — Steps 1, 2, 3 (top row)
// ═══════════════════════════════════════════════════════════════
const ROW1_Y = 1.08;
const ROW2_Y = 4.2;
const CW = 3.8; // card width
const CH = 2.85; // card height
const GAP = 0.37;
const X1 = 0.18, X2 = X1 + CW + GAP + 0.28, X3 = X2 + CW + GAP + 0.28;
// STEP 1 – DESCRIPTIVE
card(X1, ROW1_Y, CW, CH, "01", "Descriptive Analysis", C.amber, C.light, [
{ text: "Purpose: ", options: { bold: true } },
{ text: "Summarise who is in the sample before any testing.\n\n", options: {} },
{ text: "Absolute Frequency", options: { bold: true } },
{ text: " — raw count per category\n e.g. 120 adolescents had high blood pressure\n\n", options: {} },
{ text: "Percentage (%)", options: { bold: true } },
{ text: " — count as proportion of whole\n e.g. 25% of the sample\n\n", options: {} },
{ text: "Gives a clear demographic picture of the study population.", options: { italic: true, color: C.gray } },
]);
arrowR(X1 + CW + 0.04, ROW1_Y + CH / 2 - 0.11);
// STEP 2 – GROUP COMPARISON
card(X2, ROW1_Y, CW, CH, "02", "Group Comparison Tests", C.amber, C.light, [
{ text: "Compares mean outcomes between sleep groups.\n\n", options: {} },
{ text: "Normal data", options: { bold: true, color: C.teal } },
{ text: " (bell-shaped):\n", options: {} },
{ text: " 2 groups → Student's t-test\n 3+ groups → One-Way ANOVA\n\n", options: {} },
{ text: "Skewed data", options: { bold: true, color: C.red } },
{ text: " (non-normal):\n", options: {} },
{ text: " 2 groups → Wilcoxon Test\n 3+ groups → Kruskal-Wallis Test\n\n", options: {} },
{ text: "Both sets ask the same question — just suited to different data shapes.", options: { italic: true, color: C.gray } },
]);
arrowR(X2 + CW + 0.04, ROW1_Y + CH / 2 - 0.11);
// STEP 3 – DAG
card(X3, ROW1_Y, CW, CH, "03", "Directed Acyclic Graph (DAG)", C.amber, C.light, [
{ text: "A causal diagram built from literature to identify confounders.\n\n", options: {} },
{ text: "Nodes", options: { bold: true } },
{ text: " = variables | ", options: {} },
{ text: "Arrows", options: { bold: true } },
{ text: " = causal direction | ", options: {} },
{ text: "No loops\n\n", options: { bold: true } },
{ text: "Minimum adjustment sets selected:\n", options: {} },
{ text: " Sleep & Diabetes/Dyslipidemia:", options: { bold: true } },
{ text: " age, gender, education, skin color, income, work, alcohol, smoking, physical activity, screen time, diet\n", options: {} },
{ text: " Sleep & Blood Pressure:", options: { bold: true } },
{ text: " all above + ", options: {} },
{ text: "depression", options: { bold: true, color: C.red } },
]);
// ═══════════════════════════════════════════════════════════════
// DOWN ARROW between rows
// ═══════════════════════════════════════════════════════════════
arrowD(X3 + CW / 2 - 0.11, ROW1_Y + CH + 0.05);
// ═══════════════════════════════════════════════════════════════
// ROW 2 — Steps 4, 5, 6 (bottom row, reversed right-to-left flow)
// ═══════════════════════════════════════════════════════════════
const CH2 = 2.85;
// STEP 6 – RESULTS (right bottom — flow ends here)
card(X3, ROW2_Y, CW, CH2, "06", "Effect Estimation & Gender Test", C.mint, "1B3A5C", [
{ text: "Beta Coefficient (β):", options: { bold: true, color: C.mint } },
{ text: " Change in outcome per unit change in sleep\n e.g. β = −2.3 mmHg drop per extra hour of sleep\n\n", options: { color: C.lgray } },
{ text: "95% Confidence Interval:", options: { bold: true, color: C.mint } },
{ text: " Significant if CI does NOT cross zero\n ✓ [−4.1, −0.5] vs ✗ [−2.1, 1.1]\n\n", options: { color: C.lgray } },
{ text: "Gender Interaction Test:", options: { bold: true, color: C.amber } },
{ text: " No interaction found → sleep affects boys & girls equally → sample NOT split by gender.", options: { color: C.lgray } },
]);
// left arrow pointing TO step 6 (from step 5)
arrowR(X2 + CW + 0.04, ROW2_Y + CH2 / 2 - 0.11);
// STEP 5 – IPTW
card(X2, ROW2_Y, CW, CH2, "05", "IPTW — Inverse Probability Weighting", C.mint, "1B3A5C", [
{ text: "Uses propensity scores as weights to re-balance groups — simulating a randomised trial.\n\n", options: { color: C.lgray } },
{ text: "Short sleeper, expected → ", options: { color: C.lgray } },
{ text: "LOW weight\n", options: { bold: true, color: C.amber } },
{ text: "Short sleeper, NOT expected → ", options: { color: C.lgray } },
{ text: "HIGH weight\n\n", options: { bold: true, color: C.mint } },
{ text: "Balance verified:\n", options: { bold: true, color: C.mint } },
{ text: " Standardized differences < 0.1 ✓\n Variance ratios 0.18–1.2 ✓\n\n", options: { color: C.lgray } },
{ text: "Groups are now statistically equivalent in background.", options: { italic: true, color: C.gray } },
]);
arrowR(X1 + CW + 0.04, ROW2_Y + CH2 / 2 - 0.11);
// STEP 4 – PROPENSITY SCORE
card(X1, ROW2_Y, CW, CH2, "04", "Propensity Score (Linear Regression)", C.mint, "1B3A5C", [
{ text: "Problem:", options: { bold: true, color: C.red } },
{ text: " Observational study — groups are NOT randomly assigned, so short sleepers may differ systematically from normal sleepers.\n\n", options: { color: C.lgray } },
{ text: "Solution:", options: { bold: true, color: C.mint } },
{ text: " Calculate each participant's probability of being a short sleeper, given their covariates (from the DAG).\n\n", options: { color: C.lgray } },
{ text: "Method:", options: { bold: true, color: C.amber } },
{ text: " Linear regression → one propensity score per person → used as weight in IPTW.", options: { color: C.lgray } },
]);
// ── FLOW LABEL ────────────────────────────────────────────────────────────────
s.addText("→ STEP 4 → STEP 5 → STEP 6", {
x: X1, y: ROW2_Y - 0.3, w: X3 + CW - X1, h: 0.26,
fontSize: 9, color: C.mint, fontFace: "Calibri", align: "center", italic: true
});
s.addText("STEP 1 → STEP 2 → STEP 3 ↓", {
x: X1, y: ROW1_Y - 0.22, w: X3 + CW - X1, h: 0.2,
fontSize: 9, color: C.amber, fontFace: "Calibri", align: "center", italic: true
});
// ── BOTTOM FOOTER ─────────────────────────────────────────────────────────────
s.addShape(pres.ShapeType.rect, { x: 0, y: 7.32, w: 13.3, h: 0.18, fill: { color: C.teal } });
s.addText("Descriptive → Group Tests → DAG (Confounder Selection) → Propensity Score → IPTW Balancing → β Coefficient + 95% CI", {
x: 0.2, y: 7.33, w: 12.9, h: 0.15, fontSize: 8, color: C.white, fontFace: "Calibri", align: "center"
});
// ── WRITE ─────────────────────────────────────────────────────────────────────
pres.writeFile({ fileName: "/home/daytona/workspace/stats-summary/Statistical_Methods_Single_Slide.pptx" })
.then(() => console.log("DONE"))
.catch(e => { console.error(e); process.exit(1); });
node /home/daytona/workspace/stats-summary/create_single_slide.js
Statistical Methods Single Slide
Presentation · PPTX
[ Step 1: Describe ] → [ Step 2: Compare ] → [ Step 3: DAG ]
↓
[ Step 4: Propensity ] → [ Step 5: IPTW ] → [ Step 6: Results ]