statsmodels.sandbox.distributions.extras.SkewNorm_gen.expect¶
- SkewNorm_gen.expect(func=None, args=(), loc=0, scale=1, lb=None, ub=None, conditional=False, **kwds)¶
Calculate expected value of a function with respect to the distribution by numerical integration.
The expected value of a function
f(x)
with respect to a distributiondist
is defined as:ub E[f(x)] = Integral(f(x) * dist.pdf(x)), lb
where
ub
andlb
are arguments andx
has thedist.pdf(x)
distribution. If the boundslb
andub
correspond to the support of the distribution, e.g.[-inf, inf]
in the default case, then the integral is the unrestricted expectation off(x)
. Also, the functionf(x)
may be defined such thatf(x)
is0
outside a finite interval in which case the expectation is calculated within the finite range[lb, ub]
.- Parameters:
- func
callable
,optional
Function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.
- args
tuple
,optional
Shape parameters of the distribution.
- loc
float
,optional
Location parameter (default=0).
- scale
float
,optional
Scale parameter (default=1).
- lb, ubscalar,
optional
Lower and upper bound for integration. Default is set to the support of the distribution.
- conditionalbool,
optional
If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Additional keyword arguments are passed to the integration routine.
- func
- Returns:
- expect
float
The calculated expected value.
- expect
Notes
The integration behavior of this function is inherited from scipy.integrate.quad. Neither this function nor scipy.integrate.quad can verify whether the integral exists or is finite. For example
cauchy(0).mean()
returnsnp.nan
andcauchy(0).expect()
returns0.0
.The function is not vectorized.
Examples
To understand the effect of the bounds of integration consider
>>> from scipy.stats import expon >>> expon(1).expect(lambda x: 1, lb=0.0, ub=2.0) 0.6321205588285578
This is close to
>>> expon(1).cdf(2.0) - expon(1).cdf(0.0) 0.6321205588285577
If
conditional=True
>>> expon(1).expect(lambda x: 1, lb=0.0, ub=2.0, conditional=True) 1.0000000000000002
The slight deviation from 1 is due to numerical integration.