# Items tagged with distributiondistribution Tagged Items Feed

### Error in Distribution...

October 17 2015
0 2

Hi,

I have the following input

***

restart;
with( Statistics ):

a:=2;c:=0.3;
g:= exp(-a*x) + c*a*exp(-a*x);
#f := x -> piecewise( x < 0, 0, x>0, g );
f :=x -> piecewise( x < 0, 0, x>0, exp(-a*x) + c*a*exp(-a*x));

norm_factor:=int( f(x), x=0..infinity );
print(norm_factor);

randomize():
F := Distribution( PDF = 1/norm_factor*f ):
X := RandomVariable( F ):

N := 20;
S := convert( Sample(X,N), list );

print(cc,S[1]);

***

The code works. However, if I comment out

f :=x -> piecewise( x < 0, 0, x>0, exp(-a*x) + c*a*exp(-a*x));

, then use

f := x -> piecewise( x < 0, 0, x>0, g );

i.e.

f := x -> piecewise( x < 0, 0, x>0, g );
#f :=x -> piecewise( x < 0, 0, x>0, exp(-a*x) + c*a*exp(-a*x));

It is said "

Error, (in Statistics:-Sample) unable to construct the envelopes for _R, try to specify the initial range"

The norm_factors are actually the same for both inputs. What is the reason for the error message?  Suppose I still want to use something like

f := x -> piecewise( x < 0, 0, x>0, g );

,how to fix the problem?

Thank you very much

### How to compute PDF?...

July 12 2015
2 1

I am trying to find the pdf of the inverse of a random variable X, that represents a distribution I defined. I currently have :

with(Statistics):
T:=Distribution(PDF=(x->piecewise(0<x and x<1,1/4,3<x and x<5,3/8,0)));
X:=RandomVariable(T);
PDF(X,u);
CDF(X,u);
Y:=1/X;
T1:=RandomVariable(Y);

but this seems to be incorrect as I get a message saying T1:=RandomVariable(Y) is being passed a wrong argument.

What is the right way to obtain the pdf of 1/X?

### Generating sampling points with a known distribut...

July 04 2015
0 5

Hi,

Suppose I have a probability distribution function f(x). I would like to generate points in a

(1) given interval, can be up to infinity

(2) number of points

(3) satisfy the known probability distribution function f(x)

(4) possible other specifications

Is there any build-in option in maple I could use? Or I have to write something manually?

Thank you very much!

### compute the cdf of a piecewise probability distrib...

April 01 2015
1 1

This should be trivial but I am not able to figure out the right syntax to execute it

The pdf is given by :

f_X(x)={ 1/25 *x, 0<=x<5

2/5 -x/25, 5<=x<10

0, otherwise

I have tried to use the "CumulativeDistributiveFunction" so far

### Best fit a normal distribution to a set of data...

March 23 2015
0 2

If I have some data, how would I determine the best normal distribution fit?

### binomial data simulation...

March 09 2015
0 1

How to simulate a data which is follow by binomial distribution, n=200, p=0.9.

I know normal can be simulated by following code

random[normald[0, 1]](50)

### posterior plot animation...

February 15 2015
0 4

Greetings, seeking an expert to animate a plot.

see worksheet.posterior_graphs_(encapsulted)_1D.mw

before they play each other, each have a law (a normal distribution) plot-output 6.

after DD defeats CC, and a numerical integration is performed the new laws are given by plot-output 18.

as you can see, the laws of DD and CC are closer together.

if the calc was repeated (DD defeats CC again), the laws would be closer again.

so what i require is an animation of the new laws from game 1 to (say) game 6 (DD defeats CC every time). seeing the red and blue distributions merging would be ideal.

as an aside I heard maples FFT could simplify the complicated integration. any suggestions?

cheers

### Expected Value of a function...

January 08 2015
0 2

Hello people in Mapleprimes,

I want to do calculations about an expected value.

For example,

expectedvalueofc.pdf

that is, \int_a^b c d \Omega

where, \Omega is a distribution function of c.

But, I don't know whether this equation can be put into worksheet.

Is there no way other than writing this as

\int_a^b c g(c) dc,

where g shows a probability density function.

Can I use Statistics[ExpectedValue] to calculate expected value with a general distribution function, not specified

to normal distribution?

I hope you will give me some hints.

Best wishes.

### Why doesn't the integral evaluate?...

November 29 2014
0 4

I want to integrate the following cumulative distribution function with variable bounds but maple returns the integral.

>with(Statistics);

>N := RandomVariable(Normal(0, 1)):

>a := (ln(98.53*(1/95))+(0.1e-1+.5*x^2)*.5)/(x*sqrt(.5))

>y:= CDF(N, a, inert = true);

How do i make maple return a function of x instead of an integral?

### how do I setup/plot this probability distribution...

November 25 2014
1 13

How do I setup/plot this probability

As a thought example, time waiting in a line at cash register.  Let's say 40% of the time you are waiting for ~1 minute while 35% of the time you are served immediately and the rest of the time trailing off waiting up to 15 minutes.

Is this is like a skewed normal distribution?  and how could I set it up?  And then how can I randomly generate some values from this distribution?

### Random numbers...

August 25 2014 Maple
6
3

Erik Postma from Maplesoft has recently posted a Maple application going through some of the ways how to produce random numbers in Maple: http://www.maplesoft.com/applications/view.aspx?SID=153662&P=TC-4444

Doing a fair bit of work involving random numbers (i.e. simulations) myself, I was naturally drawn to it. The document is a nice extension of the relevant help pages, making practical use of some of the procs in RandomTools easier and clearer.

One particular issue I recently ran into, however, is not covered. I needed a random generator for a particular custom pdf (not one of the already recognized pdfs) that happens to be 3-dimensional. And I needed to do this >twice<, with the second generation using the result of the first one as a parameter. the problem is not unlike the last example in the help page for Statistics:-Sample.

Here is what I did:

The pdf looks graphically like this (and note that in this plot it is not normalized):

plot3d(Triangle63:-Trianglef(CrystalAngle,DeflectionAngle),\
CrystalAngle=-0.8..0.2,DeflectionAngle=-0.6..0.6,projection=0.7);

The first set of random numbers is generated by setting CrystalAngle to a fixed number (-0.1 in this case), normalizing the pdf to the integral over DeflectionAngle and then generating the random numbers. Note that evaluation of the integral is relatively time-consuming (seconds).

trianglepdf:=(CrystalAngle,DeflectionAngle) ->\
Triangle63:-Trianglef(CrystalAngle,DeflectionAngle)/\
'evalf(Int(Triangle63:-Trianglef(CrystalAngle,Da),Da=-0.6..0.6,method = _d01akc))':
triangle0pdf:=(t) -> trianglepdf(-0.1,t):
Cr1:=Distribution(PDF=triangle0pdf);
Y:=RandomVariable(Cr1);

samples:=Sample(Y,[1..600],method=[envelope,range=-0.6..0.6]);

This looks as it should; and the random number generation is reasonably fast once the initial setup has been done (i.e. the time used scales only relatively weakly with the count of random numbers generated.

The issue now is the second stage, where for each new random number, the number generated above is a new input parameter for CrystalAngle. So I can no longer define the pdf once since the pdf is different for each number generated.

The pedestrian way to do this is like the following:

samples2:=Vector(1..numelems(samples),datatype=float):
CrystalOffset:=0.3;

for ii from 1 to numelems(samples) do
triangleiipdf:=(t) -> (trianglepdf(samples[ii]-~CrystalOffset,t)); # subtract (VR peak -> 0)
Crii:=Distribution(PDF=triangleiipdf);
samples2[ii]:=evalf(Sample(RandomVariable(Crii),1,method=[envelope,range=-0.6..0.6])[1]+CrystalOffset);
end do:

This works, but only sort-of. First, it is very slow, since the whole sertup happens for each number generated (Sample()). Secondly, it tends to hang at a certain number of steps through the loop. The value of ii where it hangs is arbitrary and changes with the other parameters and CrystalOffset. It is however consistent for identical runs.

The last example in help for Statistics:-Sample would indicate that one needs to setup the pdf as a function of t as well as the parameter, call Distribution() only once and then assign the value to the parameter and call Sample() to get the random number(s) drawn from the pdf with the parameter being set to the wanted value. While this works in the example which uses a built-in pdf, I find that I cannot make it work with my pdf. Either the parameter gets ignored (i.e. stuck at the first value) or the thing runs just as slowly as my procedure above.

Ultimately I programmed my own random generator for an arbitrary pdf which, while not as efficient as Maple's built-in generator, does produce the expected set of random numbers for the 2nd path in a reasonable time. It is a simple-minded envelope-rejection method, that works fo reasonably well-behaved pdfs:

Rarbit:=proc(pdf,xmin,xmax,pdfmax)
local dx:=xmax-xmin;
local x1,x2;
x1:=RandomTools[MersenneTwister]:-GenerateFloat64()*dx+xmin; # pick location on x axis
x2:=RandomTools[MersenneTwister]:-GenerateFloat64()*pdfmax; # y axis, probability of returning x1

while (x2>evalf(pdf(x1))) do # if above pdf, reject
x1:=RandomTools[MersenneTwister]:-GenerateFloat64()*dx+xmin; # new x-axis value
x2:=RandomTools[MersenneTwister]:-GenerateFloat64()*pdfmax; # check value
end do; # eventually we'll succeed and return one.

x1;
end proc;

Using this routine I get my second and final set of randome:

for ii from 1 to numelems(samples) do
newpdf:=(DefAng) -> Triangle63:-Trianglef(samples[ii]-CrystalOffset,DefAng);
samples2[ii]:=Random:-Rarbit(newpdf,-0.6,0.6,28);
DocumentTools:-SetProperty(ProgressBar,'value',ii,refresh);
end do:
CrystalOffset := 0.3
Histogram(samples2+~samples,view=[-0.6..0.6,default]);

I would be interested in Erik's comment on this.

Mac Dude

### how to plot tail of normal distribution?...

June 27 2014
0 1

how to plot tail of normal distribution

would like to see the shape of tail of distribution

### best approximation of six multivariate normally di...

April 05 2014
1 3

Dear Maple experts,

I would like to generate population data that is the best possible approximation of a multivariate normal distribution with a specified covariance matrix and vector of means. I do not want to draw a sample from a multivariate distribution, but I want the population values itself which are approximately multivariate normal distributed. The size of the datamatrix should be limited, otherwise I could draw a huge sample from a multivariate normal distribution. For instance, I would like to generate a 200 by 6 data matrix that is the best (or at least good enough) approximation of a MVN distribution. For a bivariate normal distribution one could calculate the probalities of a grid by integrating the density, but for six variables that seems undoable.

Before trying the invent the wheel again, I think I will ask this question to experts, because it is unlikely that there is no already existing algorithm that does the job pretty well.

Harry Garst

### CDF of Student T Distribution...

February 10 2014
1 1

Hello, Please how do I compute cdf of student t distribution in maple Tξ+1(.). I have a function that i nvolves student t distribution but finding it difficult to compute student t in the funcion. I am new to maple.

### Problem with fsolve...

November 21 2013
2 7

Hi everyone

I'm currently working on some mandate distribution using "Jefforson's Method" but I have run into some problems.

The general form of the calculations I do is as follows:

d:=fsolve(m = floor(v1/x)+floor(v2/x), x)

But in the case of m=5, v1=4969 and v2=208 it does not work. If I change v1 a bit it works as a charm but when
4960=<v1=<4969 it does not.

Can any of you figure out why?

The equation surely has a solution (well, a lot of solutions). I can figure some out just by estimating and trying. Furthermore, wolfram alpha easily gives me several solutions:

http://www.wolframalpha.com/input/?i=5+%3D+floor%284969%2Fx%29%2Bfloor%28208%2Fx%29

So how come I cannot get Maple to solve it?