function iq_age_widget_shortcode() {
ob_start();
?>
<!– Adult IQ–Age Percentile Model (shortcode version, no ) –>

Adult IQ–Age Percentile Model (g₀ / 100)

This interactive graphic uses a custom functional g₀(n, x) to assign a scaled value
(shown as g₀/100) to IQ (n) at age (x), for
IQ 1–300 and ages 18–34.

Slice by age (18–34):

Slice by IQ (1–300):


https://cdn.plot.ly/plotly-2.32.0.min.js

// Namespace everything with ‘iqAge’ prefix to avoid clashes

function iqAge_g0(n, x) {
// n = IQ, x = age
if (x === 0 || x === 1) return NaN;
if (n <= 0) return NaN;

var M = 0.5 * (1 / n + 1 / (n * n)) + (n * n) / Math.sqrt(n);
var upper = Math.floor(M);
if (upper < 1) return 0;

var total = x * upper;
return total / (x * (x – 1));
}

function iqAge_rangeInt(start, end) {
var out = [];
for (var v = start; v <= end; v++) out.push(v);
return out;
}

var iqAge_iqVals = iqAge_rangeInt(1, 300);
var iqAge_ageVals = iqAge_rangeInt(18, 34);

var iqAge_Z = [];
for (var ai = 0; ai < iqAge_ageVals.length; ai++) {
var age = iqAge_ageVals[ai];
var row = [];
for (var ii = 0; ii = 0) ? iqAge_Z[idx] : iqAge_iqVals.map(function() { return NaN; });
return { x: iqAge_iqVals, y: yVals };
}

function iqAge_sliceByIQ(iq) {
var colIndex = iqAge_iqVals.indexOf(parseInt(iq));
var yVals = iqAge_ageVals.map(function(age, idx) {
if (colIndex < 0) return NaN;
return iqAge_Z[idx][colIndex];
});
return { x: iqAge_ageVals, y: yVals };
}

function iqAge_initSlices() {
var initAge = parseInt(iqAge_ageSelect.value);
var initIQ = parseInt(iqAge_iqSelect.value);

var ageSlice = iqAge_sliceByAge(initAge);
var iqSlice = iqAge_sliceByIQ(initIQ);

Plotly.newPlot('iq-age-ageSlice', [{
x: ageSlice.x,
y: ageSlice.y,
mode: 'lines'
}], {
margin: { t: 30, r: 10, b: 40, l: 50 },
xaxis: { title: 'IQ (n)' },
yaxis: { title: 'g₀(n, ' + initAge + ')/100' },
title: { text: 'Scaled g₀ vs IQ at age ' + initAge, x: 0.5 }
}, {responsive: true});

Plotly.newPlot('iq-age-iqSlice', [{
x: iqSlice.x,
y: iqSlice.y,
mode: 'lines'
}], {
margin: { t: 30, r: 10, b: 40, l: 50 },
xaxis: { title: 'Age (x)' },
yaxis: { title: 'g₀(' + initIQ + ', x)/100' },
title: { text: 'Scaled g₀ vs Age at IQ ' + initIQ, x: 0.5 }
}, {responsive: true});
}

iqAge_initSlices();

iqAge_ageSelect.addEventListener('change', function() {
var age = parseInt(iqAge_ageSelect.value);
var s = iqAge_sliceByAge(age);

Plotly.react('iq-age-ageSlice', [{
x: s.x,
y: s.y,
mode: 'lines'
}], {
margin: { t: 30, r: 10, b: 40, l: 50 },
xaxis: { title: 'IQ (n)' },
yaxis: { title: 'g₀(n, ' + age + ')/100' },
title: { text: 'Scaled g₀ vs IQ at age ' + age, x: 0.5 }
}, {responsive: true});
});

iqAge_iqSelect.addEventListener('change', function() {
var iq = parseInt(iqAge_iqSelect.value);
var s = iqAge_sliceByIQ(iq);

Plotly.react('iq-age-iqSlice', [{
x: s.x,
y: s.y,
mode: 'lines'
}], {
margin: { t: 30, r: 10, b: 40, l: 50 },
xaxis: { title: 'Age (x)' },
yaxis: { title: 'g₀(' + iq + ', x)/100' },
title: { text: 'Scaled g₀ vs Age at IQ ' + iq, x: 0.5 }
}, {responsive: true});
});

<?php
return ob_get_clean();
}
add_shortcode('iq_age_widget', 'iq_age_widget_shortcode');