Module Evidence.Var

Observation variables.

This module provides a type to describe and type observation variables. Essentially, an observation variable is a named projection function.

Variable types

type 'a type' =
  1. | Bool : bool type'
  2. | Int : int type'
  3. | Float : float type'
  4. | Ordinal : ('a -> 'a -> int) -> 'a type'
  5. | Nominal : string type'
  6. | Any : 'a type'
    (*

    Uses Stdlib.compare to order values.

    *)

The type for types of variables.

module Type : sig ... end

Variable types.

Variables

type name = string

The type for variable names.

type ('o, 'a) t

The type for describing variables of type 'a for an observation of type 'o.

type 'o v =
  1. | V : ('o, 'a) t -> 'o v

The type for existential variables for observations of type 'o.

val v : ?doc:string -> ?label:string -> ?pp:'a fmt -> name -> 'a type' -> ('o -> 'a) -> ('o, 'a) t

v ?doc ?pp name type' proj an observation variable with

  • name the name or identifier of the variable.
  • type' the type of the variable.
  • proj the projection of the variable.
  • pp a formatter for the variable, defaults to Type.value_pp
  • label a label for the variable used in graphical rendering
  • doc a documentation string for the variable

Warning. For float types, if you want nan values to be treated by Dataset as missing values, you need to use Float and not Any or Ordinal.

Note. Variables have a notion of identity, if you create two variables with the same parameters they will not be deemed equal by equal.

Convenience constructors

val bool : ?doc:string -> ?label:string -> ?pp:bool fmt -> name -> ('o -> bool) -> ('o, bool) t

bool name proj is v name Bool proj.

val int : ?doc:string -> ?label:string -> ?pp:int fmt -> name -> ('o -> int) -> ('o, int) t

int name proj is v name Int proj.

val float : ?doc:string -> ?label:string -> ?pp:float fmt -> name -> ('o -> float) -> ('o, float) t

float name proj is v name Float proj.

val nominal : ?doc:string -> ?label:string -> ?pp:string fmt -> name -> ('o -> string) -> ('o, string) t

nominal name proj is v name Nominal.

val ordinal : ?doc:string -> ?label:string -> ?pp:'a fmt -> name -> ('a -> 'a -> int) -> ('o -> 'a) -> ('o, 'a) t

ordinal name compare proj is v name (Ordinal compare) proj.

val any : ?doc:string -> ?label:string -> ?pp:'a fmt -> name -> ('o -> 'a) -> ('o, 'a) t

any name proj is v name Any proj.

val const : ?doc:string -> ?label:string -> ?pp:'a fmt -> name -> 'a type' -> 'a -> ('o, 'a) t

const name type' v is v name type' (Fun.const v).

val id : 'a type' -> ('a, 'a) t

id type' is an v "id" type' Fun.id identity variable.

Properties

val doc : ('o, 'a) t -> string

doc var is the documentation string of var.

val exist : ('o, 'a) t -> 'o v

exist var is an existential for var.

val name : ('o, 'a) t -> name

name var is the name of var.

val label : ('o, 'a) t -> string

label var is the label of var.

val proj : ('o, 'a) t -> 'o -> 'a

proj var is the projection of var.

val type' : ('o, 'a) t -> 'a type'

type' var is the type of var.

Transforming

val alter : ?doc:string -> ?label:string -> ?pp:'a fmt -> ?name:name -> ('o, 'a) t -> ('o, 'a) t

alter ?doc ?label ?name ?pp var is var with the given parameters. The resulting variable is equal to var.

val map : ?doc:string -> ?label:string -> ?pp:'b fmt -> ('a -> 'b) -> ('o, 'a) t -> name -> 'b type' -> ('o, 'b) t

map f var name type' is a new variable derived via f from var.

Operations on variable values

val equal_value : ('o, 'a) t -> 'a -> 'a -> bool

equal_value var is a comparison function for the values of var. nan values are deemed equal.

val compare_value : ('o, 'a) t -> 'a -> 'a -> int

compare_value var is a comparison function for values of var. nan values are deemed equal and lower than any other float value.

val min_value : ('o, 'a) t -> 'a -> 'a -> 'a

min_value var is a function that determines the minimum for values of var. On Float variables this uses Float.min_num which treats nans as missing values.

val max_value : ('o, 'a) t -> 'a -> 'a -> 'a

min_value var is a function that determines the maximum for values of var. On Float variables this uses Float.max_num which treats nans as missing values.

val pp_value : ('o, 'a) t -> 'a fmt

pp_value var is a formatter for the values of var.

Operations on observations

See also Obs.

type 'o order =
  1. | A : ('o, 'a) t -> 'o order
    (*

    Ascending

    *)
  2. | D : ('o, 'a) t -> 'o order
    (*

    Descending

    *)

The type for variable order.

val order : 'o order list -> 'o -> 'o -> int

order vars is the lexicographic ascending or descending order of variables vars of observations. Raises Invalid_argument if vars is empty.

val is_na : ('o, float) t -> 'o -> bool

is_na var o is Float.is_nan (proj var o).

val between : 'a -> 'a -> ('o, 'a) t -> 'o -> bool

between min max var o is true iff proj var o is in the range [min;max]. This uses compare_value.

val equal_obs : ('o, 'a) t -> 'o -> 'o -> bool

equal_obs var tests for equality on variable var. nan values are deemed equal.

val compare_obs : ('o, 'a) t -> 'o -> 'o -> int

compare_obs var tests for equality on variable var. nan values are deemed equal.

val min_obs : ('o, 'a) t -> 'o -> 'o -> 'o

min_obs var o0 o1 is the observation with the minimal var value (either is returned on ties). On Float variables this uses Float.min_num which treats nans as missing values.

val max_obs : ('o, 'a) t -> 'o -> 'o -> 'o

max_obs var o0 o1 is the observation with the maximal var value (either is returned on ties). On Float variables this uses Float.max_num which treats nans as missing values.

val pp_obs : ('o, 'a) t -> 'o fmt

pp_obs var is a formatter for the variable var of observations.

Predicates and comparisons

val equal : ('o, 'a) t -> ('p, 'b) t -> bool

equal var0 var1 is true iff var0 and var1 is the same variable.

val compare : ('o, 'a) t -> ('p, 'b) t -> int

compare is a total order on variables compatible with equal.

Formatting

type 'a fmt = Stdlib.Format.formatter -> 'a -> unit

The type for formatters of values of type 'a.

val pp : ('o, 'a) t fmt

pp formats a variable's name and type.

Standard variables

val for_var_count : ('o, 'a) t -> ('a * int, 'a) t * ('a * int, int) t

for_var_count var are two variables to access the result of a Dataset.Var.count dataset.

val for_var_values : ('o, 'a) t -> ('a, 'a) t
val for_var : ('o, 'a) t -> ('a, 'a) t
val cumsum : (float, float) t

cumsum is the variable for Data.Var.cum_sum results.

Product

module Prod : sig ... end

Variable products.

module Gprod : sig ... end

Generalize Prod.