Skip to content

Commit

Permalink
add skewness and kurtosis
Browse files Browse the repository at this point in the history
  • Loading branch information
solaoi committed Mar 30, 2022
1 parent e291701 commit 8768e8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ you'll get the correlation coefficient of two columns.

## Feature

- Quick
- Auto detect a separator
- Auto detect a header row

Expand All @@ -62,7 +61,7 @@ you can download a binary release
```sh
# Install with wget or curl
## set the latest version on releases.
VERSION=v1.0.21
VERSION=v1.0.22
## case you use wget
wget https://github.com/solaoi/colc/releases/download/$VERSION/colc_linux_amd64.tar.gz
## case you use curl
Expand Down
15 changes: 13 additions & 2 deletions colc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { runner } from "./lib/common.ts";
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";

const colcVersion = "v1.0.21"
const colcVersion = "v1.0.22"
const colcDescription = `Complete documentation is available at https://github.com/solaoi/colc
Usage:
Expand Down Expand Up @@ -152,7 +152,7 @@ if (binSize === null) {
}
bash.push("| sort -n | awk");
bash.push(
`'BEGIN{OFMT="%.${awkPrecision}f"}NR==1{min=$1}{if(0==$1)zeros++;if($1<0)neg++;sum+=$1;d[NR]=$1}END{avg=sum/NR;for(i in d)s+=(d[i]-avg)^2;stddev=sqrt(s/(NR-1));q1=(3*d[int((NR-1)/4)+1]+d[int((NR-1)/4)+2])/4;q3=(d[int(3*(NR-1)/4)+1]+3*d[int(3*(NR-1)/4)+2])/4;iqr=q3-q1;stur=1+log(NR)/log(2);sturi=int(stur);sturges=stur>sturi?sturi+1:sturi;max=d[NR];range=max-min;sqrtnr=sqrt(NR);threerootnr=exp(log(NR)/3);print stddev,avg,sum,NR,max,min,sqrt(s/(NR-1))/sqrtnr,s/(NR-1),(NR%2)?d[(NR+1)/2]:(d[NR/2]+d[NR/2+1])/2,avg+stddev,avg-stddev,avg+2*stddev,avg-2*stddev,avg+3*stddev,avg-3*stddev,range/sturges,(3.5*stddev)/threerootnr,q1,q3,iqr,q1-1.5*iqr,q3+1.5*iqr,range/sqrtnr,2*iqr/threerootnr,range,zeros,zeros*100/NR,neg,neg*100/NR,stddev/avg}'`,
`'BEGIN{OFMT="%.${awkPrecision}f"}NR==1{min=$1}{if(0==$1)zeros++;if($1<0)neg++;sum+=$1;d[NR]=$1}END{avg=sum/NR;for(i in d)s+=(d[i]-avg)^2;stddev=sqrt(s/(NR-1));for(i in d){t+=((d[i]-avg)/stddev)^3;u+=((d[i]-avg)/stddev)^4};q1=(3*d[int((NR-1)/4)+1]+d[int((NR-1)/4)+2])/4;q3=(d[int(3*(NR-1)/4)+1]+3*d[int(3*(NR-1)/4)+2])/4;iqr=q3-q1;stur=1+log(NR)/log(2);sturi=int(stur);sturges=stur>sturi?sturi+1:sturi;max=d[NR];range=max-min;sqrtnr=sqrt(NR);threerootnr=exp(log(NR)/3);print stddev,avg,sum,NR,max,min,sqrt(s/(NR-1))/sqrtnr,s/(NR-1),(NR%2)?d[(NR+1)/2]:(d[NR/2]+d[NR/2+1])/2,avg+stddev,avg-stddev,avg+2*stddev,avg-2*stddev,avg+3*stddev,avg-3*stddev,range/sturges,(3.5*stddev)/threerootnr,q1,q3,iqr,q1-1.5*iqr,q3+1.5*iqr,range/sqrtnr,2*iqr/threerootnr,range,zeros,zeros*100/NR,neg,neg*100/NR,stddev/avg,NR*t/((NR-1)*(NR-2)),NR*(NR+1)*u/(NR-1)/(NR-2)/(NR-3)-3*(NR-1)^2/(NR-2)/(NR-3)}'`,
);
return bash.join(" ");
})();
Expand Down Expand Up @@ -188,6 +188,8 @@ if (binSize === null) {
negatives,
negativeRate,
cv,
skewness,
kurtosis
] = await runner
.run(statsCommand).then((s) => s.split(" "));
const sturgesFormulaIsInvalid = count.split(".")[0].length <= 2 &&
Expand All @@ -214,6 +216,10 @@ if (binSize === null) {
"Q1–(1.5*IQR)": comma(lf),
"Q3+(1.5*IQR)": comma(uf),
};
const distribution = {
"skewness": comma(skewness),
"kurtosis": comma(kurtosis)
}
const stds = {
"stddev(σ)": comma(stddev),
"stderr": comma(stderr),
Expand All @@ -235,6 +241,7 @@ if (binSize === null) {
...total,
...stats,
...iqrs,
...distribution,
...stds,
...recommendedBinsizes,
}),
Expand All @@ -252,6 +259,10 @@ if (binSize === null) {
println(key, value);
});
hr();
Object.entries(distribution).forEach(([key, value]) => {
println(key, value);
});
hr();
Object.entries(stds).forEach(([key, value]) => {
println(key, value);
});
Expand Down

0 comments on commit 8768e8d

Please sign in to comment.