You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add in some more messages to PMStatisticalSample (#200)
* Create Math-Statistics package and add harmonic mean geometric mean and mode.
* Refactor harmonicMean to use a guard clause.
Also add in a test to make sure that passing in a negative number causes an error.
* change the implementation of geometricMean.
* Add in guard clause to prevent use with negative numbers as the behaviour is not well defined.
* Prevent a potential float under/overflow by summing the logarithms as suggested by Nicolas Cellier.
* Convert extension methods into new class: PMStatisticalSample
* Add in aliases in PMStatisticalSample to the basic methods in Collection.
Adds in average, mean, median, stdev, variance messages
* Add in shortcut class methods for mean, median, stdev, and variance
* Change aCollection to aSample
"Calculate the harmonic mean of a collection. This shortcut method will create a new instance of PMStatisticalSample and return the desired metric."
48
48
49
-
^ (selfnewFrom:aCollection) harmonicMean
49
+
^ (selfnewFrom:aSample) harmonicMean
50
50
]
51
51
52
52
{ #category : #information }
53
-
PMStatisticalSampleclass>>mode: aCollection [
53
+
PMStatisticalSampleclass>>mean: aSample [
54
+
"Calculate the mean of a collection. This shortcut method will create a new instance of PMStatisticalSample and return the desired metric."
55
+
56
+
^ (selfnewFrom: aSample) mean
57
+
]
58
+
59
+
{ #category : #information }
60
+
PMStatisticalSampleclass>>median: aSample [
61
+
"Calculate the median of a collection. This shortcut method will create a new instance of PMStatisticalSample and return the desired metric."
62
+
63
+
^ (selfnewFrom: aSample) median
64
+
]
65
+
66
+
{ #category : #information }
67
+
PMStatisticalSampleclass>>mode: aSample [
54
68
"Calculate the mode of a collection. This shortcut method will create a new instance of PMStatisticalSample and return the desired metric."
55
69
56
-
^ (selfnewFrom:aCollection) mode
70
+
^ (selfnewFrom:aSample) mode
57
71
]
58
72
59
73
{ #category : #'instance creation' }
60
-
PMStatisticalSampleclass>>newFrom:aCollection [
74
+
PMStatisticalSampleclass>>newFrom:aSample [
61
75
"Create a new PMStatisticalSample with aCollection as the data"
62
76
63
77
| ss |
64
78
ss :=selfnew.
65
-
ss data:aCollection.
79
+
ss data:aSample.
66
80
^ ss
67
81
]
68
82
83
+
{ #category : #information }
84
+
PMStatisticalSampleclass>>stdev: aSample [
85
+
"Calculate the standard deviation of a collection. This shortcut method will create a new instance of PMStatisticalSample and return the desired metric."
86
+
87
+
^ (selfnewFrom: aSample) stdev
88
+
]
89
+
90
+
{ #category : #information }
91
+
PMStatisticalSampleclass>>variance: aSample [
92
+
"Calculate the variance of a collection. This shortcut method will create a new instance of PMStatisticalSample and return the desired metric."
93
+
94
+
^ (selfnewFrom: aSample) variance
95
+
]
96
+
97
+
{ #category : #information }
98
+
PMStatisticalSample>> average [
99
+
"An alias for the arithmetic mean of the sample"
100
+
^ data average
101
+
]
102
+
69
103
{ #category : #accessing }
70
104
PMStatisticalSample>> data [
71
105
"Get the collection that this StatisticalSample is calculated against"
@@ -74,23 +108,23 @@ PMStatisticalSample >> data [
74
108
]
75
109
76
110
{ #category : #accessing }
77
-
PMStatisticalSample>>data:aCollection [
111
+
PMStatisticalSample>>data:aSample [
78
112
"Set the collection of data points that statistical samples will be made against"
79
113
80
-
data :=aCollection
114
+
data :=aSample
81
115
]
82
116
83
117
{ #category : #information }
84
118
PMStatisticalSample>> geometricMean [
85
119
"Answer with the geometric mean of the collection"
0 commit comments