Calculating expectation for a custom distribution in Mathematica

感情迁移 提交于 2019-12-01 20:04:30

Although you have provided both PDF and CDF for your custom distribution to Mathematica, you have not given the domain, so it does not know boundaries of integration, and in fact whether to integrate or sum. Adding that makes things work:

In[8]:= nlDist /: 
 DistributionDomain[nlDist[alpha_, beta_, mu_, sigma_]] := 
 Interval[{-Infinity, Infinity}]

In[9]:= NExpectation[Log@X \[Conditioned] Log@X > 0.1, 
  X \[Distributed] nlDist[3.77, 1.34, -2.65, 0.40]] - 0.1

Out[9]= 0.199329

Compare this with ProbabilityDistribution that has the format ProbabilityDistribution[ pdf, {x, min, max}], where you explicitly indicate the domain.

In order for symbolic solvers like Probability, Expectation and their numeric counterparts work on these, it is also advised to set DistributionParameterQ and DistributionParameterAssumptions as well.

DistributionParameterQ should give False is parameters explicitly violate assumptions, and DistributionParameterAssumptions should return the boolean expression representing assumptions on parameters of your distribution.

I'm not sure I really understand your question... The expected value or the mean, is the first moment of the distribution and can be calculated as

expectation := Integrate[x #, {x,-Infinity,Infinity}]&;

and use it as expectation[f[x]], where f[x] is your pdf.

Your last code snippet doesn't work for me. I don't know if it is v8 code or if it is custom defined or if you're trying to say that is what you'd like your function to be like...

You can also try looking into Mathematica's ExpectedValue function.

ExpectedValue[x, NormalDistribution[m, s], x]
Out[1] = m
doug fromoz

The following page contains some tips on enabling custom distributions (i.e. written from scratch without TransformedDisribution or ProbabilityDistribution) for use in CopulaDistribution, RandomVariate, etc: https://mathematica.stackexchange.com/questions/20067/efficient-generation-of-random-variates-from-a-copula-distribution/26169#26169

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!