Cumulative standard deviation: Difference between revisions
Content added Content deleted
m (Fixed lang tags.) |
|||
Line 7: | Line 7: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
⚫ | |||
<lang ada> |
|||
⚫ | |||
with Ada.Text_IO; use Ada.Text_IO; |
with Ada.Text_IO; use Ada.Text_IO; |
||
Line 35: | Line 34: | ||
end loop; |
end loop; |
||
Put_Line ("Deviation" & Float'Image (Deviation (Data))); |
Put_Line ("Deviation" & Float'Image (Deviation (Data))); |
||
end Test_Deviation; |
end Test_Deviation;</lang> |
||
</lang> |
|||
Sample output: |
Sample output: |
||
<pre> |
<pre> |
||
Line 400: | Line 398: | ||
J is block-oriented; it expresses algorithms with the semantics of all the data being available at once. It does not have native lexical closure or coroutine semantics. It is possible to implement these semantics in J; see [[Moving Average]] for an example. We will not reprise that here. |
J is block-oriented; it expresses algorithms with the semantics of all the data being available at once. It does not have native lexical closure or coroutine semantics. It is possible to implement these semantics in J; see [[Moving Average]] for an example. We will not reprise that here. |
||
mean=: +/ % # |
<lang j> mean=: +/ % # |
||
dev=: - mean |
|||
sumsqdev=: +/@:*:@dev |
|||
stddevP=: [: %: sumsqdev % # |
|||
stddevP\ 2 4 4 4 5 5 7 9 |
|||
0 1 0.942809 0.866025 0.979796 1 1.39971 2</lang> |
|||
{{trans|R}}<BR> |
{{trans|R}}<BR> |
||
Or we could take a cue from the [[#R|R implementation]] and reverse the Bessel correction to stddev: |
Or we could take a cue from the [[#R|R implementation]] and reverse the Bessel correction to stddev: |
||
require'stats' |
<lang j> require'stats' |
||
(%:@:(%~<:)@:# * stddev)\ 2 4 4 4 5 5 7 9 |
|||
0 1 0.942809 0.866025 0.979796 1 1.39971 2</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
Line 687: | Line 685: | ||
(7, 1.3997084244475311) |
(7, 1.3997084244475311) |
||
(9, 2.0) |
(9, 2.0) |
||
>>> |
>>></lang> |
||
===Using a class instance=== |
===Using a class instance=== |
||
Line 734: | Line 732: | ||
=={{header|R}}== |
=={{header|R}}== |
||
===Built-in Std Dev fn=== |
===Built-in Std Dev fn=== |
||
⚫ | |||
<lang R> |
|||
⚫ | |||
#If na.rm is true, missing data points (NA values) are removed. |
#If na.rm is true, missing data points (NA values) are removed. |
||
reverseBesselCorrection <- function(x, na.rm=FALSE) |
reverseBesselCorrection <- function(x, na.rm=FALSE) |
||
Line 745: | Line 742: | ||
} |
} |
||
testdata <- c(2,4,4,4,5,5,7,9) |
testdata <- c(2,4,4,4,5,5,7,9) |
||
reverseBesselCorrection(testdata)*sd(testdata) #2 |
reverseBesselCorrection(testdata)*sd(testdata) #2</lang> |
||
</lang> |
|||
===From scratch=== |
===From scratch=== |
||
⚫ | |||
<lang R> |
|||
⚫ | |||
uncorrectedsd <- function(x, na.rm=FALSE) |
uncorrectedsd <- function(x, na.rm=FALSE) |
||
{ |
{ |
||
Line 759: | Line 754: | ||
usd |
usd |
||
} |
} |
||
uncorrectedsd(testdata) #2 |
uncorrectedsd(testdata) #2</lang> |
||
</lang> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 767: | Line 761: | ||
This is indeed Object REXX. |
This is indeed Object REXX. |
||
<lang |
<lang rexx>sdacc = .SDAccum~new |
||
x = .array~of(2,4,4,4,5,5,7,9) |
x = .array~of(2,4,4,4,5,5,7,9) |
||
sd = 0 |
sd = 0 |