I'm trying to calculate a conditional expectation E[ x | x > a ]
, where the distribution of x
is inferred from a finite sample of data using SmoothKernelDistribution
.
The data contain points {t,s}
where t
is the time of day, and s
is the traffic speed at that time. Here's a small subsample:
speedData = {{17.1006,30.2979},{20.3583,15.1275},{17.8508,26.2334},{12.8106,19.9852},{7.71861,11.9718},{17.1233,14.7792},{14.95,10.4096},{20.2389,33.6072},{18.3989,13.4087},{18.2425,14.074},{7.74028,22.0739},{18.07,9.80947},{15.6636,18.9742},{15.6806,15.1147},{17.8603,7.06266},{16.5042,17.7862},{14.8319,14.5645},{15.8456,11.0942},{15.7133,11.4662},{14.3653,37.694},{15.5131,19.3896},{17.7636,18.0347}}
I define speedDistr = SmoothKernelDistribution[speedData]
.
If I understand the docs correctly, the following command should produce the result that I'm looking for:
Expectation[s \[Conditioned] s > 30, {t, s} \[Distributed] speedDistr]
However, the output just restates the command, and does not produce the desired result. At the same time, this command works perfectly well with built-in distributions (e.g. Expectation[x \[Conditioned] x > 2, x \[Distributed] NormalDistribution[]]
).
Also, unconditional expectation Expectation[s, {t, s} \[Distributed] speedDistr]
works fine.
What am I doing wrong?
NExpectation
, or perhaps giveKernelMixtureDistribution
as swing. As nice as the probability capabilities of MMA are, they have holes (ones I'd much rather WRI spend time on vs yet another superfluous function...) $\endgroup$NExpectation
actually produced a number, but it was quite slow, and showed two error messages: NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. >>NIntegrate::eincr: The global error of the strategy GlobalAdaptive has increased more than 2000 times. The global error is expected to decrease monotonically after a number \ of integrand evaluations. $\endgroup$