A very simple class wrapping an Iterable[Product2[A,B]] and providing
basic weighted statistics like weighted mean and weighted variance.
The first element of the Pair is the value and the second element the weight.
There is an implicit conversion from a Seq[Product2[A,B]] to a
WeightedStats[A,B] imported with com.github.marklister.collections. So you do
not need to do anything to use this class. Simply use the mean, stdDev
or variance methods on an appropriate sequence:
import com.github.marklister.collections.io._
import com.github.marklister.collections._
Welcome to Scala version 2.10.1 (OpenJDK Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> CollSeq((1,2),(2,1),(3,3)).mean
res1: Double = 2.1666666666666665
I would really prefer to use an external library. If you know of one please
raise an issue on Github
This member is added by an implicit conversion from WeightedStats[A, B] to
any2stringadd[WeightedStats[A, B]] performed by method any2stringadd in scala.Predef.
This member is added by an implicit conversion from WeightedStats[A, B] to
ArrowAssoc[WeightedStats[A, B]] performed by method ArrowAssoc in scala.Predef.
This member is added by an implicit conversion from WeightedStats[A, B] to
StringFormat[WeightedStats[A, B]] performed by method StringFormat in scala.Predef.
Definition Classes
StringFormat
Annotations
@inline()
final defgetClass(): Class[_]
Definition Classes
AnyRef → Any
defhashCode(): Int
Definition Classes
AnyRef → Any
final defisInstanceOf[T0]: Boolean
Definition Classes
Any
lazy valmean: Double
The weighted arithmetic mean of all the elements
final defne(arg0: AnyRef): Boolean
Definition Classes
AnyRef
final defnotify(): Unit
Definition Classes
AnyRef
final defnotifyAll(): Unit
Definition Classes
AnyRef
lazy valstdDev: Double
The weighted standard deviation of all the elements
final defsynchronized[T0](arg0: ⇒ T0): T0
Definition Classes
AnyRef
deftoString(): String
Definition Classes
AnyRef → Any
valunderlying: Iterable[Product2[A, B]]
lazy valvariance: Double
The weighted variance of all the elements (the one divided by n not n-1)
This member is added by an implicit conversion from WeightedStats[A, B] to
ArrowAssoc[WeightedStats[A, B]] performed by method ArrowAssoc in scala.Predef.
Definition Classes
ArrowAssoc
Inherited from AnyRef
Inherited from Any
Inherited by implicit conversion any2stringadd from
WeightedStats[A, B] to any2stringadd[WeightedStats[A, B]]
Inherited by implicit conversion StringFormat from
WeightedStats[A, B] to StringFormat[WeightedStats[A, B]]
A very simple class wrapping an
Iterable[Product2[A,B]]
and providing basic weighted statistics like weighted mean and weighted variance.The first element of the Pair is the value and the second element the weight.
There is an implicit conversion from a
Seq[Product2[A,B]]
to aWeightedStats[A,B]
imported with com.github.marklister.collections. So you do not need to do anything to use this class. Simply use themean
,stdDev
orvariance
methods on an appropriate sequence:I would really prefer to use an external library. If you know of one please raise an issue on Github