mmcdara

857 Reputation

13 Badges

3 years, 231 days

MaplePrimes Activity


These are replies submitted by mmcdara

@Carl Love 

Your method is surely correct for n large enough but I'm not sure it's still the cas for small values of n (It's more a feeling than a proof).

Another way could be to concatenate Sample(U1, floor(p*N)) with Sample(U2, N-floor(p*N)) (if p*N is an integer, or with N+1-floor(p*N) instead). Alittle bit simpler than your procedure but still suffering this "small n problem".

Where did you find RandomSampleSetup
Just do this :
R := Statistics:-RandomVariable(Uniform(0, 1));
exports([attributes(R)][3]);

RandomSampleSetup is in the list of the module members but I don't know where it's documented neither what it's for...

 

A REMARK

Your data is a collection of integer numbers: if it represents a sample of discrete random variable (which I don't know, but it's almost impossible that this sample could be drawn from a continuous random variable) it's inappropriate to plot a "histogram" with adjacents bins.
Even if this could seem more beautiful the good presentation to use in this case is a "bar plot" with vertical bars centered on the integer values.

The reason not to use adjacent bins is that it would give a completely false representation of the "sample".
In the attached file you will see a histogram of a sample drawn form a continuous random variable (for which adjacent bins makes sense) which is asymptotically the same as the one you would like to plot. Representing data through histograms, for instance, is a way to have a good understanding of these data: what would you think about a representation that would give identical plots for different data?

So, to sum up, unless you have better reasons than the beauty (which is a subjective criterion) to plot a histogram with adjacent bins, the better to do is to avoid doing it.

Histo.mw

@vv 

Post scriptum : I just realised that in the case of a mixture of two rvs U1 and U2 of disjoint supports it's enough to write the pdf of the mixture this way
pdf := (p,x) -> p*PDF(U__1, x) + (1-p)*PDF(U__2, x);

Of course this doesn't solve the sampling problem... but I just realised (once again) that it is very easy to sample MIXTURE(1/3) with this simple method :
U := Sample(Uniform(0, 1), 10);
map(solve, CDF(MEL(1/3), x)=~U, x); 


Now the question is: how could it be possible to declare this strategy in the definition of the Distribution (a priori by instanciating the attributes RandomSample and RandomSampleSetup) in order  to be able to invoke it while writing Sample(...., method=custom) ?

 

 

@vv 

I see two problems in your worksheet.

1. The distribution corresponding to the RV MIXTURE is not correctly defined. It should be:

pdf := (p,x) -> p*PDF(U1, x)*Heaviside(x+3) + (1-p)*PDF(U2, x)*Heaviside(x-1);
cdf := (p,x) -> int(pdf(p,y), y=-infinity..x);


Right, this was my first attempt but I got an error withe the MIXTURE := p -> RandomVariable(...)  instruction.
I just copy-paste your code and I can't reproduce this error: probably I'd done some typo but the fact is, I came to use this "incorrect" definition of pdf and cdf for it did not return an error.

In any case your correction partially solves my problem (it remains the sampling of the whole "support")

Thank you very much

 

PS : I don't know, me neither, how to define the support of a rv. Just as I don't know how to define a custom sampler: the help page is not very instructive on this point.

 

@Carl Love @vv

Thanks to both of you.

Could I infer from what you said that "arithmetic of infinity" is not completely (could I say "without flaws'?) implemented in Maple and that, in all cas, we must be very carefull while using it?

 

@Kitonum 

In a sense, this is natural, because legend option is associated with the image of curves..." it is what I suspected too.

I'm at home right now with my old Maple 2015 version: in my reply to Carl Love you will see that the error message is very explicit with this version, I do not remember thios is still the case in Maple 2019.

Thanks for the help

@Carl Love 

here it is
 

restart:

Unfortunately I'm home right now and I still use Maple 2015.

The error message is so clear that receiving it with Maple 2019  would not have lead me to ask a question.

interface(version)

`Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895`

(1)

plots:-inequal({y > t, y < t^2}, y=-2..2, t=-2..2, legend="test")

Error, (in plots:-display) display does not accept the legend option

 

 


 

Download inequal.mw

@acer 

It works perfectly.
Thanks for the help

@Kitonum 

Why not just write the following 2 lines and it will be beautiful:... because the "structure"  I want to display doesn't have a matrix shape.

An example of this "structure" is given in this help page DocumentTools:-Layout:-Cell :

T := Table(Column(),Column(),Column(),widthmode=pixels,width=90,alignment=center,
           Row( Cell( "A1", columnspan=2 ), Cell("A2", rowspan=2 ) ),
           Row( Cell( "B1", rowspan=2), Cell( "B2" ) ),
           Row( Cell( "C", columnspan=2 ) )):
InsertContent(Worksheet(Group(Input( T )))):

 

... and the cell B1, for instance, must contain the piecewise relation : so Tabulate is useless here

@Carl Love 

Thank you very much, your answer suits me perfectly and the polynomial case is more than enough.
(PS: I wasn't aware about type recursivity).

The  footnote and your conclusion are very clear.

@Carl Love @acer  @Joe Riel

Thank you three for your precious help.

Here is a special comment on Carl's sentence "But mostly I want to draw your attention to the distinction between types and properties because I think that you may be referring to the latter".

 I know a little bit about assume and properties and I think that my question was reallyoriented on types (even if it was perhaps not clear enough). 

Maybe you will have a better understanding of my question if I explain its context.
In one of your replies, months ago, you showed me how to define a type 'RV' (for Random Variable) while using TypeTools:-AddType.
I'm presently working on a course on Statistics and I decided to use Maple to explain some concepts.
The minimal way to define a random variable with package Statistics is 

dist := Distribution(PDF=(t->f(t))):
V := RandomVariable(dist);


And I thought it would have been even better if I could write something like V::RV
where type RV is (your code) :
TypeTools:-AddType(
     RV, 
     {RandomVariable, 
       'RandomVariable^posint', 
        '`*`'({RandomVariable, 'RandomVariable^posint'})
     }
);


Related to this point is the following :

  • Suppose you define 2 rvs X and Y (Statistics:-RandomVariable)
    You can verify that [attributes(X)][2] is RandomVariable (same thing for Y)
  • Now set Z=X+Y ; Z is obviously a random variable, but Z has no attributes and is not the same "type of object" than X or Y.
  • I tought that if it was possible to declare that both X and Y where of some type (RV) then this type could be inhereted by Z ..???

@Samir Khan 

Received five out of five, I took the opportunity to vote up here

@Samir Khan 

Thanks, I'm going to look at it

Nice !
I've seen these types of plots from parameter curves before and I've always wondered how to get the expressions of these curves.
Could you briefly explain to me how you did it?

Happy new year

Fine, 

What is the minimum version of Maple which supports the 'rotation' option in textplot ?

1 2 3 4 5 6 7 Last Page 1 of 38