// IQCL aggregate-only secondary analysis; no row-level output. // Fetch the versioned six-column public CSV: https://redivis.com/api/v1/tables/datapages.item_response_warehouse%3Av83_0.much_tte_2025_matrixreasoning/rows?format=csv&selectedVariables=id,item,resp,wave,treat,rt // Usage: node matrix-speed-analysis.mjs matrix.csv > results.json import fs from 'node:fs'; import { createHash } from 'node:crypto'; function analyze(raw){ const lines=raw.trim().split(/\r?\n/);const cols=lines.shift().split(",").map(x=>x.replace(/^"|"$/g,""));const idx=Object.fromEntries(cols.map((c,i)=>[c,i]));if(cols.join(",")!=="id,item,resp,wave,treat,rt"||raw.length>=1000000||lines.length!==24880)throw Error("unexpected input"); const people=new Map(),items=new Set(),keys=new Set(),blocks=new Map();let missing={resp:0,rt:0},scored=0; const nums=x=>x===""||x==="NA"||x==="NULL"||x==="null"?null:Number(x); for(const l of lines){const row=l.split(",").map(x=>x.replace(/^"|"$/g,""));if(row.length!==cols.length)throw Error("ragged CSV");const id=row[idx.id],it=row[idx.item],resp=nums(row[idx.resp]),t=nums(row[idx.treat]),w=nums(row[idx.wave]),rt=nums(row[idx.rt]);if(!id||!it||![0,1].includes(t)||![1,2].includes(w)||!(resp===null||[0,1].includes(resp)))throw Error("unexpected coding");const k=id+"\x00"+it;if(keys.has(k))throw Error("duplicate id/item");keys.add(k);items.add(it);if(blocks.has(it)&&blocks.get(it)!==w)throw Error("item crosses blocks");blocks.set(it,w);if(resp===null)missing.resp++;else scored++;if(rt===null||!Number.isFinite(rt)||rt<=0)missing.rt++;if(!people.has(id))people.set(id,{1:{t:null,resp:[],rt:[]},2:{t:null,resp:[],rt:[]}});const b=people.get(id)[w];if(b.t!==null&&b.t!==t)throw Error("mixed treatment");b.t=t;if(resp!==null)b.resp.push(resp);if(rt!==null&&Number.isFinite(rt)&&rt>0)b.rt.push(Math.log(rt))} if(people.size!==1244||items.size!==20||scored!==24737||[1,2].some(w=>[...blocks.values()].filter(x=>x===w).length!==10))throw Error("dimension check failed"); let seed=20261201;const rng=()=>{seed=(Math.imul(seed,1664525)+1013904223)>>>0;return seed/4294967296};const mean=a=>a.reduce((s,x)=>s+x,0)/a.length;const quant=(a,p)=>{const s=[...a].sort((a,b)=>a-b),k=(s.length-1)*p,i=Math.floor(k);return s[i]+(k-i)*(s[Math.min(i+1,s.length-1)]-s[i])};const bootMean=a=>{let s=0;for(let i=0;ia.length))<30)throw Error("too few paired participants");const point=(mean(seq[0])+mean(seq[1]))/2;const boot=Array.from({length:3000},()=> (bootMean(seq[0])+bootMean(seq[1]))/2);const f=metric==="resp"?x=>x*100:Math.exp;return {n:seq[0].length+seq[1].length,accuracy_first:seq[0].length,speed_first:seq[1].length,estimate:f(point),ci95:[f(quant(boot,.025)),f(quant(boot,.975))],sequence_estimates:seq.map(x=>f(mean(x))),observed_condition_levels:levels.map(a=>f(mean(a)))}} function firstBlock(metric){const g=[[],[]];for(const p of people.values()){if(p[1].t!==null&&p[1][metric].length)g[p[1].t].push(mean(p[1][metric]))}const b=Array.from({length:3000},()=>bootMean(g[1])-bootMean(g[0]));const f=metric==="resp"?x=>x*100:Math.exp;return {n:g.map(a=>a.length),estimate:f(mean(g[1])-mean(g[0])),ci95:[f(quant(b,.025)),f(quant(b,.975))],condition_levels:g.map(a=>f(mean(a)))}} return {rows:lines.length,scored,participants:people.size,items:items.size,missing,blocks:[1,2].map(w=>[...blocks.values()].filter(x=>x===w).length),paired_accuracy_available:paired("resp",false),paired_accuracy_complete:paired("resp",true),paired_rt_available:paired("rt",false),paired_rt_complete:paired("rt",true),first_block_accuracy:firstBlock("resp"),first_block_rt:firstBlock("rt"),bootstrap_replicates:3000,seed:20261201,rt_units:"source units; ratio unitless; no unit assumption"}; } const raw=fs.readFileSync(process.argv[2], 'utf8'); // Supplemental sensitivity checks: omitted scores counted as wrong; RT restricted to 1–300 source units. // Descriptive point estimates only; thresholds are exploratory, not pre-registered. const sensitivityPeople=new Map(); for(const line of raw.trim().split(/\r?\n/).slice(1)){ const [id,item,response,wave,treat,time]=line.split(",").map(x=>x.replace(/^"|"$/g,"")); const w=Number(wave),t=Number(treat),rt=Number(time); if(!sensitivityPeople.has(id))sensitivityPeople.set(id,[[],[]]); sensitivityPeople.get(id)[w-1].push({t,a:["","NA","NULL","null"].includes(response)?0:Number(response),rt}); } const avg=a=>a.reduce((s,v)=>s+v,0)/a.length; function sensitivity(kind){ const groups=[[],[]]; for(const blocks of sensitivityPeople.values()){ const vals=blocks.map(b=>kind==="wrong"?b.map(x=>x.a):b.filter(x=>x.rt>=1&&x.rt<=300).map(x=>Math.log(x.rt))); if(vals.some(v=>!v.length))continue; const t=blocks[0][0].t; groups[t].push((avg(vals[0])-avg(vals[1]))*(t===1?1:-1)); } const m=(avg(groups[0])+avg(groups[1]))/2; return {n:groups[0].length+groups[1].length,group_n:groups.map(a=>a.length),estimate:kind==="wrong"?100*m:Math.exp(m)}; } const sensitivityOutput={missing_as_wrong:sensitivity("wrong"),rt_1_to_300_source_units:sensitivity("rt")}; console.log(JSON.stringify({input_sha256:createHash('sha256').update(raw).digest('hex'),...analyze(raw),sensitivity:sensitivityOutput},null,2));