-module(gelman@transform). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/gelman/transform.gleam"). -export([winsorize/3]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " This module defines functions that perform\n" " statistical transformations over a dataset.\n" "\n" " A statistical transformation is a function that modifies\n" " the dataset based on some statistically desirable qualities.\n" "\n" " A statistical function could preserve the size of the dataset\n" " or it could reduce the size of the dataset by excluding some\n" " elements.\n" " Unlike the functions in summarize or discretize, these do not\n" " error out if the dataset has no elements.\n" ). -file("src/gelman/transform.gleam", 22). -spec winsorize(list(float()), float(), float()) -> {ok, list(float())} | {error, gelman@error:stats_error()}. winsorize(Dataset, Left, Right) -> case {Dataset, (Left > +0.0) andalso (Left < 1.0), (Right > +0.0) andalso (Right < 1.0)} of {_, false, _} -> {error, {invalid_parameter, <<"Winsorize bounds between 0.0 and 0.1"/utf8>>}}; {_, _, false} -> {error, {invalid_parameter, <<"Winsorize bounds between 0.0 and 0.1"/utf8>>}}; {[], _, _} -> {error, empty_dataset}; {[X], _, _} -> {ok, [X]}; {[X@1, Y], _, _} -> {ok, [X@1, Y]}; {_, _, _} -> _pipe = Dataset, _pipe@1 = gelman@internal@nonempty@transform:winsorize( _pipe, Left, Right ), {ok, _pipe@1} end.