Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECDF Stat #832

Merged
merged 17 commits into from
Aug 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix ECDFStat (case when in one group there is only NaN's).
  • Loading branch information
ASmirnov-HORIS committed Jul 27, 2023
commit 5411aa4555250b939780b699a3233e6193570986
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,23 @@ class ECDFStat(
return withEmptyStatValues()
}

val xs = data.getNumeric(TransformVar.X)
val statData = buildStat(data.getNumeric(TransformVar.X))

return DataFrame.Builder()
.putNumeric(Stats.X, statData.getValue(Stats.X))
.putNumeric(Stats.Y, statData.getValue(Stats.Y))
.build()
}

private fun buildStat(
xs: List<Double?>
): Map<DataFrame.Variable, List<Double>> {
val xValues = xs.filter { it?.isFinite() ?: false }.map { it!! }
if (xValues.isEmpty()) {
return withEmptyStatValues()
return mapOf(
Stats.X to emptyList(),
Stats.Y to emptyList(),
)
}

val ecdf: (Double) -> Double = { t -> xValues.count { x -> x <= t }.toDouble() / xValues.size }
Expand All @@ -37,10 +50,10 @@ class ECDFStat(
}
val statY = statX.map { ecdf(it) }

return DataFrame.Builder()
.putNumeric(Stats.X, statX)
.putNumeric(Stats.Y, statY)
.build()
return mapOf(
Stats.X to statX,
Stats.Y to statY,
)
}

private fun linspace(start: Double, stop: Double, num: Int): List<Double> {
Expand Down