Imprimir
Publicado el por

Statistical distributions for the HP Prime - 2

We continue with the distributions as promised on last blog issue:

Beta Distribution:

EXPORT betad(a, b, n)

// Beta distribution: a=α>0, b=β>0 shape param, n var (0<=n<=1)

BEGIN

local f;

f:= piecewise(n<0 ,0, n>=1, 0, (1/Beta(a,b))*(n(a-1))*(1-n)(b–1));

return f;

END;

EXPORT betad_cdf(a, b, n)

BEGIN

local f, b1;

b1:= int((X(a-1))*(1-X)(b–1),X,0,n);

// incomplete beta function

f:=piecewise(n<0,0,n>=1, 0,  b1/Beta(a,b));

return f;

END;

Gamma distribution

EXPORT gammad(a,l,n)

// Gamma distributio 1st formn a=α>0 shape param

//  l=λ>0 rate param, n var

BEGIN

local f;

f:= piecewise( n<0,0, (l*e(-l*n)*(l*n)(a–1))/Gamma(a)  );

END;

EXPORT gammad_cdf(a,l,n)

BEGIN

local f;

f:= int(X(a-1)*e(-X),X,0,l*n)/Gamma(a);

return f;

END ;

EXPORT gammad2(k,t,n)

// Gamma distribution 2nd form  k>0 shape param,

// t=θ>0 scale param, n var

BEGIN

local f;

f:=piecewise(n<0,0,  (n(k-1)*e(-n/t)) / ((tk) * Gamma(k)) );

return f;

END;

EXPORT gammad2_cdf(k,t,n)

BEGIN

local f;

f:= int(X(k-1)*e(-X),X,0,n/t)/Gamma(k);

return f;

END ;

Zeta distribution

EXPORT Zetazipf(s, k)

// Zeta (Zipf) distribution, not defined in s=1

BEGIN

local f;

IF s=1 THEN return “Not defined in s=1”;  ELSE

f:= (k^(-s))/Zeta(s);

return f;

END;  //if

END;

EXPORT Zetazipf_cdf(s,k)

BEGIN

local f, hks;

hks:= sum(1/(Xs), X, 1, k);

// nth generalized armonic number

f:= hks/Zeta(s);

return f;

END;

Laplace distribution:

EXPORT laplaced(m,b,n)

// Laplace distribution m=μ location param, b scale param,  n var

// if m=0 and b=1 -> expond scaled by 1/2

BEGIN

local f;

f:= (1/(2b))e^(-(ABS(n-m))/b);

return f;

END;

EXPORT laplaced_cdf(m,b,n)

BEGIN

local f;

f := piecewise(n<n, (1/2)*e((n-m)/b), 1-(1/2)*e(-(n-m)/b));

return f;

END ;

Uniform Distribution

EXPORT uniformd(a,b,n)

// Uniform, distribution [a-b], n var

BEGIN

local f:= piecewise(n>=a AND n<=b, 1/(b-a), 0);

return f;

END;

EXPORT uniformd_cdf(a,b,n)

BEGIN

local f:= piecewise(n<a, 0, n≥b, 1, (n-a)/(b-a));

return f;

END;

start: postbit_signature

Multinomial Distribution:

The multinomial distribution is a generalization of the binomial distribution. For n independent trials each of which leads to a success for exactly one of k categories, with each category having a given fixed success probability, the multinomial distribution gives the probability of any particular combination of numbers of successes for the various categories.

EXPORT Multinomd(n, k, p)

// Multinomial distribution (n>0,{list k_i}, {list p_i})

BEGIN

IF ((type(k) ≠ 6) OR (type(p) ≠ 6)) THEN 

return “2nd and 3th argument must be a list”; ELSE

IF n<1 THEN return “n must be >0”; END;

n:= ip(n); //n must be integer

IF (size(k) ≠ size(p) ) THEN return “items in k must be = those in p”; END;

IF (ΣList(k) ≠ n) THEN return “ΣList(k) must be = n”; END;

IF (ΣList(p) > 1) THEN return “ΣList(p) must be <= 1”; END;

// ΣList(p) should be = 1 but we can use in list k only values with no 0

//so items in p could be less than those in k…

return  (n!/ΠLIST(k!))*ΠLIST(pk);

END; // if 

END;

Comentarios: 0
Más sobre: Distributions, HP prime, Statistics

Solo los usuarios registrados pueden poner comentarios.
Identificarse y añadir comentario Regístrese ahora