Statistics/Basic: Difference between revisions
J: closer reading of task requirements
(J: closer reading of task requirements) |
|||
Line 197:
=={{header|J}}==
J has library routines to compute mean and standard deviation:
<lang j> require'statfns'
(mean,stddev) ?1000#0
0.484669 0.287482
(mean,stddev) ?10000#0
0.503642 0.290777
(mean,stddev) ?100000#0
0.
but they are not quite what is being asked for here.
Line 210:
Instead:
<lang j>
NB. compute mean and std dev of y random numbers
NB. picked from even distribution between 0 and 1
s=.t=. 0
for_n.i.<.y%1e6 do.
t=.t+ +/(data-0.5)^2
end.
t=.t++/(data-0.5)^2
(s%y),%:t%y
)</lang>
For a histogram:
<lang j>histogram=: <: @ (#/.~) @ (i.@#@[ , I.)
require'plot'
plot ((%*1+i.)100) ([;histogram) ?10000#0</lang>
(should upload an image generated this way)
Example use:
<lang j>
0.501617 0.288271
0.49732 0.290061
0.
(That said, note that these numbers are random, so reported standard deviation will vary with the random sample being tested.)
|