comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: mean and sdev
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: mean and sdev [message #11069] Tue, 03 March 1998 00:00 Go to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
David Fanning wrote:
>
> R. Bauer (r.bauer@fz-juelich.de) writes:
>
>> I 'd like to know if a build in function somewhere is available to get
>> means and standard deviations.
>
> I use the MOMENT function for most of these simple statistical
> measurements.
>
> stats = Moment(data, STD=standardDeviation)
> mean = stats[0]
> Print, mean, standardDeviation
>
> Cheers,
>
> David
>

MOMENT just has one big disadvantage in my opinion: it does not like
standard deviations of zero. So I went ahead and added an
/IGNORE_ERROR option that will return the results of mean and sdev
anyhow with skewness and kurtosis set to 0 ...

regards,
Martin.



--
------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Earth&Planetary Sciences, Harvard University
186 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA

phone: (617)-496-8318
fax : (617)-495-4551

e-mail: mgs@io.harvard.edu
IDL-homepage: http://www-as.harvard.edu/people/staff/mgs/idl/
------------------------------------------------------------ -------

;$Id: moment.pro,v 1.4 1995/07/25 20:32:55 dave Exp $
;
; Copyright (c) 1994, Research Systems, Inc. All rights reserved.
; Unauthorized reproduction prohibited.
;+
; NAME:
; MOMENT2
;
; PURPOSE:
; This function computes the mean, variance, skewness and kurtosis
; of an n-element vector.
;
; CATEGORY:
; Statistics.
;
; CALLING SEQUENCE:
; Result = Moment(X)
;
; INPUTS:
; X: An n-element vector of type integer, float or double.
;
; KEYWORD PARAMETERS:
; MDEV: Use this keyword to specify a named variable which returns
; the mean absolute deviation of X.
;
; SDEV: Use this keyword to specify a named variable which returns
; the standard deviation of X.
;
; EXAMPLE:
; Define the n-element vector of sample data.
; x = [65, 63, 67, 64, 68, 62, 70, 66, 68, 67, 69, 71, 66, 65, 70]
; Compute the mean, variance, skewness and kurtosis.
; result = moment(x)
; The result should be the 4-element vector:
; [66.7333, 7.06667, -0.0942851, -1.18258]
;
; PROCEDURE:
; MOMENT computes the first four "moments" about the mean of an
; n-element vector of sample data. The computational formulas
; are given in the Univariate Statistics section of the Mathematics
; Guide.
;
; REFERENCE:
; APPLIED STATISTICS (third edition)
; J. Neter, W. Wasserman, G.A. Whitmore
; ISBN 0-205-10328-6
;
; MODIFICATION HISTORY:
; Written by: GGS, RSI, August 1994
; modified by mgs@io.harvard.edu Nov 1997: added /ignore_error option
;-

function moment2, x, mdev = mdev, sdev = sdev,ignore_error=ignore

on_error, 2
nx = n_elements(x)
if nx le 1 then $
message, 'Not defined for scalar inputs.'

mean = total(x) / nx
resid = x - mean
;Mean absolute deviation (returned through the MDEV keyword).
mdev = total(abs(resid)) / nx
r2 = total(resid^2)
var1 = r2 / (nx-1.0)
var2 = (r2 - (total(resid)^2)/nx)/(nx-1.0)
var = (var1 + var2)/2.0
;Standard deviation (returned through the SDEV keyword).
sdev = sqrt(var)

if var ne 0 then begin
skew = total(resid^3) / (nx * sdev ^ 3)
kurt = total(resid^4) / (nx * sdev ^ 4) - 3.0
endif else begin
skew = 0.
kurt = 0.
if(not keyword_set(ignore)) then message, $
'Skewness and Kurtosis not defined for a sample variance of zero.'
endelse
return, [mean, var, skew, kurt]
end
  • Attachment: moment2.pro
    (Size: 2.40KB, Downloaded 94 times)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Array intersections
Next Topic: Re: flanagan@spacenet

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 13:16:16 PDT 2025

Total time taken to generate the page: 2.23522 seconds