php - MySQL rollup with Pearson's R -
i'm using mysql & php calculate pearson's r measuring relationship on number of years between political donations , tenders received particular business.
i've run trouble mysql query feeding values algorithm. algorithm fine , evaluates correctly. problem in query used data.
the formula i'm using pearson's r @ http://www.statisticshowto.com/how-to-compute-pearsons-correlation-coefficients/
here basic mysql query spits out values each year:
select count( distinct year) count,name,sum(donations), sum(tenders), sum(donations * tenders) xy,(sum(donations)*sum(donations)) x2, (sum(tenders)*sum(tenders)) y2 money_by_year name='$name' group name,year
here query rollup final values:
select count( distinct year) count,name,sum(donations), sum(tenders), sum(donations * tenders) xy,(sum(donations)*sum(donations)) x2, (sum(tenders)*sum(tenders)) y2 money_by_year name='$name' group name rollup limit 1
the problem totals second query wrong in sum xy, x2 & y2. being caused query itself, rollup , i'd know going on it.
you can see working examples of code values resulting both above queries , algorithm @ https://openaus.net.au/follow_the_money.php?name=kpmg
i have tried various changes sum(donations * tenders) xy example implementing sum(donations) * sum(tenders) in:
select count( distinct year) count,name,sum(donations), sum(tenders), sum(donations) * sum(tenders) xy,(sum(donations)*sum(donations)) x2, (sum(tenders)*sum(tenders)) y2 money_by_year name='kpmg' group name rollup limit 1
however rollup totals incorrect, bigger should be. values want may not possible via single mysql query appreciate knowing why case, rollup doing figures , why.
Comments
Post a Comment