2
$\begingroup$

I have a problem that I can't seem to figure out on my own due to limited knowledge of mathematics, and I was hoping I could seek help from the community. I would like to use LogNormalDistribution to generate random variables bound by min and max. I fail to do so, and I believe it is due to the way I derive Mean and StandardDeviation. Here is a simplified version of what I want to achieve but using a UniformDistribution instead.

size = 10^4; 
bound = {10^-7, 10^-4}; 

NumberLinePlot @ Interval @ bound

enter image description here

Histogram @ RandomVariate[UniformDistribution @ bound, size]

enter image description here

Based on the above, I can generate random numbers using an UniformDistribution. I have tried to derive a PDF for the above. However, it fails with an error message. Note, I use Win10 and Mathematica 11 for this work.

Show[
 Histogram[
   RandomVariate[UniformDistribution @ bound, size], 
   30, 
  "PDF"
 ],
 Plot[
  PDF[UniformDistribution @ bound, x], 
  {x, bound}
 ]
]

Skeleton is not a Graphics primitive or directive.

What I would like to be able to do is generate random numbers within a pre-defined boundary using a LogNormalDistribution. I have tried to achieve it by exploring Mean and StandardDeviation functions. However, I fail to achieve the desired outcome. In terms of the Mean, I would like it to remain sloped to the left towards the min. However, it can be anywhere within the first 15% of the CDF.

I do appreciate your help, and thank you for your willingness to assist me with the above.

EDIT 1 - PDF Fix for the above example, based on @kglr contribution

Show[
  Histogram[
    RandomVariate[UniformDistribution@bound, size], 
    30, 
    "PDF"
  ],
  Plot[
    PDF[UniformDistribution@bound, x], 
    {x, ## & @@ bound}
  ]
]
$\endgroup$
4
  • 2
    $\begingroup$ try Show[Histogram[RandomVariate[UniformDistribution@bound, size], 30, "PDF"], Plot[PDF[UniformDistribution@bound, x], {x, ## & @@ bound}]]? $\endgroup$ – kglr Dec 30 '19 at 17:21
  • $\begingroup$ Hello, @kglr, and thank you - this actually does work. I am not sure why; I will need to read-up about it. $\endgroup$ – e.doroskevic Dec 30 '19 at 17:23
  • 2
    $\begingroup$ e.doroskevis, correct syntax is Plot[function[x], {x, a, b}] not Plot[ function[x], {x, {a,b}}] (this is what you have in your code). {x, ##&@@round} (or, equivalently, {x, Sequence @@ round}) gives {x, 10^-7, 10^-4} which is the form Plot wants in its second argument. $\endgroup$ – kglr Dec 30 '19 at 23:59
  • $\begingroup$ Thank you, @kglr. I see what I did wrong. $\endgroup$ – e.doroskevic Dec 31 '19 at 0:55
1
$\begingroup$

@Chris gave you most if not all that you needed. Here is a follow-up to that answer:

dist = TruncatedDistribution[{xmin, xmax}, LogNormalDistribution[μ, σ]]
(* Mean  *)
mean = Simplify[Mean[dist], Assumptions -> {0 < xmin < xmax, σ > 0}]

Mean

(* 15th percentile  *)
x15 = Simplify[InverseCDF[dist, 15/100], Assumptions -> {0 < xmin < xmax, σ > 0, μ ∈ Reals}]

15th percentile

You ask for determining the combination of parameters (xmin, xmax, μ, and σ) that result in mean < x15. I don't think there are any combinations of the parameters that will result in that inequality being true.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.