MAP推定法 | 項目応答理論
2022年10年7日
項目応答理論
MAP推定法
PHP

Rによる項目応答理論 p166 MAP推定法を、PHPで書き直してみようという試みです。
MAPEstimation.php
class MAPEstimation{
public function icc2PL(float $a, float $b, float $Θ){
return 1 / (1 + exp(-1.7 * $a * ($Θ - $b)));;
}
public function LL(array $u, array $a, array $b, float $Θ){
$temp = array();
for($i = 0; $i < count($u); $i++){
$temp[] = ($u[$i]*log($this->icc2PL($a[$i],$b[$i],$Θ)))+((1-$u[$i])*log(1-$this->icc2PL($a[$i],$b[$i],$Θ)));
}
return array_sum($temp);
}
public function dLL(array $u, array $a, array $b, float $Θ){
$temp = array();
for($i = 0; $i < count($u); $i++){
$temp[] = 1.7*$a[$i]*($u[$i]-$this->icc2PL($a[$i],$b[$i],$Θ));
}
return array_sum($temp);
}
public function ddLL(array $a, array $b, float $Θ){
$temp = array();
for($i = 0; $i < count($a); $i++){
$temp[] = -pow(1.7,2)*pow($a[$i],2)*$this->icc2PL($a[$i],$b[$i],$Θ)*(1-$this->icc2PL($a[$i],$b[$i],$Θ));
}
return array_sum($temp);
}
public function LG(array $u, array $a, array $b, float $Θ, float $μ, float $σ){
return $this->LL($u, $a, $b, $Θ)-(0.5*pow(($Θ-$μ)/$σ,2));
}
public function dLG(array $u, array $a, array $b, float $Θ, float $μ, float $σ){
return $this->dLL($u, $a, $b, $Θ)-(($Θ-$μ)/pow($σ,2));
}
public function ddLG(array $a, array $b, float $Θ, float $μ, float $σ){
return $this->ddLL($a, $b, $Θ)-(1/pow($σ,2));
}
public function run(){
# 事前分布(標準正規分布)
$μ = 0;
$σ = 1;
$a = [1.0, 1.5, 0.7, 1.2]; # 識別力パラメタ
$b = [1.5, 0.5, 0.0, -1.0]; # 困難度パラメタ
$u = [1, 0, 1, 1]; # ある受験者の反応パタン
# 収束基準用
$ε = 0.0001;
# ある受験者の能力値 Θ 初期値を設定する
# FROM Wainer et al 2007
$Θ0 = log(array_sum($u)/(count($u)-array_sum($u)));
echo '初期値 : ' . $Θ0 . "\n";
# 初期値
$Θ1 = 0;
# フラグ
$flag = false;
while(!$flag){
$Θ1 = $Θ0 - ($this->dLG($u, $a, $b, $Θ0, $μ, $σ) / $this->ddLG($a, $b, $Θ0, $μ, $σ));
if(abs($Θ1-$Θ0)<$ε){
$flag = true;
}
$Θ0 = $Θ1;
}
echo '更新値 : ' . $Θ1 . "\n";
}
}
index.php
require_once('MAPEstimation.php')
$me = new MAPEstimation();
$me->run();
出力結果
初期値 : 1.0986122886681 更新値 : 0.55046425710048