• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PolyMathOrg / PolyMath / 4385132063

pending completion
4385132063

push

github

GitHub
Merge pull request #316 from jecisc/divers-cleanings

2977 of 2977 new or added lines in 214 files covered. (100.0%)

19725 of 24212 relevant lines covered (81.47%)

2.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

49.12
/src/Math-Distributions/PMStudentDistribution.class.st
1
Class {
2
        #name : #PMStudentDistribution,
3
        #superclass : #PMProbabilityDensity,
4
        #instVars : [
5
                'degreeOfFreedom',
6
                'norm',
7
                'chiSquareDistribution',
8
                'incompleteBetaFunction'
9
        ],
10
        #category : #'Math-Distributions-ForHistogram'
11
}
12

13
{ #category : #creation }
14
PMStudentDistribution class >> asymptoticLimit [
3✔
15

3✔
16
        ^30
3✔
17
]
3✔
18

19
{ #category : #creation }
20
PMStudentDistribution class >> degreeOfFreedom: anInteger [
3✔
21
        "Create a new instance of the receiver with anInteger degrees of freedom."
3✔
22

3✔
23
        ^anInteger > self asymptoticLimit
3✔
24
                ifTrue: [PMNormalDistribution new]
3✔
25
                ifFalse:
3✔
26
                        [anInteger = 1
3✔
27
                                ifTrue: [PMCauchyDistribution shape: 0 scale: 1]
3✔
28
                                ifFalse: [super new initialize: anInteger]]
3✔
29
]
3✔
30

31
{ #category : #information }
32
PMStudentDistribution class >> distributionName [
×
33

×
34
        ^'Student distribution'
×
35
]
×
36

37
{ #category : #creation }
38
PMStudentDistribution class >> fromHistogram: aHistogram [
×
39
        "Create an instance of the receiver with parameters estimated from the given histogram using best guesses. This method can be used to find the initial values for a fit."
×
40
        | dof var |
×
41
        var := aHistogram variance.
×
42
        var = 0
×
43
                ifTrue: [ ^nil].
×
44
        dof :=  ( 2 / (1 - (1 / aHistogram variance))) rounded max: 1.
×
45
        ^dof > self asymptoticLimit ifTrue: [ nil]
×
46
                                                                ifFalse:[ self degreeOfFreedom: dof]
×
47
]
×
48

49
{ #category : #creation }
50
PMStudentDistribution class >> new [
×
51

×
52
        ^self error: 'Illegal creation message for this class'
×
53
]
×
54

55
{ #category : #creation }
56
PMStudentDistribution class >> test: aStatisticalMoment1 with: aStatisticalMoment2 [
×
57
        "Perform a consistency Student test (or t-test) on the averages of  two statistical moments ( or histograms). Answers the probability of failing the test."
×
58
        | t |
×
59
        t := ( aStatisticalMoment1 average - aStatisticalMoment2 average) abs.
×
60
        ^1 - ( ( self class degreeOfFreedom: (  aStatisticalMoment1 count + aStatisticalMoment2 count - 2)) acceptanceBetween: t negated and: t)
×
61
]
×
62

63
{ #category : #information }
64
PMStudentDistribution >> average [
3✔
65

3✔
66
        ^0
3✔
67
]
3✔
68

69
{ #category : #transformation }
70
PMStudentDistribution >> changeParametersBy: aVector [
×
71
        "Modify the parameters of the receiver by aVector."
×
72
        degreeOfFreedom := degreeOfFreedom + ( aVector at: 1).
×
73
        self computeNorm
×
74
]
×
75

76
{ #category : #information }
77
PMStudentDistribution >> chiSquareDistribution [
×
78
        "Answer the chi square distribution used to generate random numbers for the receiver."
×
79

×
80
        chiSquareDistribution ifNil: [ chiSquareDistribution := PMChiSquareDistribution degreeOfFreedom: degreeOfFreedom - 1 ].
×
81
        ^ chiSquareDistribution
×
82
]
×
83

84
{ #category : #private }
85
PMStudentDistribution >> computeNorm [
3✔
86
        "Private - Compute the norm of the receiver because its parameters have changed."
3✔
87
        norm := ( ( degreeOfFreedom / 2 logBeta: ( 1 / 2) ) + ( degreeOfFreedom ln / 2)) negated
3✔
88
]
3✔
89

90
{ #category : #information }
91
PMStudentDistribution >> confidenceLevel: aNumber [
3✔
92
        "Answer the probability in percent of finding a value distributed according to the receiver with an absolute value larger than aNumber."
3✔
93
        ^( 1 - ( self symmetricAcceptance: aNumber abs)) * 100
3✔
94
]
3✔
95

96
{ #category : #information }
97
PMStudentDistribution >> distributionValue: aNumber [
3✔
98
        "Answers the probability of observing a random variable distributed according to the receiver with a value lower than or equal to aNumber."
3✔
99
        aNumber = 0
3✔
100
                ifTrue: [ ^1/2].
3✔
101
        ^( aNumber > 0
3✔
102
                ifTrue: [ 2 - ( self symmetricAcceptance: aNumber abs)]
3✔
103
                ifFalse:[ self symmetricAcceptance: aNumber abs]) / 2
3✔
104
]
3✔
105

106
{ #category : #information }
107
PMStudentDistribution >> incompleteBetaFunction [
3✔
108
        "Private - Answers the incomplete beta function used to compute the symmetric acceptance integral of the receiver."
3✔
109

3✔
110
        incompleteBetaFunction ifNil: [ incompleteBetaFunction := PMIncompleteBetaFunction shape: degreeOfFreedom / 2 shape: 0.5 ].
3✔
111
        ^ incompleteBetaFunction
3✔
112
]
3✔
113

114
{ #category : #initialization }
115
PMStudentDistribution >> initialize: anInteger [
3✔
116

3✔
117
        anInteger > 0
3✔
118
                ifFalse: [ self error: 'Degree of freedom must be positive'].
3✔
119
        degreeOfFreedom := anInteger.
3✔
120
        self computeNorm.
3✔
121
        ^self
3✔
122
]
3✔
123

124
{ #category : #information }
125
PMStudentDistribution >> kurtosis [
×
126
        "Answer the kurtosis of the receiver. Undefined if the degree of freedom is less than 5."
×
127
        ^degreeOfFreedom > 4 ifTrue: [ 6 / ( degreeOfFreedom - 4)]
×
128
                                                 ifFalse:[ nil]
×
129
]
×
130

131
{ #category : #information }
132
PMStudentDistribution >> parameters [
×
133

×
134
        ^Array with: degreeOfFreedom
×
135
]
×
136

137
{ #category : #information }
138
PMStudentDistribution >> random [
×
139
        "Answer a random number distributed according to the receiver."
×
140
        ^PMNormalDistribution random * ( ( (degreeOfFreedom - 1) / self chiSquareDistribution random ) sqrt)
×
141
]
×
142

143
{ #category : #information }
144
PMStudentDistribution >> skewness [
×
145

×
146
        ^0
×
147
]
×
148

149
{ #category : #information }
150
PMStudentDistribution >> symmetricAcceptance: aNumber [
3✔
151
        "Compute the acceptance of the receiver between -aNumber and aNumber"
3✔
152
        ^ self incompleteBetaFunction value: ( degreeOfFreedom / ( aNumber squared + degreeOfFreedom))
3✔
153
]
3✔
154

155
{ #category : #information }
156
PMStudentDistribution >> value: aNumber [
3✔
157
        "Answers the probability that a random variable distributed according to the receiver gives a value between aNumber and aNumber + espilon (infinitesimal interval)."
3✔
158
        ^( norm - ( ( aNumber squared / degreeOfFreedom + 1) ln * ( ( degreeOfFreedom + 1) / 2))) exp
3✔
159
]
3✔
160

161
{ #category : #information }
162
PMStudentDistribution >> variance [
×
163
        "Answer the variance of the receiver. Undefined if the degree of freedom is less than 3."
×
164
        ^degreeOfFreedom > 2
×
165
                ifTrue: [ degreeOfFreedom / ( degreeOfFreedom - 2)]
×
166
                ifFalse:[ nil]
×
167
]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc