Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to get expression() to display P(a <= X <= b)?

Tags:

r

plotmath

I've mostly been able to coerce expression() into giving me the mathematical output I've needed for graphs, but I'm flummoxed by this one.

text(-2,.21,expression(P(a <= X)), cex=1.2)

gives me the expected result, but

text(-2,.21,expression(P(a <= X <= b)), cex=1.2)

fails with an arrow pointing to the second \le. Pasting 2 pieces together doesn't work, either, as <= requires both left and right tokens; i.e. this also fails:

text(-2,.21,expression(<= X), cex=1.2)

Any ideas? It's kind of frustrating that there doesn't seem be any documentation on how the expression token parser works short of looking at the source code. The only documentation seems to be a couple of different color versions of this:

http://stat.ethz.ch/R-manual/R-patched/library/grDevices/html/plotmath.html

like image 510
pgoetz Avatar asked Nov 14 '12 20:11

pgoetz


People also ask

How do you find the probability distribution function of x?

Probability distribution for a discrete random variable. Any value x not explicitly assigned a positive probability is understood to be such that P(X=x) = 0. The function pX(x)= P(X=x) for each x within the range of X is called the probability distribution of X.

How do you find the probability function?

To work out the probability that a discrete random variable X takes a particular value x, we need to identify the event (the set of possible outcomes) that corresponds to "X=x". pX(x)=Pr(X=x).

What is the formula for probability density function?

The probability density function (pdf) f(x) of a continuous random variable X is defined as the derivative of the cdf F(x): f(x)=ddxF(x).

What does p X X mean?

Example 1: The table illustrates the probability distribution for the above experiment. Number of Tails (X)012Probability141214. The notation P(X=x) is usually used to represent the probability of a random variable, where the X is random variable and x is one of the values of random variable.


1 Answers

You need to group the operators in plotmath - in otherwords you have to be explicit about the precedence. To do this invisibly, wrap the sub-statements in { } as in:

R> plot(1:10, type = "n")
R> text(5, 5, expression(P(a <= {X <= b})), cex = 1.2)

Which gives

enter image description here

This is documented (if you know what it means) towards the end of the list of markup plotmath understands.

like image 59
Gavin Simpson Avatar answered Oct 06 '22 06:10

Gavin Simpson