Picon
Favicon

Example(s) of Biomodal distributions

Dear R users:

I am currently teaching a course in Statistics. Can someone give an R code(s) to create a biomodal curve(s)
with shaded area of 90% and with 5% in each tail

With many thanks
abou

 

==========================
AbouEl-Makarim Aboueissa, Ph.D.
Associate Professor of Statistics
Graduate Program Coordinator
Department of Mathematics & Statistics
University of Southern Maine
96 Falmouth Street
P.O. Box 9300
Portland, ME 04104-9300
USA

Tel: (207) 228-8389
Fax: (207) 780-5607
Email: aaboueissa <at> usm.maine.edu
          aboueiss <at> yahoo.com

Office: 301C Payson Smith

	[[alternative HTML version deleted]]

(Continue reading)

Jeff Laux | 15 Jan 21:26
Picon

Re: Example(s) of Biomodal distributions

Would this work?

m1 <- 3.5
m2 <- 6.5
s1 <- 0.8
s2 <- 0.8
dist1 <- dnorm(x, mean=m1, sd=s1)
dist2 <- dnorm(x, mean=m2, sd=s2)
biModalDist <- dist1 + dist2

q <- qnorm(.9,0,1)
z1 <- q*s1
z2 <- q*s2
zLow <- m1 - z1
zUp <- m2 + z

xShade <- seq(zLow, zUp, 0.1)
d1Shade <- dnorm(xShade, mean=m1, sd=s1)
d2Shade <- dnorm(xShade, mean=m2, sd=s1)
yShade <- d1Shade + d2Shade

windows()
plot(x, biModalDist, type="l")
polygon(x=c(zUp, zLow, xShade), y=c(0,0,yShade), col="gray")

On 1/15/2012 2:41 PM, AbouEl-Makarim Aboueissa wrote:
> Dear R users:
>
> I am currently teaching a course in Statistics. Can someone give an R code(s) to create a biomodal curve(s)
with shaded area of 90% and with 5% in each tail
(Continue reading)

Jeff Laux | 15 Jan 21:58
Picon

Re: Example(s) of Biomodal distributions

x didn't make it through the cut-and-paste, it should be:

x <- seq(0, 10, 0.1)

also zUp has a typo, it should be:

zUp <- m2 + z2

That should work now.

On 1/15/2012 2:41 PM, AbouEl-Makarim Aboueissa wrote:
> Dear R users:
>
> I am currently teaching a course in Statistics. Can someone give an R code(s) to create a biomodal curve(s)
with shaded area of 90% and with 5% in each tail
>
> With many thanks
> abou
>
>
>
> ==========================
> AbouEl-Makarim Aboueissa, Ph.D.
> Associate Professor of Statistics
> Graduate Program Coordinator
> Department of Mathematics&  Statistics
> University of Southern Maine
> 96 Falmouth Street
> P.O. Box 9300
> Portland, ME 04104-9300
(Continue reading)

Randall Pruim | 16 Jan 05:31
Favicon
Gravatar

Re: Example(s) of Biomodal distributions

I recently wrote a function for the mosaic package that makes it easy  
to generate various kinds of plots of distributions.  For example, to  
plot a Binom(30,.35) distribution, you just use:

distPlot("binom",params=list(size=30, prob=.35))

and get the attached plot (if it makes it through to the list).

Additional arguments let you choose between different kinds of plots  
(density, histogram, qq, cdf), and there is a heuristic to guess  
whether the distribution is discrete or continuous and to the right  
thing.

I didn't set these up to make it easy to add the shading, but I think  
I could modify things to make that possible too.   Stay tuned.

---rjp

On Jan 15, 2012, at 2:41 PM, AbouEl-Makarim Aboueissa wrote:

> Dear R users:
>
> I am currently teaching a course in Statistics. Can someone give an  
> R code(s) to create a biomodal curve(s) with shaded area of 90% and  
> with 5% in each tail
>
> With many thanks
> abou
(Continue reading)

Randall Pruim | 16 Jan 07:57
Favicon
Gravatar

Re: Example(s) of Biomodal distributions


I have modified the distPlot() function in the mosaic package so that  
the following makes the desired plot (as a density histogram):

distPlot( "binom", params=list(35,.25), groups= y <  
dbinom(qbinom(0.05, 35, .25), 35,.25), kind='hist')

The groups argument is used to get the desired shading of tail  
probabilities.  (Technically, it is not shading 5% in each tail, but  
it is doing one of the reasonable approximations to that).

I expect this feature will show up on github sometime Monday (along  
with some other updates scheduled for release) and on CRAN in the near  
future.

If you are really anxious, you can get it from my personal repository  
using

	install.packages('mosaic', repos='http://www.calvin.edu/~rpruim/R',  
type='source')

Since images don't go through on the mailing list, I've placed a few  
here:

	http://www.calvin.edu/~rpruim/R/distPlot.pdf

---rjp

On Jan 15, 2012, at 2:41 PM, AbouEl-Makarim Aboueissa wrote:

(Continue reading)

Randall Pruim | 16 Jan 14:58
Favicon
Gravatar

Re: Example(s) of Biomodal distributions


Just noticing that I read the post below too quickly and thought it  
said "binomial" rather than "bimodal".  But my solution works all the  
same, you just need to provide a bimodal distribution as the first  
argument.  The only requirement is that if the name of your  
distribution is "foo", then dfoo, pfoo, and qfoo need to exist and do  
the correct things.  They may be user defined functions.

You can of course, use the groups argument however you like to define  
the tails of the distribution.  For example, something like

	groups = ( x < qfoo(0.05, ....) | x > qfoo(0.95) )

should shade the tails differently from the center.

In view of the email from Jeff Laux, I might consider adding some  
utilities to build new dfoo, pfoo, and qfoo functions from existing  
ones, at least for a few easy cases, like linear combinations.  That  
would make it really easy to generate various bimodal distributions.

---rjp

On Jan 15, 2012, at 2:41 PM, AbouEl-Makarim Aboueissa wrote:

> Dear R users:
>
> I am currently teaching a course in Statistics. Can someone give an  
> R code(s) to create a biomodal curve(s) with shaded area of 90% and  
> with 5% in each tail
>
(Continue reading)

chubukou | 16 Jan 15:10

Re: Example(s) of Biomodal distributions

I think AbouEl-Makarim means "bimodal distribution" here is my solve 
(sorry for primitive example)

m1<-0;
sd1<-1;
m2<-4;
sd2<-1;
bimodal<-curve(dnorm(x,m1,sd1)+dnorm(x,m2,sd2), 
from=min(c(m1,m2))-3*max(c(sd1,sd2)), 
to=max(c(m1,m2))+3*max(c(sd1,sd2)));
ql_1<-quantile(rnorm(1000,m1,sd1),0.05);
qh_1<-quantile(rnorm(1000,m1,sd1),0.95);
ql_2<-quantile(rnorm(1000,m2,sd2),0.05);
qh_2<-quantile(rnorm(1000,m2,sd2),0.95);
plot(bimodal$x, bimodal$y, type="l");
abline(v=ql_1, col="red",lwd=2);
abline(v=qh_1, col="red",lwd=2);
abline(v=ql_2, col="green", lwd=2);
abline(v=qh_2, col="green", lwd=2);
polygon(x=c(ql_1,qh_1, bimodal$x[bimodal$x<=qh_1 && bimodal$x>=ql_1]), 
y=c(0,0,bimodal$y[bimodal$x<=qh_1 && bimodal$x>=ql_1]), col="gray");
polygon(x=c(ql_2,qh_2, bimodal$x[bimodal$x<=qh_2 && bimodal$x>=ql_2]), 
y=c(0,0,bimodal$y[bimodal$x<=qh_2 && bimodal$x>=ql_2]), col="gray");

--
Zhan Chubukou
Chair of Pathological Physiology magistrant
Gomel State Medical University
Belarus

(Continue reading)

chubukou | 16 Jan 15:47

Re: Example(s) of Biomodal distributions

Dear Abou,
I think Your trouble can be solved like there 
http://www.talkstats.com/showthread.php/11746-Problem-with-plotting-in-R

---
Zhan Chubukou
Chair of Pathological Physiology magistrant
Gomel State Medical University
Belarus


Gmane