# Compute conditional mean from distribution

5 vues (au cours des 30 derniers jours)
Fredrik P le 14 Nov 2023
How do I compute a conditional mean of a distribution in Matlab (e.g. between the 1st and 5th percentiles)? Right now, I am thinking of using integral, but I'm guessing that there is a smarter way.
pd = makedist('Lognormal', 5, 0.5);
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Fredrik P le 14 Nov 2023
https://en.wikipedia.org/wiki/Log-normal_distribution#Conditional_expectation

Connectez-vous pour commenter.

### Réponse acceptée

Jeff Miller le 14 Nov 2023
Another approach:
pd = makedist('Lognormal', 5, 0.5);
lb = icdf(pd,0.01); % find scores at 1% and 5%
ub = icdf(pd,0.05);
td = truncate(pd,lb,ub); % truncate the distribution between those bounds
m = mean(td);
[lb, ub, m]
% ans =
% 46.378 65.207 57.298
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Plus de réponses (2)

Julian le 14 Nov 2023
Is one of these conditional mean models fit you?
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Paul le 14 Nov 2023
Hi Fredrik,
If you just want to compute the conditional mean, why not just use the third expression for Conditional Expectation in the link you've provided? In Matlab, that PHI function is implemented with normcdf.
If you want a quick, numerical approximation to your answer you can always do something like this:
mu = 5; sigma = 0.5;
pd = makedist('Lognormal', mu, sigma);
plot(0:.1:500,pdf(pd,0:.1:500)) % plot to see what we're working with
rng(100)
r = random(pd,[1e6 1]); % generate random numbers from the distribution
r(r<200 | r>300) = []; % throw away values outside of 200 < X < 300
conditionalmean = mean(r)% mean conditioned on X being in the specified range
conditionalmean = 240.2054
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Noncentral t Distribution dans Help Center et File Exchange

R2023b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by