Imprimir

Distribuciones estadísticas

La HP Prime viene bien surtida de distribuciones estadísticas. De memoria, viene con las siguientes:

  • Normal,
  • T (Student),
  • Chi-square,
  • F (Fisher distribution),
  • Binomial y
  • Poisson.

todas ellas vienen en las tres formas que se pueden necesitar: densidad, valor acumulado y función inversa de la distribución. Comparadas con mi querida HP41CL, la HP Prime viene bien surtida para la estadística. Pero hay muchas otras distribuciones estadísticas que se pueden necesitar, sin tener que aproximar nuestras soluciones a las distribuciones más conocidas o frecuentes. El usuario Salvomic en HPmuseum.org ha creado programas para muchas de ellas. Como no reclama el copyright, y en interés de nuestros lectores, publicamos aquí sus programas.

Logistic Distribution:

EXPORT logisticd(m,s,k)

// Logistic distribution m=µ, s=s, k=x

BEGIN

local f,g;

g:= (k-m)/s;

f:=e(-g)/(s*(1+e(-g))^2) ;

return f;

END;

EXPORT logistic_cdf(m,s,k)

BEGIN

local f,g;

g:= (k-m)/s;

f := 1/(1+e^(-g));

return f;

END ;

EXPORT logisticd_icdf(m,s,p)

// inverse m=µ, s=s, p probability

BEGIN

local f;

f:= m+s*ln(p/(1-p));

return f;

END;

Lognormal

EXPORT LgNrm(m,s,k)

// LogNormal distribution m=µ, s=s, k=x

BEGIN

local f;

f:= (1/(kssqrt(2pi)))e(-(ln(k)-m)2/(2*s2));

return f;

END;

EXPORT LgNrm_cdf(m,s,k)

BEGIN

local f;

f := normal((ln(k)-m)/s) ;

return f;

END ;

Exponential

EXPORT expond(l,n)

// exponential distribution l=λ=1/np, n

BEGIN

local f;

f:= piecewise(n<0,0,  le^(-ln));

return f;

END;

EXPORT expond_cdf(l,n)

BEGIN

local f;

f := piecewise(n<0, 0, 1-e^(-l*n));

return f;

END ;

Geometric

EXPORT geometric(n,p)

// Geometric distribution, n tries, p prob

BEGIN

local f;

f:= p*(1-p)^n;

return f;

END;

EXPORT geometric_cdf(n,p)

BEGIN

local f;

f := 1-(1-p)^(n+1);

return f;

END ;

Hypergeometric

EXPORT ipergeom(n,m,k,j)

// Hypergeometric distribution, n total, m one kind, k extracted, j var

BEGIN

local f;

f:= (comb(m,j)*comb(n-m,k-j))/(comb(n,k));

return f;

END;

Negative Binomial

EXPORT NegBin(r, p,n)

// Negative Binomial distribution observing until r success, with p probability of success

//  n num trials for r success (k failures), n=r, r+1,…

BEGIN

local f;

IF (n<r) THEN return “n must be >= r”; ELSE

f:= comb(n–1, r–1)*(pr)*(1-p)(n-r);

return f;

END; //if

END;

EXPORT NegBin_cdf(r, p, n)

BEGIN

local f, b1, a, b;

a:=r; b:= n+1;

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

// incomplete beta function

f:=( b1/Beta(a,b));

return f;

END;

EXPORT NegBin2(r, p,k)

// Negative Binomial observing until r failures, with p probability of success (1-p failure)

// n num trials, k = n-r success

// i.e. NegBin(5,0.4,15) = NegBin2(5,0.6,10)

BEGIN

local f;

f:= (comb(k+r–1,k))*(pk)*((1-p)r);

return f;

END;

Gompertz

EXPORT gompertz(h,b,n)

// Gompertz distribution h=η shape param, b scale param, n var

BEGIN

local f;

IF (n<0 OR h<=0 OR b<=0) THEN return “Not defined for η or b < =0 or n <0”; ELSE

f:= bhe(b*n)*ehe(-h*e(bn)) ;

return f;

END; // if

END;

EXPORT gompertz_cdf(h,b,n)

BEGIN

local f;

IF (n<0 OR h<=0 OR b<=0) THEN return “Not defined for η or b < =0 or n <0”; ELSE

f := 1-e(-h*(e(b*n)–1));

return f;

END;

END ;

Weibull

EXPORT weibull(l, k, t)

// Weibull distribution: l=λ>0 scale param (characteristic lifetime), k>0 shape parameter t var (time)

BEGIN

local f;

f:= piecewise(t<0,0,  (k/l)(t/l)^(k–1)e(-(t/l)k));

return f;

END;

EXPORT weibull_cdf(l, k, t)

BEGIN

local f;

f:= piecewise(t<=0,0, 1-e(-(t/l)k)) ;

return f;

END ;

EXPORT weibull_translate(l, k, t, v)

// Weibull distribution tranlated: v location parameter

BEGIN

local f;

f:= piecewise(t<=v,0,  (k/l)((t-v)/l)^(k–1)e(-((t-v)/l)k));

return f;

END;

EXPORT weibull_translate_cdf(l, k, t, v)

BEGIN

local f;

f:= piecewise(t<=v,0, 1-e(-((t-v)/l)k)) ;

return f;

END ;

Cauchy

EXPORT cauchyd(x0,g,n)

// Cauchy distribution x0 location param, g=γ scale param, n var

BEGIN

local f;

f:= 1/ (pig(1+((n-x0)/g)^2)) ;

return f;

END;

EXPORT cauchy_cdf(x0,g,n)

BEGIN

local f;

f:= (1/pi)*atan((n-x0)/g)+1/2 ;

return f;

END ;

EXPORT cauchy_icdf(x0,g,p)

// inverse x0, g=γ, p probability

BEGIN

local f;

f:= x0+gtan(pi(p-(1/2)));

return f;

END;