Cumulative standard deviation: Difference between revisions

m
Fixed lang tags.
m (Fixed lang tags.)
Line 7:
 
=={{header|Ada}}==
<lang ada>with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
<lang ada>
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
with Ada.Text_IO; use Ada.Text_IO;
 
Line 35 ⟶ 34:
end loop;
Put_Line ("Deviation" & Float'Image (Deviation (Data)));
end Test_Deviation;</lang>
</lang>
Sample output:
<pre>
Line 400 ⟶ 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.
<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>
Or we could take a cue from the [[#R|R implementation]] and reverse the Bessel correction to stddev:
 
<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}}==
Line 687 ⟶ 685:
(7, 1.3997084244475311)
(9, 2.0)
>>> </lang>
 
===Using a class instance===
Line 734 ⟶ 732:
=={{header|R}}==
===Built-in Std Dev fn===
<lang R>#The built-in standard deviation function applies the Bessel correction. To reverse this, we can apply an uncorrection.
<lang R>
#The built-in standard deviation function applies the Bessel correction. To reverse this, we can apply an uncorrection.
#If na.rm is true, missing data points (NA values) are removed.
reverseBesselCorrection <- function(x, na.rm=FALSE)
Line 745 ⟶ 742:
}
testdata <- c(2,4,4,4,5,5,7,9)
reverseBesselCorrection(testdata)*sd(testdata) #2</lang>
</lang>
===From scratch===
<lang R>#Again, if na.rm is true, missing data points (NA values) are removed.
<lang R>
#Again, if na.rm is true, missing data points (NA values) are removed.
uncorrectedsd <- function(x, na.rm=FALSE)
{
Line 759 ⟶ 754:
usd
}
uncorrectedsd(testdata) #2</lang>
</lang>
 
=={{header|REXX}}==
Line 767 ⟶ 761:
This is indeed Object REXX.
 
<lang orexxrexx>sdacc = .SDAccum~new
x = .array~of(2,4,4,4,5,5,7,9)
sd = 0
Anonymous user