dart_irt 0.0.1
dart_irt: ^0.0.1 copied to clipboard
A pure Dart library for Item Response Theory (IRT). Implements Rasch (1PL), 2PL, 3PL dichotomous models, polytomous RSM/PCM, EM/MML estimation, CAT helpers, DIF analysis, person estimators (EAP, MLE, [...]
example/main.dart
import '../dart_irt.dart';
void main() {
// --- Rasch 1PL demo ---
final rasch = RaschEM();
final trueB = [-1.0, -0.3, 0.0, 0.4, 1.2];
final rawX = IrtSim.raschResponses(
persons: 400,
b: trueB,
missingRate: 0.05,
seed: 7,
);
// Filter out persons with all 0 or all 1 responses
final X = rawX.where((row) {
final vals = row.where((v) => v != null).map((v) => v!.toInt()).toList();
final hasZero = vals.contains(0);
final hasOne = vals.contains(1);
return hasZero && hasOne;
}).toList();
final res = rasch.fit(X);
print('📊 Rasch: iter=${res.iterations}, LL=${res.loglik.toStringAsFixed(3)}');
print('Estimated item b: ${res.b.map((e) => e.toStringAsFixed(2)).toList()}');
print('First 5 theta(EAP): ${res.thetaEap.take(5).map((e)=>e.toStringAsFixed(2)).toList()}');
// --- Basit 2PL kabuğu (şimdilik a=1.0) ---
final irt2 = IrtDichoEM(model: DichoModel.twoPL);
final dres = irt2.fit(X);
print('\n📊 2PL (simple): a=${dres.a.map((e)=>e.toStringAsFixed(2)).toList()}');
print('b=${dres.b.map((e)=>e.toStringAsFixed(2)).toList()}');
// --- DIF (MH) örneği ---
final group = List<int>.generate(X.length, (i) => i % 2);
final rawScore = List<int>.generate(
X.length,
(i) => X[i]
.where((v) => v != null && !(v is double && v.isNaN))
.fold<int>(0, (a, v) => a + (v!.toInt())),
);
final dif = DifTools.mantelHaenszel(
X: X,
group: group,
totalScore: rawScore,
itemIndex: 2,
);
print('\n📊 DIF (MH) item 2: '
'alpha=${dif.alphaMH.toStringAsFixed(3)}, '
'delta=${dif.deltaMH.toStringAsFixed(3)}, '
'chi2=${dif.chi2.toStringAsFixed(3)}, '
'p=${dif.p.toStringAsExponential(2)}');
}