PHP Classes

Mistakes

Recommend this page to a friend!

      PHP Statistical Analysis using Data Inference  >  All threads  >  Mistakes  >  (Un) Subscribe thread alerts  
Subject:Mistakes
Summary:propsitions to fix bug
Messages:1
Author:Andrii
Date:2018-05-10 13:42:51
 

  1. Mistakes   Reply   Report abuse  
Picture of Andrii Andrii - 2018-05-10 13:42:51
Hello!
There are few mistakes in your class :
1) Statistics.php, line 83:
$this->data is not defined
2) function mediana() is not correct :
$d1 = $total / 2;
$d2 = $d1 + 1;
If total = 10 then d1=5, d2=6, but must be d1=4,d2=5
3) functions q1(),q2(), q3() do not calculate quartiles.
I propose to modify them :
a) in class raw2table add two functions :
protected function getDataForQ1($data) {
$total = $this->get_total_data($data);
sort($data);
$arrRet = array();

if($total % 2 == 0){
$dt = $total / 2;
}
else {
$dt=($total+1)/2;
}

for ($i=0; $i < $dt; $i++) {
$arrRet[] = $data[$i];
}

return $arrRet;
}

protected function getDataForQ3($data) {
$total = $this->get_total_data($data);
sort($data);
$arrRet = array();

if($total % 2 == 0){
$dt = $total / 2;
}
else {
$dt=($total+1)/2;
}

for ($i=$dt; $i < $total; $i++) {
$arrRet[] = $data[$i];
}

return $arrRet;
}
b) Change functions q1,q2,q3 as follows :
public function q1($data){
$dataq = $this->getDataForQ1($data);
return $this->median($dataq);
}

public function q2($data){
return $this->median($data);
}

public function q3($data){
$dataq = $this->getDataForQ3($data);
return $this->median($dataq);
}

Best regards.