# Question:Statistics:-Specialize can produce wrong results

## Question:Statistics:-Specialize can produce wrong results

Maple 2015

The Statistics package contains a function named Specialize (which quite strangely doesn't appear when you expand the sections of this package).
Here is what help(Specialize) says:

```The Specialize function takes a random variable or distribution data structure that contains symbolic parameters, and performs a substitution to specialize the given random variable or distribution.
```

My goal was to work with mixtures of two random variables. There are many ways to do that depending on the what you really want to achieve, but an elegant way is to define such a mixture this way:

• Let X and Y two random variables representing the two components to be mixed.
For instance X = Normal(mu, sigma) and Y = Normal(nu, tau).

• Let B a Bernoulli random variable with parameter P.

• Then M = B*X + (1-B)*Y represents a random mixture of the two components in proportions (p, 1-p).
Note that M is a 5-parameters random variable.

Doing the things this way enables getting a lot of formal informations about M such as its mean, variance, and so on.

In order to illustrate what the mixture is I draw the histogram of a sample of M.
To do this I Specialized the three random variables X, Y, B.

I used parameters

`mu=-3, nu=3, sigma=1, tau=1, p=1/2`

My first attempt was to draw a sample of the random variable Mspec defined this way

```Mspec := Specialize(B, [p=1/2])*Specialize(X, [mu=-3, sigma=1]) + (1-Specialize(B, [p=1/2]))*Specialize(Y, [nu=3, tau=1]);
```

As you see in the attached file (first plot) the histogram is wrong (so is the variance computed formally).

I changed this into

```Mspec := Specialize(B, [p=1/2])*(Specialize(X, [mu=-3, sigma=1])-Specialize(Y, [nu=3, tau=1])) + Specialize(Y, [nu=3, tau=1]);
```

without more significative success: while the variance is nox corrext the histogram still remains obviously wrong (plot number 2)

My last attempt, which now gives q correct result (plot 3) was:

```Bspec := Specialize(B, [p=1/2]);
Mspec := Bspec*Specialize(X, [mu=-3, sigma=1]) + (1-Bspec)*Specialize(Y, [nu=3, tau=1]);
```

Specialize.mw

I agree that one can easily do this stuff without using  Specialize.
For instance by using the procedure given at the end ofthe attached file.
Or by truly constructing a mixture Distribution (which would be more elegant but more complex).

I also agree that Specialize is in itself of a relative low interest except for educational purposes (you present the theoritical results and next you run a numerical application while giving numeric values to the formal parameters).

But why providing such an anecdotal function if it doesn't do the job correctly?

Note that these results were obtained with Maple 2015, but I doubt they'll be any better for more recent versions, given the confidential nature of Specialize.

﻿